<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Thanks  a lot! I will try accordingly.<br>
Thanks again<br>
Zia<br>
<br>
Matt Beard wrote:
<blockquote
 cite="mid:9e6818f31001230235q402437as22b8c5b2a0a1cd47@mail.gmail.com"
 type="cite">Zia,
  <div><br>
  </div>
  <div>Does this work?</div>
  <div>Set your working directory and your output filename.</div>
  <div>
  <div><br>
  </div>
  <div>library(rgdal)</div>
  <div>library(maptools)</div>
  <div>setwd("C:/test")                                              #
CHANGE THIS</div>
  <div>combinedShp <- "C:/test/combined.shp"           # CHANGE THIS</div>
  <div><br>
  </div>
  <div># obtain shapefiles in current directory</div>
  <div>files <- list.files(pattern = "shp")</div>
  <div>uid <- 1</div>
  <div><br>
  </div>
  <div># get polygons from first file</div>
  <div>poly.data <- readOGR(files[1], gsub(".shp","",files[1]))</div>
  <div>n <- length(slot(poly.data, "polygons"))</div>
  <div>poly.data <- spChFIDs(poly.data, as.character(uid:(uid+n-1)))</div>
  <div>uid <- uid + n</div>
  <div><br>
  </div>
  <div># add polygons from remaining files</div>
  <div>for (i in 2:length(files)) {</div>
  <div>   temp.data <- readOGR(files[i], gsub(".shp","",files[i]))</div>
  <div>   n <- length(slot(temp.data, "polygons"))</div>
  <div>   temp.data <- spChFIDs(temp.data,
as.character(uid:(uid+n-1)))</div>
  <div>   uid <- uid + n</div>
  <div>   poly.data <- spRbind(poly.data,temp.data)</div>
  <div>}</div>
  <div><br>
  </div>
  <div>writeOGR(poly.data, dsn=combinedShp, layer="combined",
driver="ESRI Shapefile")</div>
  <div><br>
  </div>
  <div><br>
  </div>
  <div>Matt Beard</div>
  <div>Purdue University</div>
  <div><br>
  </div>
  <div><br>
  </div>
  <div><br>
  </div>
  <br>
  <div class="gmail_quote">On Fri, Jan 22, 2010 at 10:45 PM, Zia Ahmed <span
 dir="ltr"><<a moz-do-not-send="true" href="mailto:zua3@cornell.edu">zua3@cornell.edu</a>></span>
wrote:<br>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi
Matt:<br>
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!<br>
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?<br>
Thanks<br>
Zia<br>
    <br>
  </blockquote>
  </div>
  </div>
</blockquote>
</body>
</html>