Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when converting USA states/counties #56

Closed
paleolimbot opened this issue Oct 22, 2021 · 6 comments · Fixed by #74
Closed

Crash when converting USA states/counties #56

paleolimbot opened this issue Oct 22, 2021 · 6 comments · Fixed by #74

Comments

@paleolimbot
Copy link
Owner

paleolimbot commented Oct 22, 2021

library(sf)
library(geos)

# USA states
# https://biogeo.ucdavis.edu/data/gadm3.6/Rsf/gadm36_USA_1_sf.rds

states <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsf/gadm36_USA_1_sf.rds"))
# fix old-style CRS object
attr(states$geometry, "crs") <- st_crs("OGC:CRS84")

# in various formats
states_sf_geod <- states$geometry
states_sf_cart <- st_set_crs(states_sf_geod, st_crs(NA))
states_s2 <- as_s2_geography(states_sf_geod)
states_geos <- as_geos_geometry(states_sf_cart)
@christopherkenny
Copy link

If another data point is helpful, I am finding a similar issue where R crashes completely on running the following:

al <- tigris::voting_districts('AL')
algeos <- geos::as_geos_geometry(al)

(Can't submit a reprex because R crashes.)

@paleolimbot
Copy link
Owner Author

Thanks for adding this! Until I fix this, the workaround is to go through st_as_binary() and geos_read_wkb() like this:

al <- tigris::voting_districts('AL')
algeos <- geos::geos_read_wkb(sf::st_as_binary(tigris::voting_districts('AL')$geometry))
head(algeos)
#> <geos_geometry[6]>
#> [1] <MULTIPOLYGON [-86.909 31.870...-86.840 31.962]>
#> [2] <MULTIPOLYGON [-87.927 32.038...-87.745 32.191]>
#> [3] <MULTIPOLYGON [-88.052 32.030...-87.890 32.174]>
#> [4] <MULTIPOLYGON [-88.020 32.139...-87.854 32.308]>
#> [5] <MULTIPOLYGON [-87.877 32.343...-87.827 32.460]>
#> [6] <MULTIPOLYGON [-88.118 31.990...-87.950 32.129]>

Created on 2021-10-24 by the reprex package (v2.0.1)

@christopherkenny
Copy link

Thanks for the workaround! The package looks great. Planning on using this and your libgeos. After some testing, it seems like everything is extremely fast.

@paleolimbot
Copy link
Owner Author

Good to know! There's a few things that are slower (geos_intersects_matrix() is the one I know about)...let me know if you find anything else or find any problems!

@paleolimbot
Copy link
Owner Author

This crash stopped happening on my computer, so I'm going to fall back to using geos_read_wkb() for the next release and re-evaluate this later. This will slow down sf -> geos by about 4x (you can do wk::wk_handle(sf_object, geos_geometry_writer()) if you want the fast version that possibly crashes)

@christopherkenny
Copy link

Also working for me using the most recent version on GitHub. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants