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

algorithm fails on polygons around 180 longitude #67

Closed 77freab closed 4 years ago

77freab commented 4 years ago

i'm surprised that through all this years nobody found this. e.g. something like (lat, lon) 66.835993985609136,179.53481017154348, 66.570003009644324,-179.76022250492355, 66.751380624020030,-179.47256342463140, 67.039144593094719,179.70497469791349, will give you wrong bounding box (like polygon goes along all earth surface) 66.570003009644324,-179.76022250492355, 67.039144593094719,179.70497469791349, and of course wrong center 66.937436163870117,179.45104221247121, Screenshot 2020-09-10 123332

mourner commented 4 years ago

This library works on geometric coordinates x and y, it doesn't know anything about geographical coordinate systems and projections on purpose. To fix the case above, preprocess your coordinates so that they don't wrap (e.g. -179 should turn into 181).

77freab commented 4 years ago

oh, i'm sorry, i guess i misunderstood that algorithm takes lat,lon coordinates as it's map related. thanks for the hint though.