Using examples in Chapter 5, I am trying to get rid of non-unique polygons. I'm working with a Massachusetts shapefile by zips. The file consists the following fields ZCTA NAME LSAD LSAD_TRANS
I've done the following to get rid of duplicate records > zipmaps1_df <- as(zipmaps1, "data.frame") [!duplicated(zipmaps1$LSAT_TRANS)] > row.names(zipmaps1_df) <- zipmaps1_df$LSAD_TRANS > zipmaps1a <- SpatialPolygonsDataFrame(zipmaps1, zipmaps1_df) , but get the following error message Error in SpatialPolygonsDataFrame(zipmaps1, zipmaps1_df) : row.names of data and Polygons IDs do not match How do I find out what field R is treating as Polygon ID, so that I can set my row.names to that? On Wed, Apr 29, 2009 at 2:42 AM, Roger Bivand <roger.biv...@nhh.no> wrote: > 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 > > [[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