Skip to content

Commit

Permalink
Postcode lookup for NI added
Browse files Browse the repository at this point in the history
  • Loading branch information
jennajt committed Aug 7, 2024
1 parent 5aa696a commit ed416a6
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .Rhistory
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ setwd("~/Documents/Internship Red Cross/Github/geographr")
# Load package
load_all(".")
devtools::load_all(".")
devtools::load_all(".")
devtools::document()
?lookup_soa01_ldg14
?lookup_soa01_lgd14
19 changes: 19 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,25 @@
#' @source \url{https://geoportal.statistics.gov.uk/}
"lookup_nhs_trusts22_stp21"

#' Postcode to Data Zone to Super DataZone to District Electoral Areas to Local Government District
#' lookup for Northern Ireland
#'
#' @format A data frame of class "tbl":
#' \describe{
#' \item{postcode}{Postcode}
#' \item{dz21_code}{Data zone (2021) code (comparable to Output Areas)}
#' \item{dz21_name}{Data zone (2021) name}
#' \item{sdz21_code}{Super data zone (2021) code (comparable to LSOA / Scottish Data Zone)}
#' \item{sdz21_name}{Super data zone (2021) name}
#' \item{dea14_code}{District Electoral Areas (2019) code}
#' \item{dea14_name}{District Electoral Areas (2019) name}
#' \item{lgd14_code}{Local Government District (2014) code (comparable to Local Authority)}
#' \item{lgd14_name}{Local Government District (2014) name}
#' ...
#' }
#' @source \url{https://geoportal.statistics.gov.uk/}
"lookup_postcode_dz21_sdz21_dea14_lgd14"

#' Postcode to Output Area (2011) to Lower Layer Super Output Area (2011) to
#' Middle Layer Super Output Area (2011) to Local Authority District (2020)
#' Lookup
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
30 changes: 30 additions & 0 deletions data-raw/lookup_postcode_ni.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
library(tidyverse)
library(httr)
library(geographr)
library(devtools)

# Load package
load_all(".")

# Set query url
query_url <-
query_urls |>
filter(id == "postcode_dz21_sdz21_dea14_lgd14") |>
pull(query)

download <- tempfile(fileext = ".zip")
response <- GET(query_url, write_disk(download, overwrite = TRUE))
unzip(download, exdir = tempdir())

postcode_raw <- read_csv(file.path(tempdir(), "Data/ONSPD_NOV_2023_UK.csv"))

lookup_postcode_dz21_sdz21_dea14_lgd14 <- postcode_raw |>
filter(str_detect(oslaua, "^N")) |>
select(postcode = pcd,
dz21_code = oa21) |>
left_join(lookup_dz21_sdz21_dea14_lgd14, by = c("dz21_code")) |>
mutate(postcode = str_replace_all(postcode, "\\s", ""))


# Save output to data/ folder
usethis::use_data(lookup_postcode_dz21_sdz21_dea14_lgd14, overwrite = TRUE)
1 change: 1 addition & 0 deletions data-raw/query-urls.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ query_urls <-
"lookup", "msoa11_ltla21", "25.11.21", "OGLv3", "https://www.arcgis.com/sharing/rest/content/items/b4c0247ef8564d419bdeb1eda13f2d0f/data", "https://geoportal.statistics.gov.uk/documents/middle-layer-super-output-area-2011-to-ward-to-ltla-december-2021-lookup-in-england-and-wales/about",
"lookup", "msoa11_msoa21_ltla22", "15.08.22", "OGLv3", "https://services1.arcgis.com/ESMARspQHYMw9BZ9/arcgis/rest/services/MSOA11_MSOA21_LAD22_EW_LU_V2/FeatureServer/0/query?where=1%3D1&outFields=*&outSR=4326&f=json", "https://geoportal.statistics.gov.uk/datasets/ons::msoa-2011-to-msoa-2021-to-local-authority-district-2022-lookup-for-england-and-wales-version-2/about",
"lookup", "nhs_trust22_msoa11", "26.06.22", "?", "https://app.box.com/index.php?rm=box_download_shared_file&shared_name=qh8gzpzeo1firv1ezfxx2e6c4tgtrudl&file_id=f_976234504165", "https://app.box.com/s/qh8gzpzeo1firv1ezfxx2e6c4tgtrudl",
"lookup", "postcode_dz21_sdz21_dea14_lgd14", "2023", "OGLv3", "https://www.arcgis.com/sharing/rest/content/items/3700342d3d184b0d92eae99a78d9c7a3/data", "https://geoportal.statistics.gov.uk/datasets/ons-postcode-directory-november-2023/about",
"lookup", "postcode_oa11_lsoa11_msoa11_ltla20", "23.11.20", "OGLv3", "https://www.arcgis.com/sharing/rest/content/items/9f629cd0c2fb42beb0d79a474fee4776/data", "https://geoportal.statistics.gov.uk/datasets/9f629cd0c2fb42beb0d79a474fee4776/about",
"lookup", "postcode_oa21_lsoa21_msoa21_ltla22", "29.11.21", "OGLv3", "https://www.arcgis.com/sharing/rest/content/items/bcfc75627db44bb4b0261f8578361954/data", "https://geoportal.statistics.gov.uk/datasets/postcode-to-output-area-hierarchy-to-ltla-to-utla-to-region-to-country-may-2021-lookup-in-england-and-wales-1/about",
"lookup", "sa11_soa11_lgd18", "23.08.22", "OGLv3", "https://opendata.arcgis.com/datasets/096a7ccbc8e244cc972189b2f07a321a_0.csv", "https://geoportal.statistics.gov.uk/datasets/small-areas-2011-to-soas-to-local-government-districts-december-2018-lookup-with-area-classifications-in-northern-ireland",
Expand Down
Binary file added data/lookup_postcode_dz21_sdz21_dea14_lgd14.rda
Binary file not shown.
33 changes: 33 additions & 0 deletions man/lookup_postcode_dz21_sdz21_dea14_lgd14.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ed416a6

Please sign in to comment.