prioritizr / wdpar

Interface to the World Database on Protected Areas
https://prioritizr.github.io/wdpar
GNU General Public License v3.0
39 stars 5 forks source link

typology evaluation errors in wdpa_clean #20

Closed JonasGeschke closed 4 years ago

JonasGeschke commented 4 years ago

in addition to #19, I came across the following error in the "DNK" (Denmark) subset:

Error in CPL_geos_binop(st_geometry(x), st_geometry(y), op, par, pattern, : Evaluation error: TopologyException: side location conflict at 1029038.938 6096087.5300000003.

JonasGeschke commented 4 years ago

same in the "GRC" (Greece) subset:

Error in CPL_geos_binop(st_geometry(x), st_geometry(y), op, par, pattern, : Evaluation error: TopologyException: side location conflict at 2004406 4598038.

JonasGeschke commented 4 years ago

(just putting it down here to have a collection where errors pop up. the more often they appear, the more general the problem probably is ...)

JonasGeschke commented 4 years ago

same in the "BGR" (Bulgaria) subset:

Error in CPL_geos_binop(st_geometry(x), st_geometry(y), op, par, pattern, : Evaluation error: TopologyException: side location conflict at 2624909 4999187.7525391364.

JonasGeschke commented 4 years ago

same but different in the "AUT" (Austria) subset:

Error in CPL_geos_op2(op, st_geometry(x), st_geometry(y)) : Evaluation error: TopologyException: no outgoing dirEdge found at 1243901 5365689.0999999996.

JonasGeschke commented 4 years ago

just see similar errors are dealt with in #13. are the code fixes already on CRAN?

JonasGeschke commented 4 years ago

error in "BEL" Belgium subset:

Error in CPL_geos_binop(st_geometry(x), st_geometry(y), op, par, pattern, : Evaluation error: TopologyException: side location conflict at 427241 5675070.

JonasGeschke commented 4 years ago

error in "BRA" Brazil subset:

Error in CPL_geos_binop(st_geometry(x), st_geometry(y), op, par, pattern, : Evaluation error: TopologyException: side location conflict at -4449272 -152694.

jeffreyhanson commented 4 years ago

Thanks for reporting this - I'll take a look and see what I can do. In the meantime, if you're planning on dissolving all the polygons together or rasterizing the polygons then you can skip this "erasing overlaps" step erase_overlaps = TRUE.

JonasGeschke commented 4 years ago

Thanks for checking it. Probably the errors are done with the fix in #13, I didnt check this.

JonasGeschke commented 4 years ago

another error in "ITA" (Italy):

Error in CPL_geos_binop(st_geometry(x), st_geometry(y), op, par, pattern, : Evaluation error: TopologyException: side location conflict at 1025649 5066855.

JonasGeschke commented 4 years ago

another error in "ESP" (Spain):

Error in CPL_geos_union(st_geometry(x), by_feature) : Evaluation error: TopologyException: Input geom 0 is invalid: Self-intersection at or near point -517842 4727376.2839926593 at -517842 4727376.2839926593.

JonasGeschke commented 4 years ago

another error in "GBR" (United Kingdom):

Error in CPL_geos_binop(st_geometry(x), st_geometry(y), op, par, pattern, : Evaluation error: TopologyException: side location conflict at -307405 6250924.

JonasGeschke commented 4 years ago

I now re-run cleaning with the development version of wdpar. I mark all errors that are resolved with a thumb-up ...

JonasGeschke commented 4 years ago

Thanks for reporting this - I'll take a look and see what I can do. In the meantime, if you're planning on dissolving all the polygons together or rasterizing the polygons then you can skip this "erasing overlaps" step erase_overlaps = TRUE.

As a simple feedback question to this point: Sounds like you wouldn't use wdpa_clean for dissolving the WDPA. How would you do it?

JonasGeschke commented 4 years ago

For now, with use of the development version of wdpar, only GRC keeps to result in the error:

Error in CPL_geos_binop(st_geometry(x), st_geometry(y), op, par, pattern, : Evaluation error: TopologyException: side location conflict at 2624909 4999187.7525391364.

// Germany and US subset still to be done ...

JonasGeschke commented 4 years ago

error in "DEU" (Germany):

Error in CPL_geos_binop(st_geometry(x), st_geometry(y), op, par, pattern, : Evaluation error: TopologyException: side location conflict at 1273919.4773302849 5975333.6278681727.

JonasGeschke commented 4 years ago

also in "USA":

Error in CPL_geos_binop(st_geometry(x), st_geometry(y), op, par, pattern, : Evaluation error: TopologyException: side location conflict at -11068713 4016836.

jeffreyhanson commented 4 years ago

Hmm, you might need to increase the precision of the geometry calculations for these datasets. Try increasing the geometry_precision argument to 1e+6 or 1e+8 in wdpa_clean. This makes the geoprocesssing more robust/correct, but increases run time, so finding the right balance can be tricky.

jeffreyhanson commented 4 years ago

I've just pushed a patch which should make the overlap erasing procedure in wdpa_clean more robust, so hopefully this fixes the issues you're experiencing. Could you please try with the latest version?

JonasGeschke commented 4 years ago

Great, thanks, I will let you know how it works out.

JonasGeschke commented 4 years ago

Working with the development version of wdpar, there are currently no typology evaluation errors anymore (even without changing the precision).