Skip to content

Commit c70e41b

Browse files
committed
Added Local Nature Reserves dataset and updated the Sites of Special Scientific Interest script and README to reflect the correct date that the data was last updated and also to use the full resolution version of the LA boundary with which to clip the national dataset for higher accuracy.
1 parent c57b4e9 commit c70e41b

5 files changed

Lines changed: 161 additions & 6 deletions

File tree

local_nature_reserves/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<table>
2+
<tr>
3+
<td>Dataset name</td>
4+
<td>Local Nature Reserves in Trafford</td>
5+
</tr>
6+
<tr>
7+
<td>Dataset description</td>
8+
<td>Local Nature Reserves (LNRs) are a statutory designation made under Section 21 of the National Parks and Access to the Countryside Act 1949 by principal local authorities. LNRs are for people and wildlife. They are places with wildlife or geological features that are of special interest locally. They offer people opportunities to study or learn about nature or simply to enjoy it. They are an impressive natural resource which makes an important contribution to England's biodiversity.</td>
9+
</tr>
10+
<tr>
11+
<td>Source</td>
12+
<td>Natural England</td>
13+
</tr>
14+
<tr>
15+
<td>Publisher</td>
16+
<td>Natural England</td>
17+
</tr>
18+
<tr>
19+
<td>Publisher URL</td>
20+
<td><a href="https://www.data.gov.uk/dataset/acdf4a9e-a115-41fb-bbe9-603c819aa7f7/local-nature-reserves-england">https://www.data.gov.uk/dataset/acdf4a9e-a115-41fb-bbe9-603c819aa7f7/local-nature-reserves-england</a></td>
21+
</tr>
22+
<tr>
23+
<td>Geography</td>
24+
<td>Local authority</td>
25+
</tr>
26+
<tr>
27+
<td>Geographic coverage</td>
28+
<td>Trafford</td>
29+
</tr>
30+
<tr>
31+
<td>Temporal coverage</td>
32+
<td>2024-06-18</td>
33+
</tr>
34+
<tr>
35+
<td>Update frequency</td>
36+
<td>Unknown</td>
37+
</tr>
38+
<tr>
39+
<td>Licence</td>
40+
<td><a href="http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/">Open Government Licence</a></td>
41+
</tr>
42+
<tr>
43+
<td>Attribution</td>
44+
<td>&copy; Natural England copyright. Contains Ordnance Survey data &copy; Crown copyright and database right [year].</td>
45+
</tr>
46+
<tr>
47+
<td>Format</td>
48+
<td>GeoJSON</td>
49+
</tr>
50+
<tr>
51+
<td>Openness rating</td>
52+
<td>&#9733&#9733&#9733&#9734&#9734&nbsp; Structured data in open format (e.g. CSV)</td>
53+
</tr>
54+
<tr>
55+
<td>Last updated</td>
56+
<td>2024-08-15</td>
57+
</tr>
58+
<tr>
59+
<td>Notes</td>
60+
<td></td>
61+
</tr>
62+
<tr>
63+
<td>Lab visualisation</td>
64+
<td>View data within the Lab's <a href="https://www.trafforddatalab.io/explore/#dataset=nature_reserves">Explore application</a>.</td>
65+
</tr>
66+
</table>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Local Nature Reserves in Trafford
2+
# Created 2024-08-15
3+
# Data updated: 2024-06-18
4+
# Data: https://naturalengland-defra.opendata.arcgis.com/datasets/Defra::local-nature-reserves-england/about
5+
# Metadata: https://www.data.gov.uk/dataset/acdf4a9e-a115-41fb-bbe9-603c819aa7f7/local-nature-reserves-england
6+
# Licence: Open Government Licence v3 (https://www.data.gov.uk/dataset/acdf4a9e-a115-41fb-bbe9-603c819aa7f7/local-nature-reserves-england#licence-info)
7+
8+
# NOTES:
9+
# These features are obtained from an ArcGIS API service, similar to that of the ONS Geography Portal.
10+
# The default API call returns features for the whole county, therefore it's best to use some extra parameters, such as defining a rectangle (spatial envelope) around the LA, to reduce the amount of data being returned and speed up the process.
11+
12+
13+
# Required packages ---------
14+
library(tidyverse) ; library(sf)
15+
16+
# =========
17+
# VERY IMPORTANT NOTE REGARDING SF PACKAGE AND COORDINATE WINDING ORDER 2023-12-21:
18+
# The IETF standard for GeoJSON has made certain changes over the original non-IETF specification. The changes can be viewed here: https://datatracker.ietf.org/doc/html/rfc7946#appendix-B
19+
# One key change is that polygon rings MUST follow the right-hand rule for orientation (counter-clockwise external rings, clockwise internal rings).
20+
# This change has caused issues with certain libraries which have historically used the left-hand rule, i.e. clockwise for outer rings and counter-clockwise for interior rings.
21+
# D3-Geo, Vega-Lite and versions of sf below 1.0.0 (default behaviour) use the GEOS library for performing flat-space calculations, known as R^2 (R-squared) which produce polygons wound to the left-hand rule.
22+
# The sf package from version 1.0.0 onwards now uses the S2 library by default which performs S^2 (S-squared) spherical calculations and returns polygons wound according to the right-hand rule.
23+
# At the time of writing, if we want our geography files to work in D3 and Vega-Lite, they must use the left-hand rule and so we need sf to use the GEOS library not S2.
24+
# More information regarding this can be found at: https://r-spatial.github.io/sf/articles/sf7.html#switching-between-s2-and-geos
25+
# =========
26+
sf_vers <- package_version(packageVersion('sf')) # packageVersion returns a character string, package_version converts that into numeric version numbers (major.minor.patch) e.g. 1.0.0
27+
28+
# Only run the following if we are using sf version 1.0.0 or above
29+
if (sf_vers$major >= 1) {
30+
useS2 <- sf_use_s2() # store boolean to indicating if sf is currently using the s2 spherical geometry package for geographical coordinate operations
31+
sf_use_s2(FALSE) # force sf to use R^2 flat space calculations using GEOS which returns polygons with left-hand windings
32+
}
33+
34+
35+
# API parameters specifying the spatial rectangular area containing Trafford
36+
api_geommetry_envelope <- "&geometryType=esriGeometryEnvelope&geometry=%7B%22spatialReference%22%3A%7B%22latestWkid%22%3A3857%2C%22wkid%22%3A102100%7D%2C%22xmin%22%3A-278455.35481123265%2C%22ymin%22%3A7047642.057770884%2C%22xmax%22%3A-244823.0623658004%2C%22ymax%22%3A7073592.428873666%2C%22type%22%3A%22esriGeometryEnvelope%22%7D"
37+
38+
39+
# Local authority district -------------------------
40+
# Source: ONS Open Geography Portal
41+
# URL: https://geoportal.statistics.gov.uk/datasets/ons::local-authority-districts-may-2023-boundaries-uk-bfc/about
42+
# Licence: OGL v3.0
43+
# NOTE: we need the LA boundary stored as an sf object for use in st_intersection() calculations for other boundaries/features
44+
# we use the full resolution version as this ensures any features near the border are included/not included correctly
45+
la <- st_read("https://services1.arcgis.com/ESMARspQHYMw9BZ9/arcgis/rest/services/Local_Authority_Districts_May_2023_UK_BFC_V2/FeatureServer/0/query?outFields=*&where=UPPER(lad23cd)%20like%20%27%25E08000009%25%27&f=geojson") %>%
46+
select(area_code = LAD23CD, area_name = LAD23NM)
47+
48+
49+
# Get the information for areas within Trafford -------------------------
50+
df_lnr <- st_read(paste0("https://services.arcgis.com/JJzESW51TqeY9uat/arcgis/rest/services/Local_Nature_Reserves_England/FeatureServer/0/query?outFields=*&where=1%3D1&f=geojson", api_geommetry_envelope)) %>%
51+
st_intersection(la)
52+
53+
# Process the dataset, renaming and creating required variables
54+
df_lnr <- df_lnr %>%
55+
rename(site_name = LNR_NAME,
56+
site_area_hectares = LNR_AREA,
57+
site_area_square_metres = Shape__Area,
58+
natural_england_gid = GID,
59+
british_map_grid_reference = REFERENCE) %>%
60+
# Calculate and store the coordinates of each locality's centroid as a "lat" and "lon" property
61+
mutate(lon = map_dbl(geometry, ~st_centroid(.x)[[1]]),
62+
lat = map_dbl(geometry, ~st_centroid(.x)[[2]]),
63+
site_area_hectares = as.numeric(str_trim(format(site_area_hectares, nsmall = 2))),
64+
site_area_square_metres = as.numeric(str_trim(format(site_area_square_metres, nsmall = 2)))) %>%
65+
select(site_name,
66+
site_area_hectares,
67+
site_area_square_metres,
68+
natural_england_gid,
69+
british_map_grid_reference,
70+
lon,
71+
lat)
72+
73+
74+
# Create the Local Nature Reserves file for Trafford -------------------------
75+
st_write(df_lnr, "trafford_local_nature_reserves.geojson")
76+
77+
78+
# Ensure sf_use_s2() is reset to the state it was in before running the code above, i.e. whether to use the S2 library (for S^2 spherical coordinates) or GEOS (for R^2 flat space coordinates). Only if using v1 or above of the sf package
79+
if (sf_vers$major >= 1) sf_use_s2(useS2)

