gavinr / world-countries-centroids

Center points of world countries - CSV and GeoJSON
https://gavinr.github.io/geojson-viewer/?url=https://cdn.jsdelivr.net/gh/gavinr/world-countries-centroids@v1/dist/countries.geojson
MIT License
31 stars 15 forks source link

Centroids outside country borders #7

Open caesar opened 2 years ago

caesar commented 2 years ago

For some countries, such as Chile, Croatia, and Israel, the centroid is outside the borders of the country. Is there a way to keep the point within the country?

gavinr commented 2 years ago

Thanks for the feedback - please see the readme for the issues/challenges.

With the recent v1.0 we switched to using the centroid of the largest land mass. I think that got them much closer to what you'd expect, but I understand your concern with having them always inside the polygon. I think we could run polylabel as the last step in the process, ensuring the point is within the polygon, but I'm not sure if that changes the project too much. I'll leave this open to see if others want to :+1: vote this issue, perhaps we'll do it in the future.

caesar commented 2 years ago

Thanks for pointing me to polylabel. It looks like it will probably do exactly what I want – which is not necessarily to find the actual "centre of mass" of a country, but to find a good place for a label.

As to whether you want to implement that here, of course it will depend on what the data is intended for, but I understand that it would potentially be a big change from what you have now.

merwok commented 1 year ago

Same for me, approximate centroid inside the country borders would be more interesting than pure exact centroid! I have seen Vietnam, Chile, Norway, Somalia and Israel.

Maybe two files are needed here, there isn’t one correct answer for every use case.

(BTW thanks for publishing this! very useful)