Skip to contents

Fetches the generalised, clipped (BGC, 20 m) boundaries for a geography from the ONS Open Geography Portal, in British National Grid (EPSG:27700), and caches them. Products: 2021 LSOAs, 2011 LSOAs, 2021 MSOAs, December 2022 local authority districts (England and Wales only) and December 2023 police force areas. The generalised boundaries suit adjacency and mapping; a search made within a few metres of a boundary can be assigned to the neighbouring area, so supply full-resolution boundaries yourself for point-in-polygon work that needs that precision.

Usage

lamp_boundaries(
  type = c("lsoa21", "lsoa11", "msoa21", "lad", "pfa"),
  dir = lamp_cache_dir(),
  refresh = FALSE
)

Arguments

type

One of "lsoa21" (default), "lsoa11", "msoa21", "lad" or "pfa".

dir

Cache directory; see lamp_cache_dir().

refresh

Fetch again even if a cached copy exists.

Value

An sf object with columns area (code), name and geometry (multipolygons, EPSG:27700), sorted by area, with attributes vintage (for example "lsoa21-bgc-v5"), product (the ONS title and item identifier) and retrieved.

Details

Without network access a cached copy is returned, and an error of class streetlamp_error_network is raised if there is none. A first fetch of the 2021 LSOA layer reads about 50 MB in 18 pages.

Source: Office for National Statistics licensed under the Open Government Licence v3.0; contains OS data, Crown copyright and database right 2024.

Examples

# \donttest{
# Needs network access. The boundaries are cached in a temporary directory,
# and the example prints a message instead of failing when offline.
pfa <- tryCatch(
  lamp_boundaries("pfa", dir = tempfile("streetlamp-")),
  streetlamp_error_network = function(e) message(conditionMessage(e))
)
#> Network access is disabled by `STREETLAMP_OFFLINE`.
#> ℹ Could not fetch
#>   https://services1.arcgis.com/ESMARspQHYMw9BZ9/arcgis/rest/services/Police_Force_Areas_December_2023_EW_BGC/FeatureServer/0/query?where=1%3D1&outFields=PFA23CD%2CPFA23NM&returnGeometry=true&outSR=27700&f=geojson&resultOffset=0&resultRecordCount=2000.
if (!is.null(pfa)) {
  plot(sf::st_geometry(pfa))
  lamp_adjacency(pfa)
}
# }