[R-sig-Geo] dissolve tiny polygons to others with unionSpatialPolygons{maptools}

Roger Bivand Roger.Bivand at nhh.no
Mon Jun 6 21:19:25 CEST 2016


On Mon, 6 Jun 2016, Kumar Mainali wrote:

> Thank you, Roger. I cannot fix the upstream processes to eliminate
> generation of these problems. So, I need to deal with the data I got.
> I tried various online resources including
> https://gist.github.com/mstrimas/1b4a4b93a9d4a158bce4 and tried:
> setScales()
> set_RGEOS_dropSlivers(TRUE)
> set_RGEOS_polyThreshold()
>
> before performing:
> gUnaryUnion(p.ranges, id=NULL)
>
> This eliminates the slivers but it also dissolves ALL the polygons to get a
> single polygon. That is not something I wanted. I would like to dissolve
> only the tiny polygons to the neighboring bigger ones.
>
> Any help is very much appreciated!

Then you must decide which larger polygon (Multipolygon, Polygons object) 
they are to belong to. They are Polygon objects within Polygons objects, 
and are not entities you can "get at" easily. In your case, all the 
entities are Polygons objects, and perhaps by buffering the first Polygons 
object northwards, you could include all of the entities. They are far 
from trivial in size, and it is not without consequences for downstream 
analysis that you are shifting a boundary by tens of km. Really the 
upstream data source should provide clean data.

Fixing this would be arbitrary and messy, with consequences for downstream 
analysis. In addition, there are empty slivers too. I really advise you to 
get back to the data providers, and I wouldn't trust Eliminate either - 
it's just making a tidy picture, but one that isn't what the data 
processing is saying. I could do it technically, but I wouldn't share that 
script with anyone, because it isn't the way to go.

Roger

>
>>
> Postdoctoral Associate
> Department of Biology
> University of Maryland, College Park
>
> On Mon, Jun 6, 2016 at 9:24 AM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
>
>> On Mon, 6 Jun 2016, Kumar Mainali wrote:
>>
>> I am trying to use unionSpatialPolygons() of maptools to eliminate sliver
>>> in species range. I want to dissolve tiny sliver polygons in a shapefile
>>> to
>>> bigger polygons as "Eliminate (Data Management)" of ArcMap does. Whereas I
>>> can dissolve polygons that have identical features in the argument "IDs",
>>> I
>>> cannot dissolve tiny polygons based on some threshold in area. In fact,
>>> the
>>> argument "threshold" has no effect in the output.
>>>
>>
>> Indeed, threshold is not passed through, it was used when the function
>> used gpclib rather than rgeos; I'm minded to deprecate
>> maptools::unionSpatialPolygons anyway. Note that the data are in
>> geographical coordinates, which may very well not be appropriate for the
>> topological operations you are trying to do. Use rgeos::gUnaryUnion
>> instead, and refer to this thread:
>>
>> https://stat.ethz.ch/pipermail/r-sig-geo/2015-November/023667.html
>>
>> for using rgeos::set_RGEOS_polyThreshold() and friends. They do not,
>> however, try to guess which of the polygons neighbouring the sliver should
>> get the extra area, so you'll have to think that through yourself.
>>
>> Googling for lists:R-sig-geo dissolve slivers gets a fair number of hits.
>>
>> There is always also the upstream question of where the slivers came from,
>> and whether the resolution is not in the earlier process - generate a map
>> without slivers that says exactly what you mean, rather than fudging it
>> afterwards.
>>
>> Roger
>>
>>
>>> ​Input data is available here: ​
>>> https://www.dropbox.com/sh/a0x5bbo9u60y7is/AAB6RjXHFQKZv-i-t4JclF3ba?dl=0
>>>
>>> p.ranges <- shapefile{raster}
>>> (IDs <- p.ranges$style_id)
>>> library(maptools)
>>> unionSpatialPolygons(p.ranges, IDs = IDs, threshold = 1.5)
>>>
>>> ​-- Kumar Mainali
>>> Postdoctoral Associate
>>> Department of Biology
>>> University of Maryland, College Park
>>>
>>>
>>>>>>
>>>
>> --
>> 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
>> http://orcid.org/0000-0003-2392-6140
>> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>> http://depsy.org/person/434412
>

-- 
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
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
http://depsy.org/person/434412


More information about the R-sig-Geo mailing list