Skip to content

Instantly share code, notes, and snippets.

@dillonma
Created November 17, 2012 23:18
Show Gist options
  • Save dillonma/4101307 to your computer and use it in GitHub Desktop.
Save dillonma/4101307 to your computer and use it in GitHub Desktop.
Use R to read the geometry and attribute data with the rgdal package
#(so you could modify the relationships as well and create a completely new shapefile)
library(rgdal)
## read "/path/to/files/filename.shp"
shp <- readOGR("/path/to/files/", "filename")
## add new attribute data (just the numbers 1 to the number of objects)
shp$new.att <- 1:nrow(shp)
## write out to a new shapefile
writeOGR(shp, "/path/to/files/", "filename2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment