1
我想要使用python获取QGIS中多边形的质心。这是我的代码通过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编辑器有作为下拉语法完成选项。
我也试过使用这个函数作为特征对象的方法,通过feature.getCentroid()
并且收到了类似的错误(“'QgsFeature'对象没有属性'getCentroid'”)。
同样,尝试centroid(feature)
给我错误“NameError:name'centroid'is defined”,而feature.centroid()
给我“'QgsFeature'对象没有属性'centroid'”。
是否有另一种方法我应该使用此操作?
检查这个职位。 http://gis.stackexchange.com/questions/209292/getting-x-y-of-polygon-in-pyqgis –