This is part 2 of the 2 part course from CDRC on using the UK Retail Centres dataset to create retail catchments. This practical session shows you how to estimate retail catchments using a gravity or spatial interaction model (SIM), more specifically a probabilistic SIM called the Huff model. Make sure you have completed Part 1 of this Training Course before beginning this section.
After completing this material, you will:
The following video will provide an introduction to Retail Catchment Areas.
First we want to set up the libraries that we are going to be using for this practical - you should have these installed from the previous practical:
library(sf)
library(dplyr)
library(tmap)
tmap_mode("view") ## Interactive Mapping
We also need some additional packages for computation of the Huff Model, so go ahead and install the following packages if you don’t have them already:
#install.packages("rgdal")
library(rgdal)
library(rgeos)
library(igraph)
library(FNN)
Make sure you have set your working directory to wherever you have stored the CDRC-Retail-Catchment-Training folder we have provided:
#setwd("CDRC-Retail-Catchment-Training")
Finally, we need to download some functions that we need for the Huff model. The functions needed have been packaged in a .R file called huff-tools.R
, which you can find in the ‘Scripts’ folder provided for this course. The file contains 9 functions, two of which we will be using in this practical. To read the file and save the functions to your environment, run the following line of code:
## Save huff-tools.R functions to memory
source("Scripts/huff-tools.R")
You will notice you now have 9 new functions in your environment - the primary ones we will be using are huff_basic()
and select_by_probs()
. For more information on these functions visit the huff-tools.R vignette.
Again, we are going to be working with the Liverpool City Region Retail Centres dataset. Specifically we are going to work with the set of Retail Centres we created the hierarchy for in the last practical. So go ahead and read those back into your environment:
## Read in the LCR Retail Centres (with Hierarchy from Part 1)
rc <- st_read("Data/Part2_Retail_Centres.gpkg")
## Reading layer `Part2_Retail_Centres' from data source `C:\Users\nick\Dropbox\Work\2021-27-cdrc-les-dolega-retail-catchments-training\CDRC-Retail-Catchment-Training\Data\Part2_Retail_Centres.gpkg' using driver `GPKG'
## Simple feature collection with 20 features and 6 fields
## geometry type: POINT
## dimension: XY
## bbox: xmin: 321296 ymin: 381776.6 xmax: 351923.6 ymax: 417406.3
## projected CRS: OSGB 1936 / British National Grid
If you don’t have this file or had forgotten to read it out at the end of the practical, go back and complete Section 2 of Part 1 to obtain the hierarchy, and the skip to the end of the practical to write the file out (st_write
).
We will also be needing an empty set of LSOA’s (Lower Super Output Areas) for the Liverpool City Region. For those unfamiliar to LSOAs, they are a set of geographical areas developed following the 2011 census, containing on average 1,500 people in each LSOA. The LSOAs you need for this practical can be found in the ‘Data’ folder, so go ahead and read these in:
## Read in the Liverpool City Region LSOAs
lsoa <- st_read("Data/LCR_LSOA.gpkg")
## Reading layer `LCR_lsoa' from data source `C:\Users\nick\Dropbox\Work\2021-27-cdrc-les-dolega-retail-catchments-training\CDRC-Retail-Catchment-Training\Data\LCR_LSOA.gpkg' using driver `GPKG'
## Simple feature collection with 989 features and 1 field
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: 318351.7 ymin: 378277.6 xmax: 361798.8 ymax: 422878.7
## projected CRS: Transverse_Mercator
For those unfamiliar to LSOA’s, a quick plot will show you roughly what they look like:
## Plot the LSOAs for Liverpool City Region
tm_shape(lsoa) +
tm_fill(alpha = 0.75) +
tm_borders(col = "black", lwd = 0.25, alpha = 0.5)