twpayne / go-geom

Package geom implements efficient geometry types for geospatial applications.
BSD 2-Clause "Simplified" License
854 stars 106 forks source link

Use mapstructure to decode geometry #188

Open bastienbc opened 4 years ago

bastienbc commented 4 years ago

Hi,

I'm using your library to convert some mongodb documents into postgis rows. The way I do it is simple, with mongodb I decode the bson into a struct with map[string]interface{}, Then I use your library to convert the geojson part into ewkb.

But to do so I have to first use json.Marshal, because the Unmarshal method from geojson needs a json (in bytes) to Unmarshal it. So it's Bson -> map[string]interface{} -> json -> Geometry

Would it be possible to use mapstructure to encode/decode (using maybe separate functions to not break the API), to prevent this kind of pattern? It should be pretty simple from my very short experience with mapstructure in the past.

twpayne commented 4 years ago

I would be concerned about the performance overhead of using mapstructure for every conversion, but there's no reason that such code couldn't be included as a separate encoding package and would happily review a PR adding it.

However, if you're doing a one-off conversion from MongoDB to PostGIS, do the extra steps that you have to perform really matter?