Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeoJSON::from(geo:Geometry) / GeoJSON::from(geo:Polygon) / etc #163

Closed
michaelkirk opened this issue Apr 1, 2021 · 2 comments · Fixed by #165
Closed

GeoJSON::from(geo:Geometry) / GeoJSON::from(geo:Polygon) / etc #163

michaelkirk opened this issue Apr 1, 2021 · 2 comments · Fixed by #165

Comments

@michaelkirk
Copy link
Member

(Pulled out of the discussion #162 (comment))

The GeoJSON API could be more intuitive for the common case of wanting to serialize a bunch of geometric data, without wanting to leverage foreign members or other geojson features.

Specifically, I propose the following methods work for all geo_types::Geometry variants:

let a_polygon: = GeoJson::from(geo::Polygon::new(...))

let another_polygon: GeoJson = GeoJson::from(geo::Geometry::Polygon(Polygon::new(...)))

let geometry_collection: GeoJson = GeoJson::from_iter(vec![Polygon::new(...),])

With an implementation something like:

impl<T: geo_types::CoordFloat> FromIterator<geo_types::Polygon<T>> for GeoJson {
    fn from_iter<P>(polygons: P) -> Self
        where P: IntoIterator<Item = geo_types::Polygon<T>>
    { 
        let gc = geo_types::GeometryCollection::from_iter(polygons);
        let fc = FeatureCollection::from(&gc);
        GeoJson::from(fc)
    }
} 
@michaelkirk
Copy link
Member Author

@urschrei - just so we're not duplicating work - were you planning to take a go at this? Otherwise I will.

@urschrei
Copy link
Member

urschrei commented Apr 2, 2021

Happy for you to take it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants