Skip to content
Prev 11802 / 29559 Next

merging several shapefiles into one

I used following code to merge a series of  shape files with similar 
file structure. We can try this, but you need to do some modification of 
the code.
Zia

###############################################################################

# Require packages: rgdal and maptool
#-------------------------------------

library(rgdal)
library(maptools)

# Get list of all shape files from county directories/sptial/
#------------------------------------------------------------

files <- list.files(pattern="soilmu_a_ia.*.shp$", 
recursive=TRUE,full.names=TRUE)
uid<-1

# Get polygons from first file (_001)
#-------------------------------------

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

# mapunit polygoan: combin remaining  polygons with first polygoan
#-----------------------------------------------------------------

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)))
     uid <- uid + n
     poly.data <- spRbind(poly.data,temp.data)
}

names(poly.data)
proj4string(poly.data)
On 5/25/2011 3:22 AM, Pierre Roudier wrote:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20110525/df96063a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: zua3.vcf
Type: text/x-vcard
Size: 281 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20110525/df96063a/attachment.vcf>