[R-sig-Geo] Union sp polygons ID (rgoes and sp)
Omphalodes Verna
omphalodes.verna at yahoo.com
Sun Mar 17 09:07:29 CET 2013
Roger, thanks for your nicely explanation. This is due to ESRI ''contamination'', where Union is what I want.
OV
----- Original Message -----
From: Roger Bivand <Roger.Bivand at nhh.no>
To: Omphalodes Verna <omphalodes.verna at yahoo.com>
Cc: "r-sig-geo at r-project.org" <r-sig-geo at r-project.org>
Sent: Saturday, March 16, 2013 9:31 PM
Subject: Re: [R-sig-Geo] Union sp polygons ID (rgoes and sp)
On Sat, 16 Mar 2013, Omphalodes Verna wrote:
> Sorry for my confusion: I would like to get
> this: http://farm5.static.flickr.com/4102/4862739641_eacbbd8313.jpg
There are four operators: gUnion, gDifference, gSymdifference and
gIntersection. You seem to need combinations of these, so reading up on
the underlying concepts, for instance in the JTS documentation:
http://www.vividsolutions.com/jts/bin/JTS%20Technical%20Specs.pdf
Roger
>
> Input polygons are A, B and C, and I would like to get polygons:
> A
> B
> C
> AB!C
> A!BC
> !ABC
> ABC
>
> I hope, now it is clear.
>
> Thanks, OV
>
>
> ----- Original Message -----
> From: Roger Bivand <Roger.Bivand at nhh.no>
> To: Omphalodes Verna <omphalodes.verna at yahoo.com>
> Cc: "r-sig-geo at r-project.org" <r-sig-geo at r-project.org>
> Sent: Saturday, March 16, 2013 7:38 PM
> Subject: Re: [R-sig-Geo] Union sp polygons ID (rgoes and sp)
>
> On Sat, 16 Mar 2013, Omphalodes Verna wrote:
>
>> Thanks Roger!
>>
>> No, there is no mistaking. This is kind of dissolve function. But I need overlapping / intersection of polygons, where common polygons have unique ID
>
> Well, certainly your example is unclear. You are taking the unions byid=TRUE of 5 Polygons objects with the same objects, so if you start with
>
> set.seed(1)
>
> you get:
>
>> gArea(SPLpoly, byid=TRUE)
> 1 2 3 4 5
> 0.04823433 0.03769229 0.04274933 0.06575346 0.09910228
>
> and
>
>> gArea(gU, byid=TRUE)
> 1 1 1 2 1 3 1 4 1 5 2 1
> 0.04823433 0.06825532 0.09098365 0.11398779 0.14733661 0.06825532
> 2 2 2 3 2 4 2 5 3 1 3 2
> 0.03769229 0.08044161 0.10344575 0.13679457 0.09098365 0.08044161
> 3 3 3 4 3 5 4 1 4 2 4 3
> 0.04274933 0.10850279 0.14076253 0.11398779 0.10344575 0.10850279
> 4 4 4 5 5 1 5 2 5 3 5 4
> 0.06575346 0.14303501 0.14733661 0.13679457 0.14076253 0.14303501
> 5 5
> 0.09910228
>
> where 1 1, 2 2, etc. agree with the single Polygons values. If byid=TRUE, you get the union of the two Polygons objects, see:
>
> plot(gU[2])
>
> and
>
> gEquals(gU[2], gU[6])
>
> It isn't clear what you want.
>
> Roger
>
>>
>> Thanks
>>
>>
>>
>>
>> ----- Original Message -----
>> From: Roger Bivand <Roger.Bivand at nhh.no>
>> To: Omphalodes Verna <omphalodes.verna at yahoo.com>
>> Cc: "r-sig-geo at r-project.org" <r-sig-geo at r-project.org>
>> Sent: Saturday, March 16, 2013 4:34 PM
>> Subject: Re: [R-sig-Geo] Union sp polygons ID (rgoes and sp)
>>
>> On Sat, 16 Mar 2013, Omphalodes Verna wrote:
>>
>>> Dear list.
>>>
>>> I would like to do union of many polygons in R (rgeos) with ''gUnion'' function (in attached code only 5). Final result should be polygons with unique ID (using attached code it is), but when I plot them (colors by ID value), there are only 5 polygons. Please, give me some idea. Thanks to all, OV
>>
>> Are you mistaking gUnion() for gUnaryUnion()?
>>
>> gU = gUnaryUnion(SPLpoly, id=rep("1", length(SPLpoly)))
>>
>> Roger
>>
>>>
>>> RCode:
>>> library(rgeos)
>>> library(sp)
>>> n <- 5
>>> xy <- cbind(runif(n), runif(n), runif(n), runif(n))
>>> LLine <- vector("list", n)
>>> LLines <- vector("list", n)
>>> for(i in 1:n) LLine[[i]] <- Line(rbind(xy[i, 1:2], xy[i, 3:4]))
>>> for(i in 1:n) LLines[[i]] <- Lines(LLine[[i]], ID = i)
>>> SPLines <- SpatialLines(LLines)
>>> SPLpoly <- gBuffer(SPLines, width = 0.05, byid = TRUE)
>>> plot(SPLines, col = getSLLinesIDSlots(SPLines))
>>> plot(SPLpoly, add = TRUE, col = getSLLinesIDSlots(SPLines))
>>> SPLpolyA <- SPLpoly
>>> SPLpolyB <- SPLpoly
>>> gU = gUnion(SPLpolyA, SPLpolyB, byid = TRUE)
>>> plot(gU, col = rainbow(length(gU)))
>>>
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>> -- Roger Bivand
>> Department of Economics, NHH Norwegian School of Economics,
>> 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
> Department of Economics, NHH Norwegian School of Economics,
> 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
Department of Economics, NHH Norwegian School of Economics,
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