Skip to content

Instantly share code, notes, and snippets.

@dholstius
Last active Aug 29, 2015
Embed
What would you like to do?
Extract a layer from an (unzipped) shapefile
extract_layer <- function (
dsn,
layer,
datum,
quiet = FALSE,
...
) {
require(rgdal)
if (missing(layer)) {
layer <- ogrListLayers(dsn)
stopifnot(length(layer) == 1)
}
msg <- capture.output(spobj <- readOGR(dsn, layer, ...))
if (!quiet) {
message("Extracting layer ", layer, " from ", dsn)
message(str_c(msg, "\n"))
message(str(spobj@data))
}
if (!missing(datum)) {
spobj <- spTransform(spobj, datum)
}
return(spobj)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment