When you download geographical data the polygons are often highly detailed, leading to large file sizes and slow processing times. Often this detail is unnecessary if you’re not intending to produce small–scale maps. Most thematic maps, for example, tend to compare large geographies such as nations or regions, so the detail is unnecessary. Likewise, if you’re producing your map for use on the web, for example as an interactive visualisation, too much detail can slow the rendering and responsiveness of your app.
This week I updated my Townsend Material Deprivation Score project. The update makes townsendr an interactive online map of deprivation that users can simply view in their browser, rather than having to download and run the R code or view only static maps. I think the result is much more intuitive and useful.
Making the map interactive is achieved by using Shiny, a technology for R to make interactive charts and plots.
I love a good bit of map making and I have a bit of time on my hands at the moment, so I followed this tutorial by Steven Bernard to create a globe from a world map in QGIS:
The steps are straightforward. The fiddly bit was getting the line endings and indentation correct which are essential in Python, so I copied the text out and created a gist with line endings preserved:
Dissolving polygons is another fairly elementary GIS task that I need to perform regularly. With R this is can be a bit involved, but once done is fully reproducible and the code can be re-used. This post is essentially a companion piece to Clipping polygons in R; I wrote both because I often forget how to complete these tasks in R.
Getting started Let’s gather together everything we need to complete this example.
Clipping polygons is a basic GIS task. It involves removing unneeded polygons outside of an area of interest. For example, you might want to study all local authorities (LADs) in the Yorkshire and the Humber region but can only obtain shapefiles that contain all the LADs in the UK. Removing the LADs outside of Yorkshire and the Humber could be achieved by ‘clipping’ the shapefile of LADs, using the extent of the larger region as a template.
UK UK shapefiles for various administrative geographies can be easily obtained from UK Data Service Census Support boundary data pages, and most use the permissive Open Government License.
Countries DIVA-GIS is a pretty good source for country shapefiles, including administrative boundaries, natural features, and infrastructure. Thanks to Tom B for pointing this one out.
Geofabrik provide OpenStreetMap data extracts in a convenient format.
Country-specific coordinate reference systems (projections) When viewing a map of the world it’s common to use the WGS84 (World Geodetic System 1984) coordinate reference system (CRS), although others can be used.