georust / geo

Geospatial primitives and algorithms for Rust
https://crates.io/crates/geo
Other
1.47k stars 190 forks source link

Helper for converting between Mercator and Euclidean coordinates #1165

Open dabreegster opened 3 months ago

dabreegster commented 3 months ago

I use something like https://github.com/dabreegster/ltn/blob/main/backend/src/common/mercator.rs in many of my projects that're focused on one roughly city-sized area at a time. Starting from WGS84 coordinates, I find the bounding box, use Haversine distance to find the width and length of the bbox, and then linearly interpolate to transform between the two coordinate systems.

Would something like this be useful in geo? There's some cleanup of the API to do, but before I make a clean PR, I wanted to see if something like this is appropriate/useful.

kylebarron commented 3 months ago

Why not use spherical mercator? A la https://github.com/mapbox/sphericalmercator? You don't need a haversine distance to find the initial bounding box; you just project onto a normal grid. Supercluster has some simple functions for this: https://github.com/mapbox/supercluster/blob/fff7326c0232c3d488afee93c93c6b8eac5bcb46/index.js#L407-L424