local_nature_reserves/trafford_local_nature_reserves.geojson

Lines changed: 9 additions & 0 deletions
Large diffs are not rendered by default.

sites_of_special_scientific_interest/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</tr>
1818
<tr>
1919
<td>Publisher URL</td>
20-
<td><a href="https://www.data.gov.uk/dataset/5b632bd7-9838-4ef2-9101-ea9384421b0d/sites-of-special-scientific-interest-england"></a> https://www.data.gov.uk/dataset/5b632bd7-9838-4ef2-9101-ea9384421b0d/sites-of-special-scientific-interest-england</td>
20+
<td><a href="https://www.data.gov.uk/dataset/5b632bd7-9838-4ef2-9101-ea9384421b0d/sites-of-special-scientific-interest-england">https://www.data.gov.uk/dataset/5b632bd7-9838-4ef2-9101-ea9384421b0d/sites-of-special-scientific-interest-england</a></td>
2121
</tr>
2222
<tr>
2323
<td>Geography</td>
@@ -29,7 +29,7 @@
2929
</tr>
3030
<tr>
3131
<td>Temporal coverage</td>
32-
<td>2024-07-29</td>
32+
<td>2024-07-23</td>
3333
</tr>
3434
<tr>
3535
<td>Update frequency</td>
@@ -53,7 +53,7 @@
5353
</tr>
5454
<tr>
5555
<td>Last updated</td>
56-
<td>2024-08-14</td>
56+
<td>2024-08-15</td>
5757
</tr>
5858
<tr>
5959
<td>Notes</td>

