<!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">
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.<br>
Zia<br>
<br>
###############################################################################<br>
<br>
# <font face="Courier New, Courier, monospace"><small>Require
packages: rgdal and maptool<br>
#-------------------------------------<br>
<br>
library(rgdal)<br>
library(maptools)<br>
<br>
# Get list of all shape files from county directories/sptial/<br>
#------------------------------------------------------------<br>
<br>
files <- list.files(pattern="soilmu_a_ia.*.shp$",
recursive=TRUE,full.names=TRUE)<br>
uid<-1<br>
<br>
# Get polygons from first file (_001)<br>
#-------------------------------------<br>
<br>
poly.data<- readOGR(files[1],gsub("^.*/(.*).shp$", "\\1",
files[1])) <br>
n <- length(slot(poly.data, "polygons"))<br>
poly.data <- spChFIDs(poly.data, as.character(uid:(uid+n-1)))<br>
uid <- uid + n<br>
<br>
# mapunit polygoan: combin remaining polygons with first
polygoan<br>
#-----------------------------------------------------------------<br>
<br>
for (i in 2:length(files)) {<br>
temp.data <- readOGR(files[i], gsub("^.*/(.*).shp$",
"\\1",files[i]))<br>
n <- length(slot(temp.data, "polygons"))<br>
temp.data <- spChFIDs(temp.data,
as.character(uid:(uid+n-1))) <br>
uid <- uid + n<br>
poly.data <- spRbind(poly.data,temp.data)<br>
}<br>
<br>
names(poly.data)<br>
proj4string(poly.data)</small></font><br>
<br>
On 5/25/2011 3:22 AM, Pierre Roudier wrote:
<blockquote
cite="mid:BANLkTi=vBJehathXJd=L7X84NX-PRNGObQ@mail.gmail.com"
type="cite">
<pre wrap="">Hi Nicolas,
I do not have a R session handy, but if I remember correctly, the
function gUnion() in the rgeos package would do what you want.
Hope this helps,
Pierre
2011/5/25 Nicolas Degallier <a class="moz-txt-link-rfc2396E" href="mailto:nicolas.degallier@ird.fr"><nicolas.degallier@ird.fr></a>:
</pre>
<blockquote type="cite">
<pre wrap="">Hi All,
I have read different shapefiles that are contiguous and that have different column names with the function "readShapePoly".
example :
noumea <- readShapePoly(noumea.file, IDvar = "NOUMEA2_ID", proj4string = crs_rgnc)
and
dumbea <- readShapePoly(dumbea.file, IDvar = "DUMBEA2_", proj4string = crs_rgnc)
Now I would like to create a new shapefile with all the polygones in the "noumea" and "dumbea" spatial polygone data frames.
I tried :
spRbind(noumea, dumbea)
I get this message error :
Error in spRbind(as(obj, "SpatialPolygons"), as(x, "SpatialPolygons")) :
non-unique polygon IDs
I have tried with the function rbind()
I have tried to set noumea$NOUMEA2_ID and dumbea$DUMBEA2_ with unique values but I still get the same message error as if the function spRbind was not using those two columns as polygons ID...
Does anyone know how I can fix this problem ?
Thanks a lot
Nicolas
Nicolas Degallier
IRD UMR182
Laboratoire d'Océanographie et du Climat, Expérimentation et Approches Numériques (LOCEAN)
Tour 45-55, 4e ét., case 100, 4 place Jussieu
75252 Paris Cedex 5 France
tél: (33) 01 44 27 51 57
fax: (33) 01 44 27 38 05
E-mail: <a class="moz-txt-link-rfc2396E" href="mailto:Nicolas.Degallier@ird.fr"><Nicolas.Degallier@ird.fr></a>
pdf reprints:
<a class="moz-txt-link-freetext" href="http://www.locean-ipsl.upmc.fr/~ndelod/production/">http://www.locean-ipsl.upmc.fr/~ndelod/production/</a>
Skype:"xuxaxu"
_______________________________________________
R-sig-Geo mailing list
<a class="moz-txt-link-abbreviated" href="mailto:R-sig-Geo@r-project.org">R-sig-Geo@r-project.org</a>
<a class="moz-txt-link-freetext" href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo">https://stat.ethz.ch/mailman/listinfo/r-sig-geo</a>
</pre>
</blockquote>
<pre wrap="">
</pre>
</blockquote>
</body>
</html>