
/I  used following R code sometime ago to merge  several  shpe files. 
You  can try this. /Just need  little  modify  the code. (shape file  
will like this:Name01.shpe,Name02.shape........)
Zia
//
/
# Require packages: rgdal and maptool
#-------------------------------------

library(rgdal)
library(maptools)

setwd("C:/test")

# Get list of all shape files from  directories
#--------------------------------------------------------

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

# 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)
}


# Add adtribute to the polygoan
#------------------------------

data.ny <- read.csv("data_table.csv", header=TRUE)
poly.data1 <- spCbind(poly.data, data.ny)
plot(poly.data1)

# Write and Export as a shape file
#----------------------------------

combinedShp1 <- "D:/test/combined1.shp"
writeOGR(poly.data1, dsn=combinedShp1, layer="combined1", driver="ESRI 
Shapefile")



# Read and Reproject

combined1_LL <- readOGR(".", "combined1")
proj4string(combined1_LL) <- CRS("+proj=longlat ellps=WGS84")

combined1.proj <- spTransform(combined1_LL, CRS("+init=epsg:4326"))
combined1.proj
combinedShpLL <- "D:/test/combinedmu.shp"
writeOGR(combined1.proj, dsn=combinedShpLL, layer="combinedmu", 
driver="ESRI Shapefile")


/On 1/12/2011 5:50 PM, Dan Putler wrote:
> All,
>
> Why not just use the ogr2ogr command line tool included with GDAL/OGR to
> combine the shapefiles, and then bring the combined shapefile into R?
> Look at the *Examples* section on the following link to see the syntax
> on how to do it: http://www.gdal.org/ogr/drv_shapefile.html
>
> Dan
>
>
> On 01/12/2011 01:09 PM, Pierre Roudier wrote:
>> Gianni,
>>
>> My understanding is that the rgeos package would ease that sort of
>> things (without any gpclib licensing problems). I'm not sure if it is
>> stable yet. It is available through r-forge (not sure it's a CRAN
>> yet).
>>
>> Otherwise, this sounds very much like a GIS operation: why don't you
>> do it in a GIS?
>>
>> My 2 cents,
>>
>> Pierre
>>
>> 2011/1/13 gianni lavaredo<gianni.lavaredo@gmail.com>:
>>> Dear Researchers,
>>>
>>> I have 3 shapefiles and I wish to find a way to union (or merge) to have
>>> only one shapefile. Do i need to use spatstat?
>>>
>>> thanks Gianni
>>>
>>>          [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo@r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


	[[alternative HTML version deleted]]

