Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I would like to generalize a SpatialPolygonsDataFrame in R to make plotting more efficient. The polygons I have result in huge pdf plots that are slow to load and hard to integrate into a document.

I tried to use the gSimplify function from the rgeos package, but unfortunately it does not conserve the topology of the polygons.

Is there an alternative that I can use?

thanks

share|improve this question
    
not really a solution, but could you plot to raster (jpg/png) instead? This stackoverflow question which discusses pdfsize reduction may be of use: stackoverflow.com/questions/8521299/… –  djq Aug 5 '12 at 1:37
    
plotting the maps as raster image is an option, but whenever possible I would like to use vector graphics. The image quality is better when using vector graphics, especially when looking at the digital version of documents. –  yellowcap Aug 6 '12 at 10:00
    
gSimplify() has an optional parameter topologyPreserve which defaults to FALSE. Have you tried setting that to TRUE? –  krlmlr Jan 22 '13 at 16:34

2 Answers 2

up vote 7 down vote accepted

There is a discussion about this on r-sig-geo. For a definitive answer you should ask there, cause there are peoples which know the insights of spatial R.

But, you can also do this in GIS desktop applications (export the shape using writeOGR command from rgdal or writePolyShape() from maptools) like QuantumGIS, GRASS or SAGA.

For QuantumGIS use Vector / Geometry Tools / Simplify geometries (I have tested and does not preserve the topology, but applied to Romania admin1 shapefile, looks fine with 2000 nodes).

For GRASS use v.generalize (read the manual for info about the algorithms, there are some).

For SAGA you must first convert the polygon to line (Shapes - Lines / Convert Polygons to Lines), then simplify lines (Shapes Lines / Line Simplification), and finally convert lines to polygons (Shapes - Polygons / Convert Lines to Polygons). I have tested this and the results has the topology preserved.

Cheers and good luck,

share|improve this answer
    
In the meantime I have also found an online service that performs simplification while conserving topologies: mapshaper.org. I have used it as alternative, as it seems that it is not possible in R directly (QGis is not really topology conserving and I don't know the other software packages) –  yellowcap Aug 6 '12 at 15:41
    
I tested your observation with Saga 2.0.8, and the result doesn't have topology preserved! –  Fabian Zeindl Apr 5 '13 at 13:57

that should help:

  • gSimplify(..., topologyPreserve=T) from the GEOS package
share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

    
unfortunately the topology preserve option in gSimplify does not really preserve the topology over several polygons. I think it relates more to the topology of single or multipolygons. For a shapefile with many polygons, the topology is not conserved. –  yellowcap May 29 '13 at 14:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.