Centroid coordinates for closed ways #689
-
I'd like to understand how i can compute with osmium the centroid of a closed way and get back the same result as what's being processed with TileMaker. Let's take this closed way as an example: https://www.openstreetmap.org/edit?way=23906678#map=19/-36.86075/174.77782 With Osmium, I've tried 3 methods:
They all look similar, but none is exactly providing the same result as Tilemaker's. I'd need to analyse how much digits really make sense to be kept (maybe 5 are enough?) and how I could truncate tilemaker to the same amounts of digits as I'd need to have exact same values between the tile metadata (tilemaker) and the dataset (osmium). Happy to hear your thoughts! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
tilemaker uses 5 decimal points when writing GeoJSON, so I'd probably use that: tilemaker/include/geojson_writer.h Line 147 in 07e878f In v3, the centroid position is calculated using mapbox's polylabel algorithm on the outer ring with the largest area. There are implementations of this in many languages, hopefully you can find one that fits the language you need. You can also get the centroid in Lua and write it out during tile generation. I wrote a short article about that here: https://www.hikeratlas.com/blog/tilemaker-autosuggest-index |
Beta Was this translation helpful? Give feedback.
You can tell tilemaker to use Boost.Geometry's centroid algorithm rather than the Mapbox-originated polylabel one - see CONFIGURATION.md. But ultimately, I suspect the algorithms will always be slightly different between implementations so you won't necessarily get the exact same result.