subtitle: "example of using the API to get feature layer data - boundaries"
author: "Tom Rushby (@tom_rushby)"
date: 'Last run at: `r Sys.time()`'
output:
bookdown::pdf_document2:
toc: yes
fig_caption: yes
number_sections: yes
bookdown::html_document2:
fig_caption: yes
code_folding: hide
number_sections: yes
toc: yes
toc_depth: 4
toc_float: TRUE
bookdown::word_document2:
fig_caption: yes
number_sections: yes
toc: yes
toc_depth: 4
fig_width: 5
always_allow_html: yes
---
```{r setup, include=FALSE}
# you might need to install these first
library(sf)
library(htmltools)
library(leaflet)
library(utils)
library(dplyr)
```
# Introduction
This script provides an example of downloading and importing administrative boundaries from the Office for National Statistics Open Geography portal into RStudio and plotting on a map. It is based upon a useful example by [Trafford Data Lab](https://medium.com/@traffordDataLab/pushing-the-boundaries-with-the-open-geography-portal-api-4d70637bddc3).
## Creating a query
In this example we want to load Local Authority District geography. The Open Geography portal helpfully provides an [API explorer](https://geoportal.statistics.gov.uk/datasets/ons::local-authority-districts-december-2020-uk-bgc/api) to help us structure the query.
In the code chunk below, we break up the query into parts that we can change depending on the type of geography we want, the areas we want to include, the fields we want the query to return etc.