sites_of_special_scientific_interest/pre-processing.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ api_geommetry_envelope <- "&geometryType=esriGeometryEnvelope&geometry=%7B%22spa
3838

3939
# Local authority district -------------------------
4040
# Source: ONS Open Geography Portal
41-
# URL: https://geoportal.statistics.gov.uk/datasets/ons::local-authority-districts-may-2023-boundaries-uk-bgc/about
41+
# URL: https://geoportal.statistics.gov.uk/datasets/ons::local-authority-districts-may-2023-boundaries-uk-bfc/about
4242
# Licence: OGL v3.0
4343
# NOTE: we need the LA boundary stored as an sf object for use in st_intersection() calculations for other boundaries/features
44-
la <- st_read("https://services1.arcgis.com/ESMARspQHYMw9BZ9/arcgis/rest/services/Local_Authority_Districts_May_2023_UK_BGC_V2/FeatureServer/0/query?outFields=*&where=UPPER(lad23cd)%20like%20%27%25E08000009%25%27&f=geojson") %>%
45-
select(area_code = LAD23CD, area_name = LAD23NM)
44+
# we use the full resolution version as this ensures any features near the border are included/not included correctly
45+
la <- st_read("https://services1.arcgis.com/ESMARspQHYMw9BZ9/arcgis/rest/services/Local_Authority_Districts_May_2023_UK_BFC_V2/FeatureServer/0/query?outFields=*&where=UPPER(lad23cd)%20like%20%27%25E08000009%25%27&f=geojson") %>%
46+
select(area_code = LAD23CD, area_name = LAD23NM)
4647

4748

4849
# Get the SSSI information for areas within Trafford -------------------------

0 commit comments

Comments
 (0)