Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am dillonma on github.
* I am dillonm (https://keybase.io/dillonm) on keybase.
* I have a public key whose fingerprint is 174E 4F3D D478 FAC2 3B61 47CF 7BB9 D96E 021E 0DC0
To claim this, I am signing this object:
@dillonma
dillonma / r_shp.R
Created November 17, 2012 23:18
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
@dillonma
dillonma / r_dbf.R
Created November 17, 2012 23:18
Use R with the foreign package to modify the DBF file
library(foreign)
dbfdata <- read.dbf("file.dbf", as.is = TRUE)
## add new attribute data (just the numbers 1 to the number of objects)
dbfdata$new.att <- 1:nrow(shp)
## overwrite the file with this new copy
write.dbf(dbfdata, "file.dbf")