[GIS] Getting single point from polygon Centroid if within polygon or any point if not using QGIS

qgis

I am trying to generate label points from my polygons. The Polygon->Centroid works great except that if the centroid happens to land in a hole it is still returned. I need to get a single point (Centroid if that point is within the polygon) a point within the polygon if the centroid happens to be outside of the polygon.

Best Answer

I found a better solution, using OGR. The following will create a point that always falls on the surface of the polygon:

ogr2ogr PointonSurface.shp InputPolygons.shp -dialect sqlite -sql “SELECT ST_PointOnSurface(geometry) from InputPolygons”

You can see some examples here.

Related Question