Skip to content

Commit ed416a6

Browse files
committed
Postcode lookup for NI added
1 parent 5aa696a commit ed416a6

File tree

7 files changed

+87
-0
lines changed

7 files changed

+87
-0
lines changed

.Rhistory

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ setwd("~/Documents/Internship Red Cross/Github/geographr")
22
# Load package
33
load_all(".")
44
devtools::load_all(".")
5+
devtools::load_all(".")
6+
devtools::document()
7+
?lookup_soa01_ldg14
8+
?lookup_soa01_lgd14

R/data.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,25 @@
11621162
#' @source \url{https://geoportal.statistics.gov.uk/}
11631163
"lookup_nhs_trusts22_stp21"
11641164

1165+
#' Postcode to Data Zone to Super DataZone to District Electoral Areas to Local Government District
1166+
#' lookup for Northern Ireland
1167+
#'
1168+
#' @format A data frame of class "tbl":
1169+
#' \describe{
1170+
#' \item{postcode}{Postcode}
1171+
#' \item{dz21_code}{Data zone (2021) code (comparable to Output Areas)}
1172+
#' \item{dz21_name}{Data zone (2021) name}
1173+
#' \item{sdz21_code}{Super data zone (2021) code (comparable to LSOA / Scottish Data Zone)}
1174+
#' \item{sdz21_name}{Super data zone (2021) name}
1175+
#' \item{dea14_code}{District Electoral Areas (2019) code}
1176+
#' \item{dea14_name}{District Electoral Areas (2019) name}
1177+
#' \item{lgd14_code}{Local Government District (2014) code (comparable to Local Authority)}
1178+
#' \item{lgd14_name}{Local Government District (2014) name}
1179+
#' ...
1180+
#' }
1181+
#' @source \url{https://geoportal.statistics.gov.uk/}
1182+
"lookup_postcode_dz21_sdz21_dea14_lgd14"
1183+
11651184
#' Postcode to Output Area (2011) to Lower Layer Super Output Area (2011) to
11661185
#' Middle Layer Super Output Area (2011) to Local Authority District (2020)
11671186
#' Lookup

R/sysdata.rda

45 Bytes
Binary file not shown.

data-raw/lookup_postcode_ni.R

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
library(tidyverse)
2+
library(httr)
3+
library(geographr)
4+
library(devtools)
5+
6+
# Load package
7+
load_all(".")
8+
9+
# Set query url
10+
query_url <-
11+
query_urls |>
12+
filter(id == "postcode_dz21_sdz21_dea14_lgd14") |>
13+
pull(query)
14+
15+
download <- tempfile(fileext = ".zip")
16+
response <- GET(query_url, write_disk(download, overwrite = TRUE))
17+
unzip(download, exdir = tempdir())
18+
19+
postcode_raw <- read_csv(file.path(tempdir(), "Data/ONSPD_NOV_2023_UK.csv"))
20+
21+
lookup_postcode_dz21_sdz21_dea14_lgd14 <- postcode_raw |>
22+
filter(str_detect(oslaua, "^N")) |>
23+
select(postcode = pcd,
24+
dz21_code = oa21) |>
25+
left_join(lookup_dz21_sdz21_dea14_lgd14, by = c("dz21_code")) |>
26+
mutate(postcode = str_replace_all(postcode, "\\s", ""))
27+
28+
29+
# Save output to data/ folder
30+
usethis::use_data(lookup_postcode_dz21_sdz21_dea14_lgd14, overwrite = TRUE)

data-raw/query-urls.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ query_urls <-
7575
"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",
7676
"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",
7777
"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",
78+
"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",
7879
"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",
7980
"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",
8081
"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",
264 KB
Binary file not shown.

man/lookup_postcode_dz21_sdz21_dea14_lgd14.Rd

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)