Get a centroid in QGIS via python
<p>I am trying to get a centroid of a polygon in QGIS using python. Here is my code</p>

<pre><code>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 &lt; 3:
        print feature['Address']
        print getCentroid(feature)
        counter += 1
</code></pre>

<p>... which gives me a "name 'getCentroid' is not defined" error. </p>

<p>I find this surprising, since the QGIS python editor has <code>getCentroid</code> as a dropdown syntax-completion option. </p>

<p>I also tried using this function as a method of the feature object via <code>feature.getCentroid()</code> and received a similar error ("'QgsFeature' object has no attribute 'getCentroid'").</p>

<p>Similarly, trying <code>centroid(feature)</code> gives me the error "NameError: name 'centroid' is not defined," while <code>feature.centroid()</code> gives me  "'QgsFeature' object has no attribute 'centroid'".</p>

<p><strong>Is there another method I should be using for this operation?</strong></p>