Dissolving polygons is an elementary GIS task that I need to perform regularly. A dissolve removes internal boundaries, leaving only the outline. Packages Install and load the packages we’ll need. I use sf because it’s more intuitive than rgdal, and I’m loading tidyverse because it plays well with sf. # install.packages(c("tidyverse", "sf")) library("tidyverse") library("sf") Boundary data Download the shapefile we’re going to dissolve. tmp_dir = tempdir() tmp = tempfile(tmpdir = tmp_dir, fileext = ". [Read More]
Clip polygons in R
Clipping polygons is a common GIS task. For example, you might want to study local authorities (LADs) in the Yorkshire and the Humber region but can only obtain a shapefile with all the LADs in England. Removing all the LADs outside of the Yorkshire and the Humber can be achieved by ‘clipping’ the LADs, using the extent of the larger region as a template. HUGOMORE42 First, install and load sf for loading the shapefiles, and tidyverse for manipulating the data and plotting the maps. [Read More]
Set root directory for knitr
Knitr, by default, looks in the same directory as your
.Rmd file to find any files you need to draw in, like data sets or script files.
If you keep your data files and scripts in separate folders (and you should) you need to configure knitr.
Installing RGDAL and RGEOS in R on Linux
RGDAL The RGDAL package is used by R and RStudio to plot maps. Under Linux you may encounter one or two errors when trying to install the package: Error: gdal-config not found. The gdal-config script distributed with GDAL could not be found. Or: configure: error: proj_api.h not found in standard or given locations. ERROR: configuration failed for package 'rgdal' You experience these errors because R in Linux installs the packages from source (rather than a ready-compiled binary) and you need additional libraries to compile RGDAL. [Read More]