From f7bc8f8f2c0e9d46db3194bb3a676c1a1495fb54 Mon Sep 17 00:00:00 2001 From: Thomas Rushby <t.w.rushby@soton.ac.uk> Date: Mon, 23 May 2022 16:25:55 +0100 Subject: [PATCH] Update to include Rushmoor local authority area in Hampshire (previously excluded by error). Switch output location to UoS resource drive. --- getBoundaryData.R | 60 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/getBoundaryData.R b/getBoundaryData.R index cee0600..9dc9060 100644 --- a/getBoundaryData.R +++ b/getBoundaryData.R @@ -4,10 +4,13 @@ library(sf) # install first if needed library(data.table) library(here) -# Local Authority boundaries for the Solent region ---- +# Load repo params (file locations etc) +source("env.R") + +# Local Authority boundaries for the Solent region (2018) ---- # see https://medium.com/@traffordDataLab/pushing-the-boundaries-with-the-open-geography-portal-api-4d70637bddc3 -geo_query <- "https://ons-inspire.esriuk.com/arcgis/rest/services/Administrative_Boundaries/Local_Authority_Districts_December_2018_Boundaries_UK_BGC/MapServer/0/query?where=lad18nm%20IN%20(%27Southampton%27,%27Portsmouth%27,%27Winchester%27,%27Eastleigh%27,%27Isle%20of%20Wight%27,%27Fareham%27,%27Gosport%27,%27Test%20Valley%27,%27East%20Hampshire%27,%27Havant%27,%27New%20Forest%27,%27Hart%27,%27Basingstoke%20and%20Deane%27)&outFields=lad18cd,lad18nm,long,lat&outSR=4326&f=geojson" +geo_query <- "https://ons-inspire.esriuk.com/arcgis/rest/services/Administrative_Boundaries/Local_Authority_Districts_December_2018_Boundaries_UK_BGC/MapServer/0/query?where=lad18nm%20IN%20(%27Southampton%27,%27Portsmouth%27,%27Winchester%27,%27Eastleigh%27,%27Isle%20of%20Wight%27,%27Fareham%27,%27Gosport%27,%27Test%20Valley%27,%27Rushmoor%27,%27East%20Hampshire%27,%27Havant%27,%27New%20Forest%27,%27Hart%27,%27Basingstoke%20and%20Deane%27)&outFields=lad18cd,lad18nm,long,lat&outSR=4326&f=geojson" message("Loading LA geometry from ONS Open Geography API") la_sf_data <- sf::st_read(geo_query) @@ -25,6 +28,9 @@ sf::write_sf(la_sf_data, outf) # the code is included here for reference inFile <- path.expand(paste0(here::here("data", "boundaries", "msoa_all", "Middle_Layer_Super_Output_Areas__December_2011__Boundaries_Full_Clipped__BFC__EW_V3.shp"))) + +inFile <- paste0(dPath, "census/downloads/msoa/", "Middle_Layer_Super_Output_Areas_(December_2011)_Boundaries_Generalised_Clipped_(BGC)_EW_V3-shp") + msoa_all_sf <- sf::read_sf(inFile) # load the look up table so we can filter @@ -38,19 +44,22 @@ oa_lut <- data.table::fread(lutFile) # "Havant","New Forest","Hart","Basingstoke and Deane") # select the OAs we want via LAs -oa_solentLut <- oa_lut[LAD11NM == "Southampton" | - LAD11NM == "Portsmouth" | - LAD11NM == "Winchester" | - LAD11NM == "Eastleigh" | - LAD11NM == "Isle of Wight" | - LAD11NM == "Fareham" | - LAD11NM == "Gosport" | - LAD11NM == "Test Valley" | - LAD11NM == "East Hampshire" | - LAD11NM == "Havant" | - LAD11NM == "New Forest" | - LAD11NM == "Hart" | - LAD11NM == "Basingstoke and Deane"] +oa_solentLut <- oa_lut[ + LAD11NM == "Basingstoke and Deane" | + LAD11NM == "East Hampshire" | + LAD11NM == "Eastleigh" | + LAD11NM == "Fareham" | + LAD11NM == "Gosport" | + LAD11NM == "Hart" | + LAD11NM == "Havant" | + LAD11NM == "New Forest" | + LAD11NM == "Rushmoor" | # Added + LAD11NM == "Test Valley" | + LAD11NM == "Isle of Wight" | + LAD11NM == "Portsmouth" | + LAD11NM == "Southampton" | + LAD11NM == "Winchester" +] oa_solentLut[, .(nOAs = .N), keyby = .(LAD11NM)] @@ -67,7 +76,13 @@ msoa_solent <- merge(msoa_all_sf, msoa_solentLut) table(msoa_solent$LAD11NM) # save it out for re-use -outf <- path.expand(paste0(here::here("data", "boundaries", "msoa_solent.shp"))) +# two possible locations - repo or UoS resource drive + +# Repo +#outf <- path.expand(paste0(here::here("data", "boundaries", "msoa_solent.shp"))) + +# UoS resource drive +outf <- paste0(outPath, "MSOA_solent_2011.shp") sf::write_sf(msoa_solent, outf) # LSOA boundaries for the Solent region ---- @@ -78,6 +93,9 @@ sf::write_sf(msoa_solent, outf) # load all LSOAs from file inFile <- path.expand("~//Dropbox/data/UK_census2011/Lower_Layer_Super_Output_Areas_(December_2011)_Boundaries_Generalised_Clipped_(BGC)_EW_V3-shp/Lower_Layer_Super_Output_Areas_(December_2011)_Boundaries_Generalised_Clipped_(BGC)_EW_V3.shp") # local version + +inFile <- paste0(dPath, "census/downloads/lsoa/", "Lower_Layer_Super_Output_Areas_(December_2011)_Boundaries_Generalised_Clipped_(BGC)_EW_V3.shp") + lsoa_all_sf <- sf::read_sf(inFile) # las_to_load <- c("Southampton","Portsmouth","Winchester", @@ -98,5 +116,13 @@ lsoa_solent <- merge(lsoa_all_sf, lsoa_solentLut) table(lsoa_solent$LAD11NM) # save it out for re-use -outf <- paste0(here::here("data", "boundaries", "lsoa_solent.shp")) +# two possible locations - repo or UoS resource drive + +# Repo +#outf <- paste0(here::here("data", "boundaries", "lsoa_solent.shp")) + +# UoS resource drive +outf <- paste0(outPath, "LSOA_solent_2011.shp") + sf::write_sf(lsoa_solent, outf) + -- GitLab