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.
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.
I have a (somewhat convoluted) solution.
- Create centroids using the default centroids tool
- Select polygons that do not contain a centroid (the irregular shaped ones) and create a new layer
- Use the Vector > Research Tools > Random Points tool on your new layer
- Merge the two point layers
I wish this was an option in the Centroids tool (with a checkbox to 'force inside' or create a 'true' centroid) but hopefully this solution works for you for now.
Another method (if you have GRASS installed, which you can run via QGIS) is to import your polygons into GRASS. You will see that after you do so, a layer called topo_point is created, which you can save out to a shapefile.