3

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

2
  • 1
    Perhaps this post might help: Centroid coordinates for odd-shaped polygons
    – Joseph
    Commented Jun 7, 2018 at 9:37
  • 1
    If 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?
    – Spacedman
    Commented Jun 7, 2018 at 10:04

1 Answer 1

6

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

2
  • 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....
    – Spacedman
    Commented Jun 7, 2018 at 10:06
  • I think so - see blog.mapbox.com/… for more discussion
    – Ian Turton
    Commented Jun 7, 2018 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.