ropensci-archive / wicket

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

`WKT object has a different orientation from the default` error #19

Closed sckott closed 7 years ago

sckott commented 7 years ago

do you know what "The WKT object has a different orientation from the default" errors in wicket::validate_wkt refer to? that is, what needs to be fixed in the WKT for it to pass validation? googled it, but still not clear what this error really means - i have a feeling its related to order of points in a polygon, but not sure

e.g.,

wkt <- 'POLYGON((30 20, 10 40, 45 40, 30 20), (15 5, 5 10, 10 20, 40 10, 15 5))'
wicket::validate_wkt(wkt)
#>   is_valid                                                    comments
#> 1    FALSE The WKT object has a different orientation from the default
sckott commented 7 years ago

perhaps one of http://www.boost.org/doc/libs/1_63_0/libs/geometry/doc/html/geometry/reference/algorithms/correct.html or http://www.boost.org/doc/libs/1_47_0/libs/geometry/doc/html/geometry/reference/algorithms/reverse.html can be implemented here? (assuming the error in question here has to do with order of points in a geometry object)

Ironholds commented 7 years ago

Yeah, that's what it means! Correct seems the right approach.

Ironholds commented 7 years ago

So would you like a distinct wkt_correct function, or a parameter, or..?

sckott commented 7 years ago

Probably a separate fxn then e.g., if (!wkt_validate(foobar)) wkt_correct(foobar)

Ironholds commented 7 years ago

That works!*

*assuming an absence of vectorised usage

Ironholds commented 7 years ago

Give the github version a spin? And if it works - any more things to ask for soon? If not I'll throw in a new CRAN release.

sckott commented 7 years ago

Will test now ... 🕐

sckott commented 7 years ago

finding some problems, just a sec

sckott commented 7 years ago
wkt <- 'POLYGON((30 20, 10 40, 45 40, 30 20), (15 5, 5 10, 10 20, 40 10, 15 5))'
wicket::validate_wkt(wkt)
#>   is_valid                                                    comments
#> 1    FALSE The WKT object has a different orientation from the default

i didn't know what to do with this error at first

wicket::validate_wkt(wicket::wkt_correct(wkt))
#>   is_valid                                                            comments
#> 1    FALSE The WKT object has interior rings sitting outside its exterior ring

but i guess it makes sense that you can't have multiple polygons' in a POLYGON object unless one is inside the other, - so in this case need to make it a MULTIPOLYGON

wkt <- "MULTIPOLYGON(((15 5,40 10,10 20,5 10,15 5)), ((30 20,10 40,45 40,30 20)))"
validate_wkt(wicket::wkt_correct(wkt))
#>   is_valid comments
#> 1     TRUE     <NA>

can give further informative warning/message about this when it happens

Ironholds commented 7 years ago

Are those problems with this ticket or unrelated problems? I mean, the 'orientation default' one could be clarified to point to wkt_correct, absolutely, but the rings?

sckott commented 7 years ago

Sort of related, just sort of thinking out loud.

if a "orientation default" error happens, i'm catching that and then pointing the user to wkt_correct fxn - but you could include in this pkg if you think it makes sense

Ironholds commented 7 years ago

Have tweaked the error message now! I'm not sure how I'd turn the exterior/interior rings thing into a multipolygon specific error message because of course it can happen when the intent is in fact to have just a straight up polygon.

sckott commented 7 years ago

great, thanks