Over a million developers have joined DZone.

A Function for Batch Downloading Zipped Shapefiles with R

DZone's Guide to

A Function for Batch Downloading Zipped Shapefiles with R

· Big Data Zone
Free Resource

Learn best practices according to DataOps. Download the free O'Reilly eBook on building a modern Big Data platform.

Here's a function I use to download multiple zipped shapefiles from URLs and load them to the workspace:

URLs <- c("http://gis.tirol.gv.at/ogd/umwelt/wasser/wis_gew_pl.zip",
url_shp_to_spdf <- function(URL) {
  wd <- getwd()
  td <- tempdir()
  temp <- tempfile(fileext = ".zip")
  download.file(URL, temp)
  shp <- dir(tempdir(), "*.shp$")
  lyr <- sub(".shp$", "", shp)
  y <- lapply(X = lyr, FUN = function(x) readOGR(dsn=shp, layer=lyr))
  names(y) <- lyr
y <- lapply(URLs, url_shp_to_spdf)
z <- unlist(unlist(y))
# finally use it:

Find the perfect platform for a scalable self-service model to manage Big Data workloads in the Cloud. Download the free O'Reilly eBook to learn more.


Published at DZone with permission of Kay Cichini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}