# How to get the coordinates inside the polygon using python

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?

• what do you mean by getting the coordinates? Be more specific ! – julsbreakdown Jul 20 '15 at 12:01
• A polygon is defined as at least one outer boundary and 0..n inner boundaries (holes). You want the inner boundaries (holes) or a point inside the polygon? – nickves Jul 20 '15 at 12:19
• @nickves i want the points falling inside the polygon. – user99 Jul 20 '15 at 12:29

# 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:]
``````
• i am getting only only one point but i need all the points falling inside the polygon. – user99 Jul 20 '15 at 12:47
• What do you mean? How many points do you want? You mean you have another point layer and you want to count how many points are inside your polygons? – nickves Jul 20 '15 at 13:01
• If you want the points falling inside the polygon then it is an infinite number of points. – HeikkiVesanto Jul 20 '15 at 13:01
• @nickves i have raster layer and i want to calculate the pixels values. For that i want to find the points in the polygon that intersects with the raster. – user99 Jul 20 '15 at 13:24