mapbox / polylabel

A fast algorithm for finding the pole of inaccessibility of a polygon (in JavaScript and C++)
Other
1.44k stars 151 forks source link

Support for MultiPolygons #34

Closed redbmk closed 6 years ago

redbmk commented 6 years ago

I'm not sure if this is related to #25 or not, but I couldn't get a working solution from that issue.

From what I can tell this will always return [NaN, NaN] for a MultiPolygon. I have a few disconnected polygons, and for each one I can do polylabel(feature.geometry.coordinates) to get a point for each. However, if I want the pole of inaccessibility for all the features combined, the following both just give me [NaN, NaN]:

polylabel(turf.union(features).geometry.coordinates)
polylabel(features.map(feature => feature.geometry.coordinates))

Is this the intended behavior? Currently when I run into this situation I use polylabel for each one, then figure out which one is closest to the centroid of the unioned MultiPolygon. Maybe other option would be to get the pole of inaccessibility of the largest Polygon.

mourner commented 6 years ago

Yeah, Polylabel was designed to only handle individual polygons. For multipolygons, I think a good approach would be to implement #2 first, and then you'd just pick the point with the biggest distance.