Skip to content

Commit 7951994

Browse files
committed
Programmatically fetching the data from Ordnance Survey so that the script is now reproducible, and have added another dataset for the watercourses within 10km of the Trafford boundary.
1 parent 837452f commit 7951994

9 files changed

Lines changed: 4172 additions & 2053 deletions

watercourses/README.md

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
1-
[<img src="thumbnail.png">](trafford_watercourses_styled.geojson)
2-
</br>
3-
4-
<table>
5-
<tr>
6-
<td>Dataset name</td>
7-
<td>OS Open Rivers</td>
8-
</tr>
9-
<tr>
10-
<td>Dataset description</td>
11-
<td>Rivers and other waterways constrained by the boundaries of Trafford borough and the Greater Manchester Combined Authority.</td>
12-
</tr>
13-
<tr>
14-
<td>Source</td>
15-
<td>Ordnance Survey</td>
16-
</tr>
17-
<tr>
18-
<td>Publisher</td>
19-
<td>Ordnance Survey</td>
20-
</tr>
21-
<tr>
22-
<td>Publisher URL</td>
23-
<td><a href="https://www.ordnancesurvey.co.uk/business-and-government/products/os-open-rivers.html"></a>https://www.ordnancesurvey.co.uk/business-and-government/products/os-open-rivers.html</td>
24-
</tr>
25-
<tr>
26-
<td>Geography</td>
27-
<td>Local authority</td>
28-
</tr>
29-
<tr>
30-
<td>Geographic coverage</td>
31-
<td>Trafford</td>
32-
</tr>
33-
<tr>
34-
<td>Temporal coverage</td>
35-
<td>December 2017</td>
36-
</tr>
37-
<tr>
38-
<td>Update frequency</td>
39-
<td>Unknown</td>
40-
</tr>
41-
<tr>
42-
<td>Licence</td>
43-
<td><a href="http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/">Open Government Licence</a></td>
44-
</tr>
45-
<tr>
46-
<td>Attribution</td>
47-
<td>Contains Ordnance Survey data © Crown copyright and database right 2018</td>
48-
</tr>
49-
<tr>
50-
<td>Format</td>
51-
<td>GeoJSON</td>
52-
</tr>
53-
<tr>
54-
<td>Openness rating</td>
55-
<td>&#9733&#9733&#9733&#9734&#9734&nbsp; Structured data in open format (e.g. CSV)</td>
56-
</tr>
57-
<tr>
58-
<td>Last updated</td>
59-
<td>March 2018</td>
60-
</tr>
61-
<tr>
62-
<td>Notes</td>
63-
<td></td>
64-
</tr>
65-
<tr>
66-
<td>Lab visualisation</td>
67-
<td>View data within the Lab's <a href="https://www.trafforddatalab.io/maps/explore/index.html?dataset=watercourses">Explore application</a>.</td>
68-
</tr>
69-
</table>
1+
[<img src="thumbnail.png">](trafford_watercourses_styled.geojson)
2+
</br>
3+
4+
<table>
5+
<tr>
6+
<td>Dataset name</td>
7+
<td>OS Open Rivers</td>
8+
</tr>
9+
<tr>
10+
<td>Dataset description</td>
11+
<td>Rivers and other waterways constrained by the boundaries of Trafford borough and the Greater Manchester Combined Authority, and within a 10km buffer of Trafford.</td>
12+
</tr>
13+
<tr>
14+
<td>Source</td>
15+
<td>Ordnance Survey</td>
16+
</tr>
17+
<tr>
18+
<td>Publisher</td>
19+
<td>Ordnance Survey</td>
20+
</tr>
21+
<tr>
22+
<td>Publisher URL</td>
23+
<td><a href="https://www.ordnancesurvey.co.uk/products/os-open-rivers">https://www.ordnancesurvey.co.uk/products/os-open-rivers</a></td>
24+
</tr>
25+
<tr>
26+
<td>Geography</td>
27+
<td>Local authority</td>
28+
</tr>
29+
<tr>
30+
<td>Geographic coverage</td>
31+
<td>Trafford, Trafford plus 10km buffer and Greater Manchester</td>
32+
</tr>
33+
<tr>
34+
<td>Temporal coverage</td>
35+
<td>October 2024</td>
36+
</tr>
37+
<tr>
38+
<td>Update frequency</td>
39+
<td>Unknown</td>
40+
</tr>
41+
<tr>
42+
<td>Licence</td>
43+
<td><a href="http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/">Open Government Licence</a></td>
44+
</tr>
45+
<tr>
46+
<td>Attribution</td>
47+
<td>Contains Ordnance Survey data © Crown copyright and database right 2025</td>
48+
</tr>
49+
<tr>
50+
<td>Format</td>
51+
<td>GeoJSON</td>
52+
</tr>
53+
<tr>
54+
<td>Openness rating</td>
55+
<td>&#9733&#9733&#9733&#9734&#9734&nbsp; Structured data in open format (e.g. CSV)</td>
56+
</tr>
57+
<tr>
58+
<td>Last updated</td>
59+
<td>2025-02-21</td>
60+
</tr>
61+
<tr>
62+
<td>Notes</td>
63+
<td></td>
64+
</tr>
65+
<tr>
66+
<td>Lab visualisation</td>
67+
<td>View data within the Lab's <a href="https://www.trafforddatalab.io/explore/index.html?dataset=watercourses">Explore application</a>.</td>
68+
</tr>
69+
</table>

