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

Sean O'Riordain seanpor at acm.org
Wed Dec 2 19:11:00 CET 2009


Thanks Roger,

The process was holding its' own in terms of process size - it seemed
to be about the same size for ages.

cheers,
Sean

On Wed, Dec 2, 2009 at 5:35 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> On Wed, 2 Dec 2009, Sean O'Riordain wrote:
>
>> Hello again,
>>
>> I've tried
>>   new.refs.for.CA <-
>> as.character(seq(from=max(as.numeric(row.names(LA)))+1,length=nrow(CA)))
>> # which takes about 0.15 secs...
>>   ca1 <- spChFIDs(CA, new.refs.for.CA)
>> # has been running now for more than 48 minutes (or at least 48 mins
>> CPU on this winbox)  is this right?
>> # It was running for about 15minutes and then I tried restarting it in
>> a cleaner
>> # environment... but it's still taking *ages*
>> #
>> # it was my intention then of saying
>>   S1 <- spRbind(LA, ca1)
>>
>> but both LA and CA have about 12,000 rows... and it's been running now
>> for quite a few minutes and I'm surprised it hasn't finished... is
>> this "normal" ?
>
> It is only coded as a for loop in R, and shapefiles used in typical
> applications in R have at most hundreds of entities, although this size is
> encountered without substantial trouble. Timings may vary depending on
> object sizes too, if copying is involved internally.
>
> This goes on the TODO list for coding in C.
>
> Roger
>
>>
>> Thanks,
>> Sean
>>
>>
>> On Wed, Dec 2, 2009 at 3:18 PM, Sean O'Riordain <seanpor at acm.org> wrote:
>>>
>>> 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
>>>>
>>>>
>>>
>>
>
> --
> 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