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?
-
1Perhaps this post might help: Centroid coordinates for odd-shaped polygons– JosephCommented Jun 7, 2018 at 9:37
-
1If centroids are in holes and you don't want that then what you want isn't the centroid. What do you want? A label point? A point for sampling?– SpacedmanCommented Jun 7, 2018 at 10:04
1 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.
-
Where's the pole of inaccessibility for a multipolygon feature that is two identical squares? I guess its the centre of either square, according to the vagaries of the algorithm.... Commented Jun 7, 2018 at 10:06
-