On Tue, 28 Apr 2009, Alina Sheyman wrote:
I'm trying to combine two shapefiles using
zipmaps5 <- spRbind(zipmaps1,zipmaps2)
and getting the following error message
Error in spRbind(as(obj, "SpatialPolygons"), as(x, "SpatialPolygons")) :
non-unique polygon IDs
Does anyone know how I can get rid of duplicate polygons in a shapefile?
This isn't the problem. The real problem is that zipmaps1 and zipmaps2
have non-unique polygon IDs, so that it isn't obvious to the function what
you want to do. By default:
sapply(slot(zipmaps1, "polygons"), slot, "ID")
is set to the FID of the shapefile in readOGR() and equivalently in
readShapeSpatial() in maptools. These typically run 0:(n-1). For two
objects, they obviously overlap. Please use spChFIDs() methods in maptools
to assign IDs that are unique for the output object; in the worst case:
zipmaps1 <- spChFIDs(zipmaps1, paste("map1", sapply(slot(zipmaps1,
"polygons"), slot, "ID"), sep="_"))
and a different "map*" string for zipmaps2 will work, but a unique,
meaningful ID is best.
This is covered in detail in the code examples for Chapter 5 in our book,
and on the help page for ?"spChFIDs-methods".
Hope this helps,
Roger
thank you!
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: roger.biv...@nhh.no
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo