Giter Site home page Giter Site logo

Comments (10)

jeffreyhanson avatar jeffreyhanson commented on May 21, 2024

Hi @fabeit,

Thanks for reaching out! Just to check, when you're dissolving the global dataset by country, are you using wdpa_dissolve()? If so, I would suggest to try increasing geometry_precision and see if that fixes it (e.g., you might need to try some really high values for it to work)?

from wdpar.

fabeit avatar fabeit commented on May 21, 2024

Thanks for the quick reply. Yes I am using that function and it stalls or gives errors. I can try with a larger value but how do I dissolve per country?

from wdpar.

jeffreyhanson avatar jeffreyhanson commented on May 21, 2024

Yeah, you could do something like this (see below). The code assumes that x is your cleaned version of the data, and the column COUNTRY has the country name for each protected area. I haven't tested this, so it might need some debugging.

# load packages
library(wdpar)
library(sf)
library(dplyr)

# dissolve by country
result <-
  x %>%
  split(.$COUNTRY) %>% 
  lapply(function(y) {
    n <- y$COUNTRY[[1]]
    y <- wdpa_dissolve(y)
    y$COUNTRY <- n
    y
  }) %>% 
  bind_rows()

from wdpar.

fabeit avatar fabeit commented on May 21, 2024

Thank you for the suggestion Jeffrey. Unfortunately I run into the same error that I get when I tried to dissolve the global data set such as

Error in wk_handle.wk_wkb(wkb, s2_geography_writer(oriented = oriented, :
Loop 2 is not valid: Edge 2 crosses edge 4y, I also tried geometry_precision = 1500000000 and I get

Error in wk_handle.wk_wkb(wkb, s2_geography_writer(oriented = oriented, :
Loop 0 edge 314 crosses loop 5 edge 24

There seems no way to do this in a reasonable way, the MPA data is too messy. It's quite frustrating.

from wdpar.

jeffreyhanson avatar jeffreyhanson commented on May 21, 2024

Hmm, do you know which country is causing the error?

Also, you could try repairing the geometries again before dissolving it. E.g., something like this:

# load packages
library(wdpar)
library(sf)
library(dplyr)

# dissolve by country
result <-
  x %>%
  split(.$COUNTRY) %>% 
  lapply(function(y) {
    n <- y$COUNTRY[[1]]
   print(paste("starting", n))
    y <- sf::st_set_precision(y, 1e5)
    y <- sf::st_make_valid(y)
    y <- wdpa_dissolve(y)
    y$COUNTRY <- n
    y
  }) %>% 
  bind_rows()

Also, if you have access to ArcGIS, you cold try using the repair geometry tool and then the dissolve tool? IME ArcGIS is better at handling these geometry issues.

from wdpar.

fabeit avatar fabeit commented on May 21, 2024

That's a good idea to debugging the problem. It seems that it gets stuck at Australia. I will have to try to exclude it but I doubt that it will go smoothly for all other countries, especially the ones that have complex geometries.

Unfortunately I don't have access to ArcGIS. I'm surprised that there's no publicly accessible this dissolved shape file of all MPAs.

from wdpar.

jeffreyhanson avatar jeffreyhanson commented on May 21, 2024

Hmm, could you try increasing the precision in the above coded to something super high like 1e10?

Also, just to check, are you using the latest version of the sf and lwgeom packages?

Yeah, the license for the WDPA prohibits redistributing the database and any derived datasets (see https://www.protectedplanet.net/en/legal), which means people can't directly share any cleaned up or pre-processed versions of the dataset.

from wdpar.

jeffreyhanson avatar jeffreyhanson commented on May 21, 2024

Just to follow up @fabeit, were you able to resolve this issue? Anything I can do to help?

from wdpar.

fabeit avatar fabeit commented on May 21, 2024

I was never able to resolve the issue. I ended up asking UNEP to send me a shapefile with dissolved polygons for each country. I think something like this should be made public.

from wdpar.

jeffreyhanson avatar jeffreyhanson commented on May 21, 2024

Ah - sorry, I wasn't able to help with resolving it. Glad to hear that you got the data you needed in the end.

from wdpar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.