Seguí el enlace publicado por Roman Luštrik, y la siguiente respuesta es una ligera modificación de http://r-sig-geo.2731867.n2.nabble.com/suggestion-to-MERGE-or-UNION-3-shapefiles-td5914413.html#a5916751.
El siguiente código le permitirá fusionar los archivos .shp
obtenidos de Census 2000 5-Digit ZIP Code Tabulation Areas (ZCTAs) Cartographic Boundary Files y trazarlos.
En este caso, descargué los archivos .shp
y los archivos .dbf
y .shx
asociados para Massachusetts, New Hampshire y Maine.
library('maptools')
library('rgdal')
setwd('c:/location.of.shp.files')
# this location has the shapefiles for zt23_d00 (Maine), zt25_d00 (Mass.), and zt33_d00 (New Hampshire).
# columns.to.keep
# allows the subsequent spRbind to work properly
columns.to.keep <- c('AREA', 'PERIMETER', 'ZCTA', 'NAME', 'LSAD', 'LSAD_TRANS')
files <- list.files(pattern="*.shp$", recursive=TRUE, full.names=TRUE)
uid <-1
# get polygons from first file
poly.data<- readOGR(files[1], gsub("^.*/(.*).shp$", "\\1", files[1]))
n <- length(slot(poly.data, "polygons"))
poly.data <- spChFIDs(poly.data, as.character(uid:(uid+n-1)))
uid <- uid + n
poly.data <- poly.data[columns.to.keep]
# combine remaining polygons with first polygon
for (i in 2:length(files)) {
temp.data <- readOGR(files[i], gsub("^.*/(.*).shp$", "\\1",files[i]))
n <- length(slot(temp.data, "polygons"))
temp.data <- spChFIDs(temp.data, as.character(uid:(uid+n-1)))
temp.data <- temp.data[columns.to.keep]
uid <- uid + n
poly.data <- spRbind(poly.data,temp.data)
}
plot(poly.data)
# save new shapefile
combined.shp <- 'combined.shp'
writeOGR(poly.data, dsn=combined.shp, layer='combined1', driver='ESRI Shapefile')
Este este enlace (http://r-sig-geo.2731867.n2.nabble.com/suggestion-to-MERGE-or-UNION-3-shapefiles-td5914413.html#a5916751) en la fusión. El archivo de nabble debería ser una mina de oro para manejar datos espaciales. –
Mmm ... no sabía que R-sig-geo había llegado a Nabble. Desafortunadamente no está agrupado con los otros foros de R. – Sharpie
Me tomó casi cinco años de GIS realizar esto pero ... es "choropleth" no "chloropleth" –