Hi Michael,
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):

library(rgdal)
library(shapefiles)

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[[39]], "Polygons")[[1]]) # 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")

HTH
David

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 example.

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;

or

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.
-Michael



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, etc.).

Roger

HTH
David

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.

thanks,
-Michael







--
***************************************************
David PINAUD
Ingénieur de Recherche "Analyses spatiales"

Centre d'Etudes Biologiques de Chizé - CNRS UPR1934
79360 Villiers-en-Bois, France poste 485
Tel: +33 (0)5.49.09.35.58
Fax: +33 (0)5.49.09.65.26
http://www.cebc.cnrs.fr/

***************************************************




__________ Information from ESET Mail Security, version of virus signature 
database 4621 (20091119) __________

The message was checked by ESET Mail Security.
http://www.eset.com

<<attachment: pinaud.vcf>>

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to