prioritizr / wdpar

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

request for "wdpa_merge()" #22

Closed JonasGeschke closed 2 years ago

JonasGeschke commented 4 years ago

Hi @jeffreyhanson, while I am about to finish cleaning all WDPA country subsets, I tried putting them all together, in order to finally get a "flattened WDPA layer". However, both with st_combine or st_union and with rbind and a second wdpa_clean it seems not to be working properly. I always get some areas overlapping and thus double counting in any area calculations. Therefore, as you know the details of your package: Could you put together a function wdpa_merge that puts together subsets of the WDPA and cleans the overlaps between countries? (in theory this should be transboundary protected areas only) That would be great ...

jeffreyhanson commented 4 years ago

Hi, yeah sometimes st_union can output overlapping polygons depending on the precision of the geoprocessing calculations. Maybe something like this would work (assuming you called your rbind'd WDPA dataset w)? If it doesn't, try increasing the prec object.

library(sf)
library(lwgeom)
prec <- 1e+8
x <- st_make_valid(st_precision(st_union(st_precision(st_combine(x), prec)), prec))
jeffreyhanson commented 4 years ago

Just to follow up, did my suggestion work? Or are you still experiencing issues with dissolving the WDPA? If possible, I'd recommend using ESRI ArcMap to process the global WDPA since it's more robust to geometry issues and runs a lot faster.

JonasGeschke commented 4 years ago

Hi, thanks for your follow-up. I am still on it ...

jeffreyhanson commented 4 years ago

OK - let me know how it goes. You might need to try various precision levels. I would also recommend dissolving each country together separately and then assembling the global dataset. However, this is still going to be a very difficult (if impossible) task given the limits of FOSS GIS software.

JonasGeschke commented 4 years ago

Actually #19 is my bottleneck at the moment. It keeps coming up. Would be great if you can have a look at this.

JonasGeschke commented 4 years ago

I am working on a HPC cluster now, so processing capacity is no bottleneck anymore. It seems to be working with simply using wdpaunion <- st_union(st_make_valid(wdpaclean)). Will let you know if succeeding when the whole dataset is done – and then also close the issue if successful.

jeffreyhanson commented 2 years ago

I've just added a wdpa_dissolve() to the latest GitHub version which should implement this functionality (see https://prioritizr.github.io/wdpar/reference/wdpa_dissolve.html). Please feel free to reopen this issue if you run into any issues with it.