Vector boundaries
The Office for National Statistics’ Open Geography Portal provide a range of geospatial datasets under the Open Government Licence 3.0. Digital vector boundaries for different administrative and statistical geographies are available to freely download. Here we’ll download a single local authority boundary file.
Ingredients
Instructions
- Load the necessary R packages.
library(tidyverse) ; library(sf)
Visit the ONS Open Geography Portal and select your local authority boundary: Boundaries > Administrative Boundaries > Local Authority Districts. For example, choose Local Authority Districts (December 2018) Boundaries UK BGC from the list.
Select the ‘APIs’ button on the right hand side and copy the URL path under GeoJSON.
Paste the URL path into the
st_read()
function and retrieve the data.
sf <- st_read("https://opendata.arcgis.com/datasets/2c5b8eb836c7475ba3b305106ac9dfc3_0.geojson")
- Filter by your chosen local authority
sf <- filter(sf, lad18nm == "Trafford")
- Check the coordinate reference system
st_crs(bdy)
- Plot the results
plot(st_geometry(sf))
- Save the boundary as a GeoJSON
st_write(sf, "local_authority_boundary.geojson")
- Load the necessary R packages.
library(tidyverse) ; library(sf)
Visit the ONS Open Geography Portal and select your local authority boundary: Boundaries > Administrative Boundaries > Local Authority Districts. For example, choose Local Authority Districts (December 2018) Boundaries UK BGC from the list.
Select the ‘API Explorer’ button at the top of the page.
Navigate to the ‘Query’ box and click the + next to the ‘Where’ parameter. Select ‘lad18nm | Text’ from the ‘Attributes’ pick list and enter your local authority name in the box. Press Enter on your keyboard.
Highlight and copy the URL that appears in the ‘Query URL’ box.
Paste the URL path into the
st_read()
function and retrieve the data. Note that we’ve added on ‘geojson’.
sf <- st_read("https://ons-inspire.esriuk.com/arcgis/rest/services/Administrative_Boundaries/Local_Authority_Districts_December_2018_Boundaries_UK_BGC/MapServer/0/query?where=lad18nm%20=%20%27Trafford%27&outFields=lad18cd,lad18nm,long,lat&outSR=4326&f=geojson")
Notes
Further information can be found in our Medium article: “Pushing the boundaries with the Open Geography Portal API”.