watercourses/gm_watercourses.geojson

Lines changed: 1306 additions & 1777 deletions
Large diffs are not rendered by default.

watercourses/gm_watercourses_styled.geojson

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

watercourses/pre-processing.R

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
## OS Open Rivers ##
2+
3+
# Source: Ordnance Survey
4+
# Publisher URL: https://www.ordnancesurvey.co.uk/products/os-open-rivers
5+
# https://osdatahub.os.uk/downloads/open/OpenRivers
6+
# Licence: Open Government Licence 3.0
7+
# Attribution: (C) Crown copyright and database rights. Ordnance Survey 2025
8+
# Last Updated: 2025-02-21
9+
10+
11+
# Load libraries ---------------------------
12+
library(tidyverse) ; library(sf)
13+
14+
15+
# Load the boundaries of Trafford and GM ---------------------------
16+
trafford <- read_sf("http://trafforddatalab.io/spatial_data/local_authority/2021/trafford_local_authority_full_resolution.geojson")
17+
gm <- read_sf("http://trafforddatalab.io/spatial_data/combined_authority/2017/GM_combined_authority_full_resolution.geojson")
18+
19+
# Create a boundary of Trafford with a 10km buffer around it
20+
trafford_with_buffer <- trafford %>%
21+
st_buffer(10000)
22+
23+
24+
# Download the Watercourses dataset for the whole of GB from Ordnance Survey ---------------------------
25+
data_files <- c("data/WatercourseLink.dbf", "data/WatercourseLink.prj", "data/WatercourseLink.shp", "data/WatercourseLink.shx") # These are the Shapefiles we're interested in from the download
26+
download.file("https://api.os.uk/downloads/v1/products/OpenRivers/downloads?area=GB&format=ESRI%C2%AE+Shapefile&redirect", dest = "oprvrs_essh_gb.zip")
27+
unzip("oprvrs_essh_gb.zip", files = data_files) # just un-zip the files we want, leave the rest
28+
29+
30+
# Load in the GB Watercourses dataset shapefile and tidy the data ---------------------------
31+
watercourses_gb <- read_sf("data/WatercourseLink.shp") %>%
32+
st_transform(crs = 4326)
33+
34+
watercourses_gb_tidy <- watercourses_gb %>%
35+
rename(id = identifier,
36+
start_node_id = startNode,
37+
end_node_id = endNode,
38+
length_in_metres = length,
39+
name = name1,
40+
alternative_name = name2) %>%
41+
mutate(form = case_when(form == "inlandRiver" ~ "inland river",
42+
form == "tidalRiver" ~ "tidal river",
43+
TRUE ~ form),
44+
form_description = case_when(form == "canal" ~ "A human-made watercourse originally created for inland navigation.",
45+
form == "inland river" ~ "A river or stream that is not influenced by normal tidal action.",
46+
form == "lake" ~ "A large area of non-tidal water without an obvious flow that is enclosed by land.",
47+
form == "tidal river" ~ "Tidal river or stream (that is, below Normal Tidal Limit).",
48+
TRUE ~ "")) %>%
49+
select(name, alternative_name, form, form_description, length_in_metres, id, start_node_id, end_node_id, geometry)
50+
51+
52+
# Crop the GB dataset to the different boundaries ---------------------------
53+
watercourses_trafford <- watercourses_gb_tidy %>%
54+
st_intersection(trafford) %>%
55+
select(-lat, -lon) # These are the centroid coordinates of Trafford - doesn't make sense to have them in this dataset
56+
57+
watercourses_trafford_buffer <- watercourses_gb_tidy %>%
58+
st_intersection(trafford_with_buffer) %>%
59+
select(-area_code, -area_name, -lat, -lon) # As this is a dataset cropped to Trafford plus a buffer it isn't correct to associate Trafford's area code and name when the link might be outside Trafford's boundary
60+
61+
watercourses_gm <- watercourses_gb_tidy %>%
62+
st_intersection(gm) %>%
63+
select(-lat, -lon) # These are the centroid coordinates of GM - doesn't make sense to have them in this dataset
64+
65+
66+
# Tidy up the filesystem, removing the downloaded files and previous cropped data ---------------------------
67+
file.remove(data_files,
68+
"data",
69+
"oprvrs_essh_gb.zip",
70+
"trafford_watercourses.geojson",
71+
"trafford_buffer_watercourses.geojson",
72+
"gm_watercourses.geojson")
73+
74+
75+
# Create the new cropped datasets ---------------------------
76+
write_sf(watercourses_trafford, "trafford_watercourses.geojson", driver = "GeoJSON")
77+
write_sf(watercourses_trafford_buffer, "trafford_buffer_watercourses.geojson", driver = "GeoJSON")
78+
write_sf(watercourses_gm, "gm_watercourses.geojson", driver = "GeoJSON")

