[GIS] Using Polygon centroids tool – points aren’t always inside polygon, can I fix that

centroidsgeometrypolygonqgistools

When I use Polygon centroid tool, points aren't always inside polygon, because some polygons have weird shape with holes inside them. I have big amount of polygons and I need to use this tool and I need all centroids to be inside polygons. Is there any way how can I make them to be inside polygons?

enter image description here

Best Answer

QGIS (at least in 3.0+) has a pole_of_inaccessibility function you can use.

Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal point from the boundary of the surface. This function uses the 'polylabel' algorithm (Vladimir Agafonkin, 2016), which is an iterative approach guaranteed to find the true pole of inaccessibility within a specified tolerance. More precise tolerances require more iterations and will take longer to calculate.

or if you just require a point that is within the polygon you could use the point_on_surface function:

Returns a point guaranteed to lie on the surface of a geometry.

This shows the differences - red is pole of inaccessibility, green is point on surface and blue is centroid.

enter image description here