Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Created January 29, 2016 01:06
Show Gist options
  • Save mdsumner/b9baaf74e57f33e209f0 to your computer and use it in GitHub Desktop.
Save mdsumner/b9baaf74e57f33e209f0 to your computer and use it in GitHub Desktop.
## wtf
#' Combine a list of PolygonDataFrame objects into a single object.
#'
#' Objects are combined by modifying sequential IDs to increase.
c_poly <- function(x) {
poly <- x[[1]]
if (length(x) == 1L) {
warning("input of length one, returning first element")
return(poly)
}
for (i in seq_along(x)[-1]) {
x0 <- spChFIDs(x[[i]], as.character(seq(nrow(x[[i]])) + max(as.integer(row.names(poly)))))
poly <- maptools::spRbind(poly, x0)
}
poly
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment