[R-sig-Geo] combining polygons from shapefiles...

Sean O'Riordain seanpor at acm.org
Wed Dec 2 16:18:44 CET 2009


Thanks Roger,

> head(row.names(LA))
[1] "0" "1" "2" "3" "4" "5"
> head(row.names(CA))
[1] "0" "1" "2" "3" "4" "5"
>

I'll have a look at these and get back with my results.

Kind regards,
Sean


On Wed, Dec 2, 2009 at 3:07 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> On Wed, 2 Dec 2009, Sean O'Riordain wrote:
>
>> Good afternoon,
>>
>> I've been making good progress in the last few weeks thanks to this
>> list, along with Roger and Adrians' books and some great geo-packages.
>>
>> I'm trying to combine some shapefiles...
>>
>> library(maptools)
>> CA <- readShapePoly('ca.shp')
>> LA <- readShapePoly('la.shp')
>>
>> Now I want to combine these two into a bigger object...
>>
>> I've searched the books and the internet and I've tried a number of
>> things... including...
>>
>>> class(LA)
>>
>> [1] "SpatialPolygonsDataFrame"
>> attr(,"package")
>> [1] "sp"
>>>
>>> class(CA)
>>
>> [1] "SpatialPolygonsDataFrame"
>> attr(,"package")
>> [1] "sp"
>>>
>>>    S1 <- unionSpatialPolygons(CA, LA)
>>
>> Loading required package: gpclib
>> General Polygon Clipper Library for R (version 1.4-4)
>>       Type 'class ? gpc.poly' for help
>>
>> Error in unionSpatialPolygons(CA, LA) : input lengths differ
>>>
>>>
>>> S1 <- spRbind(CA, LA)
>>
>> Error in spRbind(as(obj, "SpatialPolygons"), as(x, "SpatialPolygons")) :
>>  non-unique polygon IDs
>>>
>
> Correct. Look at row.names(CA) and row.names(LA). Do something of your
> choice to disambiguate them and re-assign with spChFIDs() - since you refer
> to the ASDAR book, there is an example in chapter 5, sections 5.4 & 5.5, pp.
> 120-126. You'll also see that your reading of how to use
> unionSpatialPolygons() did not agree with that in the function, which is to
> dissolve Polygons objects within an existing SpatialPolygons object.
>
> Hope this helps,
>
> Roger
>
>>
>> Any ideas please?
>>
>> Thanks in advance!
>> Sean
>>
>> _______________________________________________
>> 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