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

Easier serialization of wkt with ToWkt::wkt_string/write_wkt #89

Merged
merged 2 commits into from Apr 14, 2022

Conversation

michaelkirk
Copy link
Member

@michaelkirk michaelkirk commented Apr 1, 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.
  • I ran cargo fmt

Fixes #55 - adds an easier API to serialize a geo-type.

Depends on #86, so merge that first. Merged!

partially conflicts with #88, because I'm relying on the ToWkt trait. superseded!

@michaelkirk michaelkirk mentioned this pull request Apr 1, 2022
3 tasks
@michaelkirk michaelkirk mentioned this pull request Apr 1, 2022
@michaelkirk michaelkirk changed the title ToWkt::to_wkt_string ToWkt::wkt_string Apr 9, 2022
Also renamed "to_wkt_string" to just "wkt_string", it's shorter and I
don't think anything is lost.
@categulario
Copy link
Contributor

At this point I do think that this impl goes in the right direction, but it is not (for me) the best possible scenario

@michaelkirk
Copy link
Member Author

michaelkirk commented Apr 13, 2022

Ok, l'm going to call this ready for review. Please take a look anyone who's interested.

@michaelkirk michaelkirk changed the title ToWkt::wkt_string Easier serialization of wkt with ToWkt::wkt_string/write_wkt Apr 13, 2022
Copy link
Member

@urschrei urschrei left a comment

Choose a reason for hiding this comment

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

I like where this has ended up.

@michaelkirk
Copy link
Member Author

bors r=urschrei

@bors
Copy link
Contributor

bors bot commented Apr 14, 2022

Already running a review

@bors
Copy link
Contributor

bors bot commented Apr 14, 2022

Build succeeded:

@bors bors bot merged commit 0d4404c into main Apr 14, 2022
@bors bors bot deleted the mkirk/to-wkt-string branch April 14, 2022 19:33
bors bot added a commit that referenced this pull request Apr 26, 2022
92: impl ToWkt for inner geo_type variants, allow non-geotypes to impl ToWkt r=uschrei a=michaelkirk

- [x] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/master/CODE_OF_CONDUCT.md).
- [x] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
- [x] I ran cargo fmt
---

~~Draft because it's based on #89, so please review that first.~~ **update:** merged!

The user benefit here is the implementation of `ToWkt` directly on the inner geometry enums so...

instead of:
```
let point: geo_types::point!(x: 1.0, y: 2.0);
let geo_geometry = geo_types::Geometry::from(point);
let string = geo_geometry.wkt_string();
assert_eq!("POINT(1 2)", string);
```

you can do:
```
let point: geo_types::point!(x: 1.0, y: 2.0);
let string = point.wkt_string();
assert_eq!("POINT(1 2)", string);
```

I also wanted to detangle ToWkt from geo-types, so that (hypothetical) non-geo-types users could implement it.

The majority of the lines changed are in [ToWkt for non-geotypes](75ab496), but it's a misleading large diff (sorry). Largely it's a cut and paste job: I cut the `geo-types` specific code from `towkt.rs` and pasted it into the new `geo_types_to_wkt.rs`.

For symmetry, and to better reflect it's functionality, I renamed the `conversions` module to `geo_types_from_wkt`.

Co-authored-by: Michael Kirk <michael.code@endoftheworl.de>
michaelkirk added a commit that referenced this pull request Apr 27, 2022
…ediate representation.

Note that this isn't a performance change. It's about (hopefully) making
the library easier to use.

This is a corollary to #89, but for
reading WKT, rather than writing. As we discussed there, probably there
is no reason for the user to care about the Wkt struct.

Note that the intermediate representation is still used (for now!), but
the user is no longer required to interact with it.

The road is open though for having a direct translation from Wkt text to
the geo-types (or whatever) represenation (see geozero for inspiration).
michaelkirk added a commit that referenced this pull request Apr 27, 2022
…ediate representation.

Note that this isn't a performance change. It's about (hopefully) making
the library easier to use.

This is a corollary to #89, but for
reading WKT, rather than writing. As we discussed there, probably there
is no reason for the user to care about the Wkt struct.

Note that the intermediate representation is still used (for now!), but
the user is no longer required to interact with it.

The road is open though for having a direct translation from Wkt text to
the geo-types (or whatever) represenation (see geozero for inspiration).
michaelkirk added a commit that referenced this pull request Apr 27, 2022
…ediate representation.

Note that this isn't a performance change. It's about (hopefully) making
the library easier to use.

This is a corollary to #89, but for
reading WKT, rather than writing. As we discussed there, probably there
is no reason for the user to care about the Wkt struct.

Note that the intermediate representation is still used (for now!), but
the user is no longer required to interact with it.

The road is open though for having a direct translation from Wkt text to
the geo-types (or whatever) represenation (see geozero for inspiration).
michaelkirk added a commit that referenced this pull request Apr 27, 2022
…ediate representation.

Note that this isn't a performance change. It's about (hopefully) making
the library easier to use.

This is a corollary to #89, but for
reading WKT, rather than writing. As we discussed there, probably there
is no reason for the user to care about the Wkt struct.

Note that the intermediate representation is still used (for now!), but
the user is no longer required to interact with it.

The road is open though for having a direct translation from Wkt text to
the geo-types (or whatever) represenation (see geozero for inspiration).
michaelkirk added a commit that referenced this pull request Apr 28, 2022
…ediate representation.

Note that this isn't a performance change. It's about (hopefully) making
the library easier to use.

This is a corollary to #89, but for
reading WKT, rather than writing. As we discussed there, probably there
is no reason for the user to care about the Wkt struct.

Note that the intermediate representation is still used (for now!), but
the user is no longer required to interact with it.

The road is open though for having a direct translation from Wkt text to
the geo-types (or whatever) represenation (see geozero for inspiration).
bors bot added a commit that referenced this pull request Apr 28, 2022
95: FromWkt trait for reading WKT without exposing the user to the intermediate representation. r=urschrei a=michaelkirk

- [x] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/master/CODE_OF_CONDUCT.md).
- [x] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
- [x] I ran cargo fmt
---

Draft because it's based on #94. Please review that first.

--- 

Note that this isn't a performance change. It's about (hopefully) making
the library easier to use.

This is a corollary to #89, but for
reading WKT, rather than writing. As we discussed there, probably there
is no reason for the user to care about the Wkt struct.

Note that the intermediate representation is still used (for now!), but
the user is no longer required to interact with it.

The road is open though for having a direct translation from Wkt text to
the geo-types (or whatever) represenation (see geozero for inspiration).

--- 

I also added the missing GeometryCollection::from(wkt) implementation to make this work for all geo-types.

Co-authored-by: Michael Kirk <michael.code@endoftheworl.de>
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.

Better way to serialize to wkt?
3 participants