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

class error in wdpa_clean #19

Closed JonasGeschke closed 4 years ago

JonasGeschke commented 4 years ago

After trying around with the sp package for quite a bit, I will now try to flatten the WDPA with wdpar. The first error I came across, however, is as follows:

Error in st_cast_sfc_default(x) : list item(s) not of class sfg

It came in the WDPA subset for "SOM" (Somalia). Would be great if you can have a look at it. Thanks and best regards, Jonas

JonasGeschke commented 4 years ago

Are you @jeffreyhanson around at the sri2020.org conference? Would be great meeting you.

jeffreyhanson commented 4 years ago

Hmm - that's strange. Could you please post a reproducible example showing this? Are you using as(x, "sf") to convert the sp class objects to sf class objects before using wdpa_clean?

No, I'm not attending that conference unfortunately - it looks pretty interesting! Yeah - it would be great to catch up. I'm based in Palmerston North in New Zealand - I don't suppose you're travelling to New Zealand while you're in the region?

JonasGeschke commented 4 years ago

Well no I didnt convert the WDPA from sp to sf, I read the WDPA with wdpar:

wdpa <- wdpa_read("~/WDPA_Feb2020-shapefile.zip") wdpa <- wdpa[-which(wdpa$MARINE == "2"),] wdpa <- wdpa[-which(wdpa$ISO3 == "ABNJ"),] wdpa_som <- wdpa[which(wdpa$ISO3 == "SOM"),] wdpa_som <- wdpa_clean(wdpa_som)

Bildschirmfoto 2020-02-19 um 10 30 41

(sorry it is in German, but the error remains the same)

JonasGeschke commented 4 years ago

update: I now tried to clean SOM with the development version of wdpar – it worked. so in case you dont want to follow up on the origin of the error, you may close the issue.

JonasGeschke commented 4 years ago

its your go to close it in case you are good to go ;-)

jeffreyhanson commented 4 years ago

Great - glad to hear it's working. I'll close this issue now then. In the future, if you feel that you've solved an issue that you've opened, please feel free to close it yourself :)

JonasGeschke commented 4 years ago

Strange... with a changed precision, the error comes up again. Would be great if you could have a look at it.

Error in st_cast_sfc_default(x) : list item(s) not of class sfg

JonasGeschke commented 4 years ago

So this class error still is the bottleneck in my progress...

jeffreyhanson commented 4 years ago

Per #22, could you please post a complete reproducible example showing the issue you're experiencing?

JonasGeschke commented 4 years ago

Hi – sorry for not replying yet. You can find the reproducible example above. However, it does not pop up always, I have no clue why. Did you change anything in the development version that could have lead to fixing the class error?

JonasGeschke commented 4 years ago

Congrats to your paper, very nice reading!

In regard of my work on the WPDA, using wdpar: I am in still in progress cleaning and unioning all countries individually and plan to union them together afterwards. During the computing, the class error came up again – using the development version of the package. Would be great if you find some time working on this error.

jeffreyhanson commented 4 years ago

Thanks! It looks like the issue with Somalia is that all the protected areas are points and they have a REP_AREA of zero - meaning that there are no "spatially valid non-empty" geometries for this country. I'll add in a patch to return an empty result (i.e. sf object with zero rows) for such cases.

jeffreyhanson commented 4 years ago

Ok - I've just pushed a new version to GitHub that works for Somalia. Thanks for the reminder!