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

Implement geo_traits for geojson types. #245

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

frewsxcv
Copy link
Member

@frewsxcv frewsxcv commented Oct 25, 2024

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

@frewsxcv frewsxcv marked this pull request as draft October 25, 2024 04:31
@kylebarron
Copy link
Member

Still need to implement for Feature (and FeatureCollection?), but that should be easy.

I wouldn't necessarily expect the traits to be implemented on Feature and FeatureCollection. I think it's fine if they're only implemented on the geometry structs.

@frewsxcv frewsxcv marked this pull request as ready for review October 27, 2024 19:25
@@ -12,11 +12,14 @@ edition = "2018"

[features]
default = ["geo-types"]
geo-traits = ["dep:geo-traits", "dep:bytemuck"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about making this a default dependency? I wouldn't imagine it would add too much to compilation time?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me! As long as we keep it optional

src/geo_traits_impl/multi_point.rs Show resolved Hide resolved
match self {
crate::GeoJson::Feature(f) => f.as_type(),
crate::GeoJson::FeatureCollection(_fc) => {
unimplemented!("TODO")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO here needs to be completed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume a FeatureCollection, interpreted as a geometry-trait, would map to a GeometryCollection?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep exactly. FeatureCollection.as_type is already implemented to return a GeometryCollection. We just need to add that detail here in GeoJson::FeatureCollection.

}

fn dim(&self) -> Dimensions {
self.coord(0).unwrap().dim() // TODO: is this okay?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO to remove / resolve

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An empty linestring is a normal occurrence, so I don't think we should be unwrap here.

My guess would be something like Dimensions::Unknown(0) or just Dimensions::Xy since it's usually correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should document in geo-traits the expected values of Dimensions::Unknown and whether 0 should be allowed or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We face a similar issue in WKT: georust/wkt#125

WKT seemingly has a solution, but it doesn't really apply to geojson, because the dimensions of geojson are only ever implicit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say it's not really an issue in WKT because the WKT string does explicitly say what dimension it is. Here it truly is implicit.

match self {
crate::GeoJson::Feature(f) => f.as_type(),
crate::GeoJson::FeatureCollection(_fc) => {
unimplemented!("TODO")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume a FeatureCollection, interpreted as a geometry-trait, would map to a GeometryCollection?

}

fn dim(&self) -> Dimensions {
self.coord(0).unwrap().dim() // TODO: is this okay?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An empty linestring is a normal occurrence, so I don't think we should be unwrap here.

My guess would be something like Dimensions::Unknown(0) or just Dimensions::Xy since it's usually correct.

Self: 'b;

fn dim(&self) -> Dimensions {
self.geometry(0).unwrap().dim()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, we should not crash on a valid geometry like GEOMETRYCOLLECTION EMPTY

}

fn dim(&self) -> Dimensions {
self.line_string(0).unwrap().dim()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

type GeometryType<'b> = &'b crate::Feature;

fn dim(&self) -> Dimensions {
self.features.first().unwrap().dim()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just marking all these so they don't get missed.

src/geo_traits_impl/geometry_collection.rs Show resolved Hide resolved
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 this pull request may close these issues.

3 participants