Skip to content
Snippets Groups Projects
Commit f7bc8f8f authored by Tom Rushby's avatar Tom Rushby
Browse files

Update to include Rushmoor local authority area in Hampshire (previously...

Update to include Rushmoor local authority area in Hampshire (previously excluded by error). Switch output location to UoS resource drive.
parent feb8e021
No related branches found
No related tags found
1 merge request!6Update to include Rushmoor local authority area in Hampshire (previously missing)
...@@ -4,10 +4,13 @@ library(sf) # install first if needed ...@@ -4,10 +4,13 @@ library(sf) # install first if needed
library(data.table) library(data.table)
library(here) 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 # 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") message("Loading LA geometry from ONS Open Geography API")
la_sf_data <- sf::st_read(geo_query) la_sf_data <- sf::st_read(geo_query)
...@@ -25,6 +28,9 @@ sf::write_sf(la_sf_data, outf) ...@@ -25,6 +28,9 @@ sf::write_sf(la_sf_data, outf)
# the code is included here for reference # the code is included here for reference
inFile <- path.expand(paste0(here::here("data", "boundaries", "msoa_all", inFile <- path.expand(paste0(here::here("data", "boundaries", "msoa_all",
"Middle_Layer_Super_Output_Areas__December_2011__Boundaries_Full_Clipped__BFC__EW_V3.shp"))) "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) msoa_all_sf <- sf::read_sf(inFile)
# load the look up table so we can filter # load the look up table so we can filter
...@@ -38,19 +44,22 @@ oa_lut <- data.table::fread(lutFile) ...@@ -38,19 +44,22 @@ oa_lut <- data.table::fread(lutFile)
# "Havant","New Forest","Hart","Basingstoke and Deane") # "Havant","New Forest","Hart","Basingstoke and Deane")
# select the OAs we want via LAs # select the OAs we want via LAs
oa_solentLut <- oa_lut[LAD11NM == "Southampton" | oa_solentLut <- oa_lut[
LAD11NM == "Portsmouth" | LAD11NM == "Basingstoke and Deane" |
LAD11NM == "Winchester" | LAD11NM == "East Hampshire" |
LAD11NM == "Eastleigh" | LAD11NM == "Eastleigh" |
LAD11NM == "Isle of Wight" | LAD11NM == "Fareham" |
LAD11NM == "Fareham" | LAD11NM == "Gosport" |
LAD11NM == "Gosport" | LAD11NM == "Hart" |
LAD11NM == "Test Valley" | LAD11NM == "Havant" |
LAD11NM == "East Hampshire" | LAD11NM == "New Forest" |
LAD11NM == "Havant" | LAD11NM == "Rushmoor" | # Added
LAD11NM == "New Forest" | LAD11NM == "Test Valley" |
LAD11NM == "Hart" | LAD11NM == "Isle of Wight" |
LAD11NM == "Basingstoke and Deane"] LAD11NM == "Portsmouth" |
LAD11NM == "Southampton" |
LAD11NM == "Winchester"
]
oa_solentLut[, .(nOAs = .N), keyby = .(LAD11NM)] oa_solentLut[, .(nOAs = .N), keyby = .(LAD11NM)]
...@@ -67,7 +76,13 @@ msoa_solent <- merge(msoa_all_sf, msoa_solentLut) ...@@ -67,7 +76,13 @@ msoa_solent <- merge(msoa_all_sf, msoa_solentLut)
table(msoa_solent$LAD11NM) table(msoa_solent$LAD11NM)
# save it out for re-use # 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) sf::write_sf(msoa_solent, outf)
# LSOA boundaries for the Solent region ---- # LSOA boundaries for the Solent region ----
...@@ -78,6 +93,9 @@ sf::write_sf(msoa_solent, outf) ...@@ -78,6 +93,9 @@ sf::write_sf(msoa_solent, outf)
# load all LSOAs from file # 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 <- 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) lsoa_all_sf <- sf::read_sf(inFile)
# las_to_load <- c("Southampton","Portsmouth","Winchester", # las_to_load <- c("Southampton","Portsmouth","Winchester",
...@@ -98,5 +116,13 @@ lsoa_solent <- merge(lsoa_all_sf, lsoa_solentLut) ...@@ -98,5 +116,13 @@ lsoa_solent <- merge(lsoa_all_sf, lsoa_solentLut)
table(lsoa_solent$LAD11NM) table(lsoa_solent$LAD11NM)
# save it out for re-use # 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) sf::write_sf(lsoa_solent, outf)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment