Skip to content

Instantly share code, notes, and snippets.

@kadyb
Last active March 24, 2024 04:56
Show Gist options
  • Save kadyb/69b55caca364ea7f6a8167079d78772f to your computer and use it in GitHub Desktop.
Save kadyb/69b55caca364ea7f6a8167079d78772f to your computer and use it in GitHub Desktop.
Directly load and save zipped shapefiles in {sf}
library("sf")
file = system.file("shape/nc.shp", package = "sf")
shp = read_sf(file)
## write zipped shapefile
write_sf(shp, "myshapefile.shp.zip", driver = "ESRI Shapefile")
## read zipped shapefile
read_sf("myshapefile.shp.zip")
## read zipped shapefile using `vsizip`
## see: https://gdal.org/user/virtual_file_systems.html
f = paste0("/vsizip/", "myshapefile.shp.zip")
read_sf(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment