[GIS] How to get the coordinates inside the polygon using python

coordinatespolygonpyqgisqgis

I have a polygon and using this code snippet we can get the coordinates boundary of the polygon.

canvas = qgis.utils.iface.mapCanvas()
aLayer = canvas.currentLayer()
coord = feat.geometry().asPoygon()

So if i want to get the coordinates inside the polygon also how can i do that using python?

Best Answer

A point inside a polygon

canvas = qgis.utils.iface.mapCanvas()
aLayer = canvas.layer(0)  # or code to select the layer of interest
for f in aLayer.getFeatures():
    geom = f.geometry()  
    p = geom.pointOnSurface()
    print p.asPoint()

Get Inner Rings

canvas = qgis.utils.iface.mapCanvas()
aLayer = canvas.layer(0)  # or code to select the layer of interest
for f in aLayer.getFeatures():
    geom = f.geometry()
    if len(geom.asPolygon()) > 1 : # we have inner rings
      print geom.asPolygon()[1:]  
Related Question