watercourses/styling.R

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
## Styling features ##
1+
## Styling watercourses features ##
22

3-
# load packages ---------------------------
4-
library(tidyverse); library(sf) ; library(geojsonio)
3+
# Load packages ---------------------------
4+
library(tidyverse); library(sf)
55

6-
# read data ---------------------------
7-
geojson <- st_read("http://trafforddatalab.io/spatial_data/watercourses/trafford_watercourses.geojson")
86

9-
# apply styles ---------------------------
10-
geojson_styles <- geojson_style(geojson, var = 'identifier',
11-
stroke = "#40a4df",
12-
stroke_width = 3,
13-
stroke_opacity = 1,
14-
fill = "#40a4df",
15-
fill_opacity = 0.8) %>%
16-
rename(`stroke-width` = stroke.width,
17-
`stroke-opacity` = stroke.opacity,
18-
`fill-opacity` = fill.opacity)
7+
# Remove the previous files ---------------------------
8+
file.remove(c("trafford_watercourses_styled.geojson",
9+
"trafford_buffer_watercourses_styled.geojson",
10+
"gm_watercourses_styled.geojson"))
1911

20-
# write data ---------------------------
21-
st_write(geojson_styles, "trafford_watercourses_styled.geojson")
12+
13+
# Function to apply styles ---------------------------
14+
style_watercourses <- function(unstyled_data_filename) {
15+
read_sf(unstyled_data_filename) %>%
16+
mutate(stroke = "#40a4df",
17+
`stroke-width` = 3,
18+
`stroke-opacity` = 1,
19+
fill = stroke,
20+
`fill-opacity` = 0.8)
21+
}
22+
23+
24+
# Create the new styled data ---------------------------
25+
write_sf(style_watercourses("trafford_watercourses.geojson"), "trafford_watercourses_styled.geojson", driver = "GeoJSON")
26+
write_sf(style_watercourses("trafford_buffer_watercourses.geojson"), "trafford_buffer_watercourses_styled.geojson", driver = "GeoJSON")
27+
write_sf(style_watercourses("gm_watercourses.geojson"), "gm_watercourses_styled.geojson", driver = "GeoJSON")

0 commit comments

Comments
 (0)