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

Roger Bivand Roger.Bivand at nhh.no
Mon Jun 6 15:24:01 CEST 2016


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


More information about the R-help mailing list