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

Roger Bivand Roger.Bivand at nhh.no
Fri May 9 17:31:35 CEST 2008


On Fri, 9 May 2008, Oscar Breugelmans wrote:

> 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.

No, it will not work, because it is not clear which rows should be 
retained - you have to do this yourself. Think about whether you want to 
aggregate using sum(), or mean(), or in other ways. Once you have 
aggregated the data frame part of the SpatialPolygonsDataFrame, and 
inserted row names to match the union criterion vector, you can build a 
new SpatialPolygonsDataFrame, and export it in the usual way.

Roger

> 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}}
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at 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.Bivand at nhh.no




More information about the R-sig-Geo mailing list