[R-sig-Geo] Singlepart to multipart

Roger Bivand Roger.Bivand at nhh.no
Tue Apr 1 19:53:34 CEST 2014


On Tue, 1 Apr 2014, Jonathan Greenberg wrote:

> This is a counter-question to the previous one: how would I go about
> taking a multipart SpatialPolygon* and "flattening" it so each
> individual polygon is its own component, "repeating" the data frame
> (if a SpatialPolygonsDataFrame) for the new polygons, effectively
> "undoing" the previous suggestion?

Crucially, and typically for me, what do you mean by "polygon"? Do you 
mean SFS POLYGON (one exterior ring and zero or more interior rings aka 
holes), or Polygon as defined in sp, which is a linear ring either hole or 
non-hole? I suspect the former, but the answers would differ.

The IDs on the Polygons objects (features) are tied to rows in the data 
frame, so you are breaking up each Polygons object either to the lowest 
level of each component linear ring irrespective of its hole status, or, 
more likely, to that of each constituent SFS POLYGON. Something like this 
happens as Polygons objects enter GEOS, but there such a Polygons object 
may go to MULTIPOLYGON (multiple exterior rings) or POLYGON (single 
exterior ring) as encoded in the comment attribute of Polygons objects 
(yes, a nasty kludge, knowing about SFS postdated the definition of 
polygon vector objects in sp). Some mechainsm for assigning ID values 
would also be needed.

Roger

>
> --j
>
> On Tue, Oct 29, 2013 at 2:32 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
>> On Tue, 29 Oct 2013, Jonathan Greenberg wrote:
>>
>>> R-sig-geo'ers:
>>>
>>> If I have a SpatialPolygonsDataFrame with a field "MYID", how do I go
>>> about
>>> coercing that object to a multipart polygon, where I am "merging" on the
>>> MYID field?
>>
>>
>> maptools::unionSpatialPolygons() which calls rgeos::gUnaryUnion, so go to
>> rgeos::gUnaryUnion first unless you have challenged geometries - if hole
>> problems use maptools::checkPolygonsHoles first.
>>
>> Hope this helps,
>>
>> Roger
>>
>>>
>>> --j
>>>
>>>
>>
>> --
>> 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, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list