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?


2 Answers 2


There is a discussion about this on r-sig-geo. For a definitive answer you should ask there, because there are people who know the insides 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 QGIS, GRASS or SAGA.

For QGIS 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.


There is now the wonderful rmapshaper package by Andy Teucher that includes a simplify function that "performs topologically-aware multi-polygon simplification".

From their github repo, a usage example:

states_simp <- ms_simplify(states_sp)

where states_sp is a spatialPolygons* object.

See the package README for more information: https://github.com/ateucher/rmapshaper

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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