Thanks a lot! I will try accordingly. Thanks again Zia
Matt Beard wrote:
Zia, Does this work? Set your working directory and your output filename. library(rgdal) library(maptools)setwd("C:/test") # CHANGE THIScombinedShp <- "C:/test/combined.shp" # CHANGE THIS # obtain shapefiles in current directory files <- list.files(pattern = "shp") uid <- 1 # get polygons from first file poly.data <- readOGR(files[1], gsub(".shp","",files[1])) n <- length(slot(poly.data, "polygons")) poly.data <- spChFIDs(poly.data, as.character(uid:(uid+n-1))) uid <- uid + n # add polygons from remaining files for (i in 2:length(files)) { temp.data <- readOGR(files[i], gsub(".shp","",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) }writeOGR(poly.data, dsn=combinedShp, layer="combined", driver="ESRI Shapefile")Matt Beard Purdue UniversityOn Fri, Jan 22, 2010 at 10:45 PM, Zia Ahmed <z...@cornell.edu <mailto:z...@cornell.edu>> wrote:Hi Matt: With help of Jim Holtman (my R Guru!), I am able to modified your code for selecting particular type of shape files from different folders and able to combine them together. Thank you so much! However, final polygon does not contain any filed (suppose county name, FIPS code etc) of the shape files those I used for merging . How do I keep these fields in my final polygon. Any idea? Thanks Zia
<<attachment: zua3.vcf>>
_______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo