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

What kind of file format does polylabel accept? #43

Closed gabimoncha closed 6 years ago

gabimoncha commented 6 years ago

I tried with geojson and json. But it seems that content of the file must be specific. Can you please add in documentation what kind of file format does it accept and also, how should the content format be?

mourner commented 6 years ago

GeoJSON polygon format is an array of rings, where each ring is an array of [x, y] pairs.

msageryd commented 6 years ago

What do you mean by "file"? Are you using the original JavaScript library? In that case you should just feed the polylabel function with an array of points where each point is an array.

example: [[1,1],[1,2],[2,2],[2,1]]

mourner commented 6 years ago

@msageryd one level deeper, because polygon has multiple rings (an outer ring and holes).

msageryd commented 6 years ago

@mourner Yes, of course. Sorry for neglecting that.

Updated example for @gabrielmoncea: const p = polylabel([[[1,1],[1,2],[2,2],[2,1]]], 1.0) (one ring)

gabimoncha commented 6 years ago

Nice. I manage to discover how to get the point for each polygon in my geojson. Can we update the package to work with Geojsons? We basically just need a loop over each feature getting the geometry.coordinates[0]