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

Support null feature geometries #176

Merged
merged 1 commit into from
Jun 5, 2023
Merged

Support null feature geometries #176

merged 1 commit into from
Jun 5, 2023

Conversation

s3cur3
Copy link
Contributor

@s3cur3 s3cur3 commented Nov 1, 2022

Hi there! Thanks for putting together such a rock-solid library. We've been using it happily in production for over a year. ☺️

I recently encountered an odd corner of the GeoJSON spec thanks to a user-submitted file, and I'd love to have a way to handle it in Geo. Per RFC 7946, a Feature object's "geometry" member can be either a Geometry object or a JSON null value.

Prior to this patch, you would get a BadMapError if you attempted to decode GeoJSON that included a feature with null geometry, thereby aborting the processing of all the data—in the case I encountered, one out of ~1000 features in a FeatureCollection was like this. With this patch, that Feature will be filtered out of the FeatureCollection, or in the case of a standalone Feature, it will be decoded to nil.

I'm not entirely convinced this is the right implementation—the GeoJSON RFC seems to indicate there may be some value in having an "unlocated" feature (I guess for its properties?). However, it seemed like a much bigger, scarier, and frankly less consistent change to introduce a non-located type into Geo.GeometryCollection or Geo.geometry(). (After all, these are explicitly about geometries, so the unlocated feature doesn't seem to fit into the abstraction at all.)

I'd love to get your thoughts on it. ☺️

[Per RFC 7946](https://www.rfc-editor.org/rfc/rfc7946#section-3.2), a Feature object's `"geometry"` member can be either a Geometry object or a JSON null value.

Prior to this patch, you would get a `BadMapError` if you attempted to decode GeoJSON that included a feature with null geometry; with this change, that feature will be filtered out of a FeatureCollection, or in the case of a standalone Feature, it will be converted to `nil`.

I'm not entirely convinced this is the right implementation—the GeoJSON RFC seems to indicate there may be some value in having an "unlocated" feature (I guess for its `properties`?). However, it seemed like a much bigger, scarier, and frankly less consistent change to introduce a non-located type into `Geo.GeometryCollection` or `Geo.geometry()`. (After all, these are explicitly about _geometries_, so the unlocated feature doesn't seem to fit into the abstraction at all.)
@s3cur3
Copy link
Contributor Author

s3cur3 commented Nov 2, 2022

A coworker notes that if this is the direction you'd like to go, we probably want to make a note in the README that null geometries get dropped (since this is maybe against the spirit of the FeatureCollection spec).

@axelson
Copy link
Contributor

axelson commented Jun 2, 2023

@bryanjos friendly ping :)

@bryanjos bryanjos merged commit 5ffa5be into felt:master Jun 5, 2023
@bryanjos
Copy link
Contributor

bryanjos commented Jun 5, 2023

Merged and I'll get it published today. Thanks and sorry it took so long!

@bryanjos
Copy link
Contributor

bryanjos commented Jun 5, 2023

Published: https://hex.pm/packages/geo/3.5.0

@axelson
Copy link
Contributor

axelson commented Jun 5, 2023

Awesome, thank you Bryan! 🎉

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

Successfully merging this pull request may close these issues.

3 participants