Created
April 4, 2024 16:48
-
-
Save dankkom/ff4c531d39d35cd029679625abb451f2 to your computer and use it in GitHub Desktop.
read_shp(): R function to read zipped shapefiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
read_shp <- function(filepath) { | |
# If zipped | |
if (stringr::str_ends(filepath, ".zip")) { | |
temp1 <- tempfile() | |
unzip(zipfile = filepath, exdir = temp1) | |
d <- sf::read_sf(temp1) | |
unlink(temp1, recursive = TRUE) | |
return(d) | |
} | |
# If not zipped | |
sf::read_sf(filepath) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment