|
1 | 1 | ## Risk of Flooding from Rivers and Sea ## |
2 | 2 |
|
3 | 3 | # Source: Environment Agency |
4 | | -# Publisher URL: https://data.gov.uk/dataset/risk-of-flooding-from-rivers-and-sea1 |
| 4 | +# Publisher URL: https://www.data.gov.uk/dataset/bad20199-6d39-4aad-8564-26a46778fd94/risk-of-flooding-from-rivers-and-sea |
5 | 5 | # Licence: Open Government Licence 3.0 |
| 6 | +# Attribution: (C) Environment Agency Copyright and/or Database Rights 2023. All rights reserved. |
| 7 | +# Last Updated: 2024-02-09 |
| 8 | +# NOTE 1: "This year we are pausing the updates to this dataset after December 2023. This is in advance of publishing the first outputs from our new National Flood Risk Assessment. These outputs will be published by the end of 2024 and will include a new version of this dataset." |
| 9 | +# NOTE 2: The initial dataset is downloaded from https://environment.data.gov.uk/explore/8d57464f-d465-11e4-8790-f0def148f590 by creating a bounding polygon around Trafford. This file is large ~14MB. |
6 | 10 |
|
7 | | -# load libraries--------------------------- |
| 11 | +# Load libraries --------------------------- |
8 | 12 | library(tidyverse) ; library(sf) |
9 | 13 |
|
10 | | -# load data --------------------------- |
11 | | -flood <- st_read("flood_risk_radius.geojson") # processed in QGIS beforehand |
12 | 14 |
|
13 | | -trafford <- st_read("https://github.com/traffordDataLab/spatial_data/raw/master/local_authority/2016/trafford_local_authority_full_resolution.geojson") %>% |
14 | | - st_set_crs(4326) %>% |
15 | | - select(-lat, -lon) |
| 15 | +# Set sf geometry calculation method --------------------------- |
| 16 | +# Refer to the following for further information: https://github.com/r-spatial/sf/issues/1771 |
| 17 | +is_sf_using_s2 <- sf_use_s2() # Store whether sf is using S2 or R2 geometry calculations |
| 18 | +sf_use_s2(FALSE) # Set sf to use R2 calculations as we get errors using S2 |
| 19 | + |
| 20 | + |
| 21 | +# Load raw data and Trafford's boundary --------------------------- |
| 22 | +flood_risk_raw <- st_read("Risk_of_Flooding_from_Rivers_and_Sea.json") %>% # Downloaded file mentioned in NOTE 2 |
| 23 | + st_make_valid() # The geometry returned in the data downloaded above needs correcting as there are overlapping vertices/self-intersections etc. |
| 24 | + |
| 25 | +# Load boundary of Trafford --------------------------- |
| 26 | +trafford <- st_read("https://www.trafforddatalab.io/spatial_data/local_authority/2021/trafford_local_authority_full_resolution.geojson") %>% |
| 27 | + st_set_crs(4326) %>% |
| 28 | + select(-lat, -lon) |
| 29 | + |
| 30 | +# Intersect data, leaving just flood risk data within Trafford's boundary and tidy up variables --------------------------- |
| 31 | +trafford_flood_risk <- st_intersection(flood_risk_raw, trafford) %>% |
| 32 | + rename(flood_risk = prob_4band, |
| 33 | + suitable_scale = suitability) %>% |
| 34 | + mutate(publication_date = as.character(as.POSIXct(pub_date, tz="UTC"))) %>% |
| 35 | + filter(st_geometry_type(geometry) != "POINT") %>% # Remove any point data as this will show up as a marker pin on the map which will be confusing. There seem to be 6 within the dataset. |
| 36 | + select(flood_risk, suitable_scale, publication_date, RoFRS_id = id) |
16 | 37 |
|
17 | | -# intersect data --------------------------- |
18 | | -trafford_flood <- st_intersection(flood, trafford) |
19 | 38 |
|
20 | 39 | # write data --------------------------- |
21 | | -st_write(trafford_flood, "trafford_flood_risk.geojson", driver = "GeoJSON") |
| 40 | +st_write(trafford_flood_risk, "trafford_flood_risk.geojson", driver = "GeoJSON") |
| 41 | + |
| 42 | +sf_use_s2(is_sf_using_s2) # Reset whether sf is using S2 or R2 geometry calculations |
0 commit comments