|
| 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") |
0 commit comments