【发布时间】:2017-02-15 06:29:03
【问题描述】:
我正在尝试使用 python 在 QGIS 中获取多边形的质心。这是我的代码
layerPluto = iface.addVectorLayer("/path/to/mn_mappluto_16v1/MNMapPLUTO.shp", "PLUTO", "ogr")
features = layerPluto.getFeatures()
counter = 0
for feature in features:
# Get the first feature from the layer
if counter < 3:
print feature['Address']
print getCentroid(feature)
counter += 1
...这给了我一个“名称'getCentroid'未定义”错误。
我觉得这很令人惊讶,因为 QGIS python 编辑器有getCentroid 作为下拉语法完成选项。
我也尝试通过feature.getCentroid()将此函数用作特征对象的方法并收到类似的错误(“'QgsFeature'对象没有属性'getCentroid'”)。
同样,尝试 centroid(feature) 时会出现错误“NameError: name 'centroid' is not defined”,而 feature.centroid() 会出现“'QgsFeature' object has no attribute 'centroid'”。
我应该使用其他方法进行此操作吗?
【问题讨论】:
标签: python geometry qgis centroid