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

Add toWKT() implementation #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Baresse
Copy link

@Baresse Baresse commented Mar 5, 2015

Hello,
This library is really great and has make me saved a bunch of time. That's why I wanted to contributed in return and here is my pull-request.

WKT format (http://en.wikipedia.org/wiki/Well-known_text) is used by several other frameworks and tools around and I've had to transform GeoJSON geometries from and into WKT. In this pull request I've added the implementation of a new method String toWKT() into the following geometries :

  • Point
  • MultiPoint
  • LineString
  • MultiLineString
  • Polygon
  • MultiPolygon

If you enjoy this PR I can if you are interested in make another one in order to implement new static methods on these geometries like Point parseWKT(String wkt) in the Point class, MultiPoint parseWKT(String wkt) in the MultiPoint class, etc.

…neString, Polygon and MultiPolygon geometries.
@grundid
Copy link
Member

grundid commented Mar 5, 2015

Thank you for the PR.
I'm not familiar with WKT but looking at the implementation I'm not sure if the toWKT methods should return null if there are no coordinates.
Could you point me to the specification? Otherwise I would suggest to return an empty string in this case.

On the other hand, I'm wondering why we should add WKT to a GeoJSON library. Is the a parser like Jackson for WKT? Maybe it would be better to write a parser and only add some annotations to these classes. What do you think?

@Baresse
Copy link
Author

Baresse commented Mar 5, 2015

It's ok to return an empty string instead of null when the geometry is empty. It's just a matter of convention to be aware of.

To answer about why this feature should be included here, it is because may be like me some geojson-jackson users will need to transform geometry into a WKT format. It's just a format transformation feature.

WKT is an OGC format which is used in OGC standard for instance in some OpenSearch Extension, but also in some tools which rely on this "simple" format to get geometry as parameter (or even HTTP GET parameters). Here are some link about this format :

@drish
Copy link

drish commented Aug 21, 2018

hello guys,

this pr is pretty useful, any chance this is getting merged ?

@antinodes
Copy link

FYI, we implemented this using the visitor pattern. It's been very useful, especially interacting with PostGIS since EWKT are automatically recognized. If you want I can share the code. It would be super useful if there was an E/WKT parser included in this library.

Thanks for the great work!

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.

4 participants