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

Store a single geometry inside Wkt #72

Merged
merged 3 commits into from
Jan 20, 2022
Merged

Store a single geometry inside Wkt #72

merged 3 commits into from
Jan 20, 2022

Conversation

lnicola
Copy link
Member

@lnicola lnicola commented Jan 19, 2022

  • 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.

r? @urschrei

@@ -131,28 +131,19 @@ pub struct Wkt<T>
where
T: WktFloat,
{
pub items: Vec<Geometry<T>>,
pub item: Geometry<T>,
Copy link
Member Author

Choose a reason for hiding this comment

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

Wkt<T>(Geometry<T>) might be better here? Not sure.

Copy link
Member

Choose a reason for hiding this comment

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

No strong opinion from me, but I have a slight preference for how you have it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I'd prefer renaming Geometry to Wkt or an into_geometry() method.

Copy link
Member

Choose a reason for hiding this comment

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

No strong opinion from me, but I have a slight preference for how you have it.

Same, but do what you feel is best here. Where does the into_geometry() method come into it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Where does the into_geometry() method come into it?

I meant Wkt::into_geometry(self) -> Geometry.

I'd say keep item for now and maybe change it in a follow-up PR if we figure out a better way.

@michaelkirk
Copy link
Member

I just noticed that cargo test-all-features doesn't seem to account for the "implicit features" of optional dependencies.

$ cargo test --all-features                                                           
   Compiling wkt v0.9.2 (/Users/mkirk/src/georust/wkt)    
warning: `#[macro_use]` only has an effect on `extern crate` and modules
  --> src/conversion.rs:50:1    
   | 
50 | #[macro_use]                  
   | ^^^^^^^^^^^^                                                                     
   |
   = note: `#[warn(unused_attributes)]` on by default      
                                           
error[E0609]: no field `items` on type `Wkt<_>`       
  --> src/deserialize.rs:75:16
   |
75 |         if wkt.items.len() == 1 {
   |                ^^^^^ help: a field with a similar name exists: `item`

error[E0308]: mismatched types
  --> src/deserialize.rs:75:31
   |
62 | impl<'de, T> Visitor<'de> for GeometryVisitor<T>
   |           - this type parameter
...
75 |         if wkt.items.len() == 1 {
   |                               ^ expected type parameter `T`, found integer
   |

@lnicola
Copy link
Member Author

lnicola commented Jan 19, 2022

I think it actually failed, but I fixed it in the meantime and did a force-push.

@michaelkirk
Copy link
Member

Oh you're right! Sorry.

@lnicola lnicola marked this pull request as ready for review January 20, 2022 06:42
Copy link
Member

@michaelkirk michaelkirk left a comment

Choose a reason for hiding this comment

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

I have one non-blocking reservation: Does this break conformance with the spec? I pretty quickly surrendered before the very long and (to me) unnavigable spec.

More pragmatically, I tested that this seems to align us with the behavior of postgis: Like the highlander, There can be only one top level geometry.

eg. postgis will not parse an entity like:

sql=# SELECT ST_GeomFromText('POINT(1 2) POINT(2 3)');
ERROR:  parse error - invalid geometry
HINT:  "POINT(1 2) POINT(2 " <-- parse error at position 19 within geometry
sql=# SELECT ST_GeomFromText('POINT(1 2), POINT(2 3)');
ERROR:  parse error - invalid geometry
HINT:  "POINT(1 2), PO" <-- parse error at position 14 within geometry

So, the only way to have multiple geometries in postgis, like in this PR, is to explicitly wrap with a Geometry Collection:

SELECT ST_GeomFromText('GEOMETRYCOLLECTION(POINT(1 2), POINT(2 3))');

So this LGTM, but let's see what @urschrei thinks.

@lnicola
Copy link
Member Author

lnicola commented Jan 20, 2022

It's just as conforming as the parser, since it (before my PR) parsed only one geometry out of the string.

@urschrei
Copy link
Member

I feel the same: we're in line with PostGIS, in a less confusing way than before, so lgtm.

@lnicola
Copy link
Member Author

lnicola commented Jan 20, 2022

No opposition to merging and @urschrei said it's fine to merge this before #71, so let's do that.

bors r+

@bors
Copy link
Contributor

bors bot commented Jan 20, 2022

🔒 Permission denied

Existing reviewers: click here to make lnicola a reviewer

@michaelkirk
Copy link
Member

Added! Can you please try again?

@lnicola
Copy link
Member Author

lnicola commented Jan 20, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Jan 20, 2022

Build succeeded:

@bors bors bot merged commit 8e22c63 into master Jan 20, 2022
@lnicola lnicola deleted the wkt-item branch January 20, 2022 18:01
@lnicola
Copy link
Member Author

lnicola commented Jan 20, 2022

I like how it almost takes longer to install cargo-all-features than it takes to run all the tests.

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