[R-sig-Geo] Cleaning small spatial polygons
Roger Bivand
Roger.Bivand at nhh.no
Thu Nov 5 12:05:04 CET 2015
On Wed, 4 Nov 2015, Roger Bivand wrote:
> On Wed, 4 Nov 2015, Eduardo Diez wrote:
>
>> Is there any way of doing this or should i forget it and go on using GRASS
>> through rgrass7?
>
> I suggest working with Emmanuel Blondel (cleangeo maintainer) to extend
> cleangeo (also suggested in an earlier thread today, with apologies to
> Emmanuel for picking on him!). That package already uses rgeos, and is a
> logical place to put GRASS v.clean-like functionality (maybe even
> encapsulating using GRASs via rgrass7 and a throwaway location).
>
> At the moment it is messy, though some rgeos internals do do something like
> this, but it isn't exposed to users.
A possibility is to use:
set_RGEOS_polyThreshold(1e-2) # for example
set_RGEOS_warnSlivers(TRUE)
shows the remaining slivers, and:
set_RGEOS_dropSlivers(TRUE)
drops them when using for example:
> t1 <- gBuffer(<your_object>, byid=TRUE, width=0)
A buffer of zero width should not have side-effects, but your mileage may
vary. It will only remove slivers, not dangles. I haven't tried it when it
also finds a Polygons object under the threshold, which was your initial
problem.
Roger
>
> Roger
>
>>
>> Thanks
>>
>> 2015-10-19 15:03 GMT-03:00 Eduardo Diez <eduardodiez at gmx.com>:
>>
>> > Ok. So here's a link to a zip file that contains two shapefiles:
>> > - pol_to_be_cleaned: the layer from which i'd like to remove small
>> > polygons
>> > - pol_cleaned: the layer cleaned with the function v.clean rmarea
>> >
>> > http://1drv.ms/1GmRWS7
>> >
>> > The threshold i used for cleaning was 3000 (meaning 3000 squared
>> > meters).
>> >
>> > Although i do project it before sending it to GRASS, according to the
>> > official help page it should be able to handle it:
>> > "Threshold must always be in square meters, also for latitude-longitude
>> > locations or locations with units other than meters"
>> >
>> > Thanks
>> >
>> > 2015-10-19 8:28 GMT-03:00 Roger Bivand <Roger.Bivand at nhh.no>:
>> >
>> > > On Fri, 16 Oct 2015, Eduardo Diez wrote:
>> > >
>> > > Dear list,
>> > > > I'm willing to know if any knows a way of performing tha same thing
>> > > > i'm
>> > > > doing through rgrass7 with GRASS when I execute the function v.clean
>> > > > with
>> > > > "rmarea" as the tool argument. That is:
>> > > >
>> > > > "The rmarea tool removes all areas <= thresh. The longest boundary
>> > > > with
>> > > > an
>> > > > adjacent area is removed or all boundaries if there is no adjacent
>> > > > area.
>> > > > Area categories are not combined when a small area is merged with a
>> > > > larger
>> > > > area."
>> > > >
>> > > > Basically i have raster of zones within a field. I convert it to
>> > > > SpatialPolygonsDataFrame and in order to leave only the more
>> > > > important/meaningful ones i remove the small/sliver with this tool.
>> > > > In
>> > > > general it works fine but having to call an external software with a
>> > > > specific version makes the script less portable and you have to be
>> > > > careful
>> > > > with updates and such. Also you have to write rasters and shapefiles
>> > > > back
>> > > > and forth as GRASS can't work with in-memory objects.
>> > > >
>> > >
>> > > Could you please provide an example of a built-in or contributed data
>> > > set
>> > > (URL, not attachment) with the slivers you mention, so that we know
>> > > that we
>> > > are addressing your problem? I don't think that:
>> > >
>> > > https://cran.r-project.org/web/packages/cleangeo/index.html
>> > >
>> > > does this, as it seems to try to repair broken geometries.
>> > >
>> > > Also note that you need to specify that the area threshold is in a
>> > > square
>> > > planar metric - dropping slivers in unprojected geometries may be more
>> > > complicated.
>> > >
>> > > Roger
>> > >
>> > >
>> > > > Does someone know a way of doing this in plain R?
>> > > >
>> > > > Thanks
>> > > >
>> > > > [[alternative HTML version deleted]]
>> > > >
>> > > > _______________________________________________
>> > > > 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, 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
>> > >
>> > >
>> >
>>
>
>
--
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