georust / geozero

Zero-Copy reading and writing of geospatial data.
Apache License 2.0
342 stars 35 forks source link

How to convert projection #12

Closed musicformellons closed 2 years ago

musicformellons commented 2 years ago

As I do encounter mentions of SRID in the issues and docs I am a bit puzzled if this library can also convert from one projection to another? Or would I need to use it in combination with https://github.com/georust/proj and if so, is there an example maybe how to do that?

michaelkirk commented 2 years ago

geozero is principally concerned with reading and writing different formats of geospatial data, but it doesn't really have any facilities for transforming the data.

Or would I need to use it in combination with https://github.com/georust/proj

That should work! The specifics will depend on what your input and output are exactly.

proj crate knows how to work with geo-types geometries, so my approach would probably be something like:

  1. use geozero's geo-types reader, depending on your particular format (see the proj README for examples)
  2. use the to_geo method to get geo-types geometries
  3. use the proj crate to project the geo-types geometries to whatever SRS you want
  4. use geozero to write back to whatever supported format you'd like
frewsxcv commented 2 years ago

There's now a Transform trait in the proj crate (and also reexported in the geo crate) that you can use that will make this a little simpler https://docs.rs/proj/latest/proj/trait.Transform.html

michaelkirk commented 2 years ago

I don't think there's anything left to do here, so closing.

michaelkirk commented 2 years ago

@musicformellons - I actually ended up trying to do something like what you mentioned and had a hard time. 😅

I was able to go from geojson -> geo_types -> proj -> geojson easy enough.

But the complication I encountered was that I didn't see a non-terrible way to maintain the geojson's properties (since they are lost at the "-> geo_types" step.

Did you end up getting something like this to work?

musicformellons commented 2 years ago

@michaelkirk I think in the end I might not needed it. I see only 'proj' and 'geo-types' in my cargo.toml. I was working with shapefiles. So can't help I'm afraid.