ropensci / rnaturalearth

An R package to hold and facilitate interaction with natural earth map data :earth_africa:
http://ropensci.github.io/rnaturalearth/
Other
214 stars 24 forks source link

Invalid geometry world: Loop 0 is not valid #99

Closed JJFoest closed 7 months ago

JJFoest commented 7 months ago

Dear rnaturalearth developers,

Firstly, thank you for making an awesome package (I'm using v. 0.3.4). I've been running into some problems with invalid geometry.

If I run:

worldshape <- rnaturalearth::ne_countries(returnclass = "sf") %>% sf::st_union()

I receive the error message: "Error in wk_handle.wk_wkb(wkb, s2_geography_writer(oriented = oriented, : Loop 0 is not valid: Edge 0 crosses edge 78".

Now, if I try to force the geometry to be valid:

worldshape <- rnaturalearth::ne_countries(returnclass = "sf") %>% sf::st_make_valid() %>%
sf::st_union()

I receive the same error message.

If it helps, I am running v. 1.0-13 of sf in R 4.3.1.

Thank you for your consideration.

Nowosad commented 7 months ago

@JJFoest see https://github.com/r-spatial/sf/issues/1649#issuecomment-860274770

PMassicotte commented 7 months ago

If you turn s2 off, does it help?

JJFoest commented 7 months ago

Hi! Thanks for the suggestions.

This runs ok:

sf_use_s2(FALSE) worldshape <- rnaturalearth::ne_countries(returnclass = "sf") %>% sf::st_union() worldshape

I only get a message: "although coordinates are longitude/latitude, st_union assumes that they are planar".

Thank you!