Skip to content

Instantly share code, notes, and snippets.

@arcaravaggi
Created April 18, 2018 12:21
Show Gist options
  • Save arcaravaggi/cc7a0995279d2a05780b733bed74554c to your computer and use it in GitHub Desktop.
Save arcaravaggi/cc7a0995279d2a05780b733bed74554c to your computer and use it in GitHub Desktop.
Extract coordinates from SpatialPolygon object
# By Stack user forlooper
# https://stackoverflow.com/a/37332382
#
# e.g.
# p <- extractCoords(SST_start)
extractCoords <- function(sp.df)
{
results <- list()
for(i in 1:length(sp.df@polygons[[1]]@Polygons))
{
results[[i]] <- sp.df@polygons[[1]]@Polygons[[i]]@coords
}
results <- data.frame(Reduce(rbind, results))
results
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment