ropensci-archive / wellknown

:warning: ARCHIVED :warning: WKT <-> GeoJSON
Other
17 stars 3 forks source link

wkt validator #9

Closed sckott closed 8 years ago

sckott commented 9 years ago

No good solution right now for validating wkt strings. Could use geos C library, but way to heavy just for validating. There doesn't seem to be any web APIs for this. The Python client geomet simply throws an error if the string doesn't parse.

Could work on a R validator - then reimplement in C if super slow.

sckott commented 9 years ago

WKT spec

http://cl.ly/aFKD/06-103r4_Implementation_Specification_for_Geographic_Information_-_Simple_feature_access_-_Part_1_Common_Architecture_v1.2.1%20(1).pdf

starting pg 52

raymondben commented 8 years ago

Some possible WKT validation errors (I am not super-familiar with the WKT spec, so don't know if these should be failing or not). They are all to do with extra whitespaces:

The starting point, which validates as TRUE:

wellknown::lint("POLYGON((154 -43.74, 154 -9, 112.9 -9, 112.9 -43.74, 154 -43.74))")

And variants thereon:

## whitespace before commas
wellknown::lint("POLYGON((154 -43.74 , 154 -9, 112.9 -9, 112.9 -43.74, 154 -43.74))")

## whitespace after ((
wellknown::lint("POLYGON(( 154 -43.74, 154 -9, 112.9 -9, 112.9 -43.74, 154 -43.74))")

## whitespace before ))
wellknown::lint("POLYGON((154 -43.74, 154 -9, 112.9 -9, 112.9 -43.74, 154 -43.74  ))")

These all fail validation (wellknown v0.1.0). FWIW these three are accepted by rgeos::readWKT (rgeos v 0.3-8).

sckott commented 8 years ago

thanks, i'll have a look

sckott commented 8 years ago

okay, try reinstalling, should work now. devtools::install_github("ropensci/wellknown")

raymondben commented 8 years ago

Yup, those pass now. Thanks

sckott commented 8 years ago

great!

sckott commented 8 years ago

@raymondben keep in mind that this wkt linter is just R regex, so it is lightweight, and avoids requiring GDAL/GEOS - thanks for helping make it better