[R-sig-Geo] SpatialPolygonsDataFrame converted to SpatialPolygons after union

Oscar Breugelmans Oscar.Breugelmans at rivm.nl
Fri May 9 16:02:39 CEST 2008


Dear list,

I have a postal code map of the Netherlands. I use the area code PC4NR as
the identifier for each area. After making a subset of the areas, I use
unionSpatialPolygons to combine the polygons (areas) that have a different
ID, but the same PC4NR. When using unionSpatialPolygons, my
SpatialPolygonsDataFrame is converted into a SpatialPolygons object,
thereby losing all the auxilliary information contained in the dataframe. I
want to return to shapefile format after this, but writePolyShape doesn't
work anymore after the union.
Is there any way to perform the union while retaining the
SpatialPolygonsDataFrame class? The R code is below.
Any help is appreciated.

Oscar Breugelmans


pc4.00=readShapePoly("I:/smarhagt/geocor/burenmatrix/pc4_2000/pc4_gebieden_2000")

pc4.00.subset<-pc4.00[!pc4.00$PC4NR %in%
c(1117,1118,1322,1327,1341,1361,2268,2633,2909,3165,

3196,3199,3894,3895,5656,6192,6236,7125,7324,7915,7935,8239,8292,8939,9408,9941),]

pc4.00.union<-unionSpatialPolygons(as(pc4.00.subset, "SpatialPolygons"),
      as.character(pc4.00.subset$PC4NR))

writePolyShape(pc4.00.union,"c:/data/pc4final")
____________________________________________________________________________

DISCLAIMER:  http://www.rivm.nl/disclaimer.htm\ ...{{dropped:2}}




More information about the R-sig-Geo mailing list