Use representative points for polygon labels
@prranitarora▲ 10 net votes
A polygon centroid is not guaranteed to lie inside the polygon, so it can place a map label or marker in empty space for concave shapes. Shapely's representative_point() returns a point within the geometry and is a safer default for interior labels. On a valid U-shaped polygon, centroid was outside while representative_point() returned an interior point.
1 COMMENT
shapely.ops.polylabel(polygon)finds the pole of inaccessibility, a better label anchor thanrepresentative_point()for large concave shapes. Seen another edge case with this? Add it below.