Simplify polygons without creating slithers

September 29, 2016
By

(This article was first published on rstats – philmikejones.me, and kindly contributed to R-bloggers)

When simplifying polygons it’s almost inevitable that you will generate some slither polygons or gaps between the correct polygons. For example, the following image shows two adjoining complex polygons, representing two adjoining administrative areas. Note there are no gaps between the polygons; they are contiguous (the border is between Sheffield and Barnsley LADs, by the way).

Unsimplified polygons
Original geometries without simplification

Now if we simplify these polygons to reduce their complexity using simplify geometries in QGIS, gaps appear between the original two polygons and they are no longer contiguous.

Polygons simplified with QGIS with sliters visible
Geometries simplified with QGIS simplify geometries command

If you’re just plotting a basic, low resolution thematic map this isn’t necessarily a problem, but it becomes problematic when you try to use these polygons with other data or use the polygons for clipping. There are solutions but correcting them can be a pain, and don’t always work as intended. But why correct them; why not simplify without creating slither polygons in the first place? If you’re an R user the ms_simplify() function in the rmapshaper package allows you to do exactly that.

Polygons simplified with rmapshaper
Simplified geometries using rmapshaper

QGIS’s simplify geometries and rmapshaper::ms_simplify() use different arguments for thresholds, so I’ve matched the level of simplification as best I can to ensure a fair test. The QGIS simplified shapefile is 6.6MB, while the rmapshaper simplified shapefile is 5.7MB (so slightly smaller and still without errors introduced).

To use rmapshaper::ms_simplify() just install and load the library and run it on a spatialPolygons* object:

install.packages("rmapshaper")

library("rmapshaper")

simplified_shape <- ms_simplify(unsimplified_shape)

I’ve created an Rmd notebook you can download and run inside RStudio that takes you through the (very simple) process of simplifying the local authority districts (LADs) in the United Kingdom.

To leave a comment for the author, please follow the link and comment on their blog: rstats – philmikejones.me.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)