gadomski / antimeridian

Correct GeoJSON geometries that cross the 180th meridian
https://antimeridian.readthedocs.io
Apache License 2.0
50 stars 6 forks source link

JavaScript port #109

Open m-mohr opened 7 months ago

m-mohr commented 7 months ago

Just opening this to express my interest in a JavaScript port. If someone aims at doing this, please let me know. At some point I may also get to porting it myself. So this is really just to collect people that are in need to this in JS...

gadomski commented 7 months ago

@m-mohr one hobby-project idea I had was to implement this in Rust and then make Python wrappers (an increasingly common pattern). Are there any examples of Javascript wrapping Rust that you've seen? If so, a Rust reimpl would become more attractive b/c it would support you as well.

m-mohr commented 7 months ago

I've seen Rust via Webassembly, but I'm trying to avoid that. I think this could be implemented in pure JS, too.

gadomski commented 7 months ago

Yeah Rust->WASM is pretty common — it's a possibility at least :-).

philipc2 commented 2 months ago

@m-mohr one hobby-project idea I had was to implement this in Rust and then make Python wrappers (an increasingly common pattern). Are there any examples of Javascript wrapping Rust that you've seen? If so, a Rust reimpl would become more attractive b/c it would support you as well.

I'm curious to how much faster a Rust implementation would be. I've attached some (old) benchmarks of the perfromance we've encountered for our Polygon visualization with UXarray. The row with "including antimeridian" uses this package to handle the crossings.

image

This may warrant a separate issue, but I've been interested in looking at some optimizations, maybe using Numba, since we call many of the functions hundreds of thousands of times when correcting each antimeridian face for our project when working with high-resolution datasets.

gadomski commented 2 months ago

Excellent timing, because I was just thinking today about how I haven't cared about performance in this library and wasn't sure if I was ever going to need to :-).

My motivating use case was a "fix once" scenario, where we were applying the antimeridian fix before ingesting to a data store. In that case, the time it took to do the antimeridian fix was dwarfed by so many other things, not least of which IO stuff.

Your case does seem to be different. I'm not sure that this library is the right tool for that job, but not not sure either :-).

gadomski commented 2 weeks ago

Dropping a note that we've been doing more and more rust-core-with-bindings-out work lately (e.g. https://github.com/developmentseed/cql2-rs/) so I'm warming to the idea of a rewrite of this package. We do use some shapely down in the algorithm, so I'm not convinced that it'll be easy. georust has been coming along but it's not always like-for-like in capabilities for algorithm work like this.

As an aside, I found a go port the other day: https://pkg.go.dev/github.com/go-geospatial/antimeridian