ropensci-archive / wicket

:no_entry: ARCHIVED :no_entry: Utilities to Handle WKT Spatial Data
Other
9 stars 1 forks source link

WKT linter #3

Closed Ironholds closed 7 years ago

Ironholds commented 7 years ago

There should be a function, lint_wkt, that:

  1. Takes a character vector of strings;
  2. For each one, identifies if they are valid WKT objects;
  3. Returns a data.frame of two columns: is_valid, of TRUE/FALSE values identifying if the string is valid, and comments, a character vector containing either an empty string or (in the case of invalid strings) a pointer to what's wrong with them.
sckott commented 7 years ago

Sounds good. 👍

Ironholds commented 7 years ago

Would it be useful to also provide a column of examples? so you get:

wicket:::validate_wkt("POINT (12,14)")
     is_valid  comments                               example
1    FALSE     Expected ')' at ',' in 'point (12,14)' POINT(12 14)
sckott commented 7 years ago

Yeah, sounds good

Ironholds commented 7 years ago

okay, validate_wkt is ready to test (I was slowed down by building GeometryCollection support in which is..non-trivial, as a parsing problem)

sckott commented 7 years ago

cool, all seems good to me.

validate_wkt(c(
  "polygon ((30 10, 40 40, 20 40, 10 20, 30 10))",
  "POLYGON ((30 10, 40 40, 20 40, 10 20))",
  "POINT(-71.064544 42.28787)",
  "POINT(-71.064544, 42.28787)",
  "POINT(-71.064544 42.28787))",
  "FOO(-71.064544 42.28787))"
))
#>   is_valid                                                comments
#> 1     TRUE                                                    <NA>
#> 2     TRUE                                                    <NA>
#> 3     TRUE                                                    <NA>
#> 4    FALSE    Expected ')' at ',' in 'point(-71.064544, 42.28787)'
#> 5    FALSE Too much tokens at ')' in 'point(-71.064544 42.28787))'
#> 6    FALSE  Object could not be recognised as a supported WKT type