3

I need to write a parser in C++ which allows me to create a geojson geometry type from a valid WKT string.

So, I have a valid WKT string as input, and I need to convert it and write all coordinates etc. using rapidjson.

The thing I wonder about is whether or not the Geojson and WKT match, in terms of parsing. For example, it seems that a Geojson polygon type matches the coordinate and exterior / interior ring order.

So, are Geojson and WKT types equivalent, in terms of coordinate order and internal structure for all types (point, linestring, multipolygon?

That would make the conversion almost trivial.

benjist
  • 2,740
  • 3
  • 31
  • 58

1 Answers1

13

WKT is ideal for extremely-high precision datasets, since it can support various CRS'. The coordinate reference system for all GeoJSON coordinates, however, is WGS 84. So, in addition to the geographic coordinate reference system, the WKT format can also describe how to combine geocentric, projected, vertical, temporal and engineering coordinate reference systems; while "GeoJSON doesn’t limit you to longitude, latitude, elevation... high-dimensional data isn’t quite as common, since GeoJSON’s flexibility isn’t matched by other formats."

Another key difference between WKT and GeoJSON is that GeoJSON (based on JSON) is case sensitive whereas WKT is not. WKT is also capable of supporting curved shapes whereas GeoJSON is not.

As such, there is a definite need for conversion tools. Upon further research you can find a number of GeoJSON-emitting WKT parsers, including one authored by Tom MacWright (for browsers and node), that enable users to parse and stringify Well-Known Text into GeoJSON.

Not sure if you have figured this out but wanted to provide an answer for anyone else who might be interested.

Sources:

https://www.rfc-editor.org/rfc/rfc7946#section-4

http://www.macwright.org/2015/03/23/geojson-second-bite.html#coordinate

Community
  • 1
  • 1
Chelsea
  • 131
  • 1
  • 4