[R-sig-Geo] thinning a SpatialPolygonsDataFrame
pinaud at cebc.cnrs.fr
Thu Nov 19 10:59:01 CET 2009
Roger is fully right, this function does not preserve the topology, so
be aware of that, some problems can occur...
If you want to use shapefiles::dp() just for raw plotting and visual
simplification, you can try (on the fly):
fr <- readOGR("polygonFRA_WGS84.shp", "polygonFRA_WGS84") # a shapefile
of France with complex topology (holes, islands...) in WGS84 coordinates
pp <- slot(fr, "polygons") # take the polygons
cf <- coordinates(slot(pp[], "Polygons")[]) # extract the
coordinates of the main polygon ("continental France")
pf <- list(x=cf[,1], y=cf[,2]) # list of coordinates, as dp() needs a
list and not a matrix or dataframe...
cf1 <- dp(pf, 0.1) # simplification, with a bandwith of 0.1 decimal degree
plot(fr) # to see the result
points(cf1, col="red", t="l")
Michael Friendly a écrit :
> I think, for my application, I'd be happy with the D-P polyline
> simplification algorithm, because that is what is used
> in SAS (worked well), and I don't think there are unusual topologies
> in my map of France that would be so severely
> out of whack as to lead to *significant* visual artifacts. In fact,
> you might well expect some artifacts from any visual
> thinning, but it's a matter of the tradeoff in the way the thinned map
> is used in a visualization. Mark Monmonier's
> US Visibility Map might be an extremely thinned, but highly useful
> For R spatial analysis, I think this is worth pursuing and integrating
> into sp methods. In SAS, proc greduce works simply
> by adding another variable, density, to the (x,y) coordinates of the
> spatial polygons, density %in% 1:5, where density==5
> is the full map. It is then a simple matter to subset the polygon
> outlines by saying
> data smallmap;
> set mymap;
> where density<4;
> proc gmap map=mymap(where=(density<4));
> Meanwhile, I can't see easily how I could use shapefiles::dp() to thin
> my Guerry::gfrance maps, because the documentation is,
> shall we say, somewhat thin.
> Roger Bivand wrote:
>> On Wed, 18 Nov 2009, Pinaud David wrote:
>>> Hi Michael,
>>> maybe you should try the function dp() in the package shapefiles
>>> that is an implementation of the Douglas-Peucker polyLine
>>> simplification algorithm.
>> Note that its help page does warn that it is not topology-preserving,
>> that is that lines are generalised, but that coincident lines
>> (boundaries of neighbouring polygons) may be generalised differently.
>> GEOS offers a topology-preserving line generalisation facility, which
>> ought to take longer but do better than dp(), because it will not
>> lead to visual artefacts (overlapping polygons, interpolygon slivers,
>>> Michael Friendly a écrit :
>>>> The Guerry package contains two maps of france (gfrance, gfrance85)
>>>> which are quite detailed and large in size (~900K).
>>>> In writing a vignette for the package, there are quite a few
>>>> figures that use the map multiple times in a layout, and
>>>> consequently result in huge file sizes for the .PDF files created.
>>>> For these purposes, the map need not be nearly
>>>> so detailed.
>>>> I'm wondering if there is a facility to "thin" the map by drawing
>>>> it at a lower density of lines in the polygon regions.
>>>> When I was working with SAS, there was a GREDUCE procedure that did
>>>> this nicely.
Ingénieur de Recherche "Analyses spatiales"
Centre d'Etudes Biologiques de Chizé - CNRS UPR1934
79360 Villiers-en-Bois, France
Tel: +33 (0)5.49.09.35.58
Fax: +33 (0)5.49.09.65.26
__________ Information from ESET Mail Security, version of virus signature database 4621 (20091119) __________
The message was checked by ESET Mail Security.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 324 bytes
Desc: not available
More information about the R-sig-Geo