Skip to content

Commit 4e975da

Browse files
committed
Updated the flood risk dataset and method of creation following the release of the new RoFRS dataset by the Environment Agency on 2025-01-28.
1 parent 999f71e commit 4e975da

7 files changed

Lines changed: 2522 additions & 5641 deletions

flood_risk/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<table>
22
<tr>
33
<td>Dataset name</td>
4-
<td>Risk of Flooding from Rivers and Sea</td>
4+
<td>Risk of Flooding from Rivers and Sea (RoFRS)</td>
55
</tr>
66
<tr>
77
<td>Dataset description</td>
8-
<td>The dataset, taken from the national assessment of flood risk for England produced using local expertise, shows the chance of flooding from rivers and/or the sea, based on cells of 50m within Trafford. Each cell is allocated one of four flood risk categories, taking into account flood defences and their condition.
9-
</td>
8+
<td>Flood risk in Trafford. Taken from the <a href="https://environment.data.gov.uk/dataset/96ab4342-82c1-4095-87f1-0082e8d84ef1">Risk of Flooding from Rivers and Sea</a> (RoFRS) dataset, showing the chance of flooding taking into account the presence and condition of flood defences, represented on a 2m resolution grid. RoFRS is a probabilistic product, meaning that it shows the overall risk, rather than the risk associated with a specific event or scenario. This risk is displayed as one of four likelihood bandings.<br /><br />Please refer to the <a href="https://environment.data.gov.uk/api/file/download?fileDataSetId=cf7e9513-2004-4ab7-befa-12294eedde0f&fileName=RoFRS%20Product%20Description.pdf">RoFRS Product Description PDF</a> for more information.</td>
109
</tr>
1110
<tr>
1211
<td>Source</td>
@@ -18,7 +17,7 @@
1817
</tr>
1918
<tr>
2019
<td>Publisher URL</td>
21-
<td><a href="https://www.data.gov.uk/dataset/bad20199-6d39-4aad-8564-26a46778fd94/risk-of-flooding-from-rivers-and-sea">https://www.data.gov.uk/dataset/bad20199-6d39-4aad-8564-26a46778fd94/risk-of-flooding-from-rivers-and-sea</a></td>
20+
<td><a href="https://environment.data.gov.uk/dataset/96ab4342-82c1-4095-87f1-0082e8d84ef1">https://environment.data.gov.uk/dataset/96ab4342-82c1-4095-87f1-0082e8d84ef1</a></td>
2221
</tr>
2322
<tr>
2423
<td>Geography</td>
@@ -30,19 +29,19 @@
3029
</tr>
3130
<tr>
3231
<td>Temporal coverage</td>
33-
<td>2018-03-28 - 2019-12-18</td>
32+
<td>2024-10-30</td>
3433
</tr>
3534
<tr>
3635
<td>Update frequency</td>
37-
<td>Unknown</td>
36+
<td>Quarterly</td>
3837
</tr>
3938
<tr>
4039
<td>Licence</td>
4140
<td><a href="http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/">Open Government Licence</a></td>
4241
</tr>
4342
<tr>
4443
<td>Attribution</td>
45-
<td>© Environment Agency copyright and/or database right 2023. All rights reserved.</td>
44+
<td>© Environment Agency copyright and/or database right 2025. All rights reserved.</td>
4645
</tr>
4746
<tr>
4847
<td>Format</td>
@@ -54,7 +53,7 @@
5453
</tr>
5554
<tr>
5655
<td>Last updated</td>
57-
<td>2024-02-09</td>
56+
<td>2025-01-28</td>
5857
</tr>
5958
<tr>
6059
<td>Notes</td>

flood_risk/Risk_of_Flooding_from_Rivers_and_Sea.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

flood_risk/pre-processing.R

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,65 @@
11
## Risk of Flooding from Rivers and Sea ##
22

33
# Source: Environment Agency
4-
# Publisher URL: https://www.data.gov.uk/dataset/bad20199-6d39-4aad-8564-26a46778fd94/risk-of-flooding-from-rivers-and-sea
4+
# Publisher URL: https://environment.data.gov.uk/dataset/96ab4342-82c1-4095-87f1-0082e8d84ef1
5+
# NOTE: previous dataset now retired: https://www.data.gov.uk/dataset/bad20199-6d39-4aad-8564-26a46778fd94/risk-of-flooding-from-rivers-and-sea
56
# 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.
7+
# Attribution: (C) Environment Agency copyright and/or database right 2025. All rights reserved.
8+
# Last Updated: 2025-01-28
9+
# Update frequency: Quarterly
10+
# The dataset is downloaded from https://environment.data.gov.uk/explore/96ab4342-82c1-4095-87f1-0082e8d84ef1?download=true by uploading a bounding polygon around Trafford. This file is large ~40MB.
11+
1012

1113
# Load libraries ---------------------------
1214
library(tidyverse) ; library(sf)
1315

1416

15-
# Set sf geometry calculation method ---------------------------
17+
# Set sf geometry calculation method if required ---------------------------
1618
# 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+
# Uncomment and run the following 2 lines if you encounter issues working with the spatial files
20+
#is_sf_using_s2 <- sf_use_s2() # Store whether sf is using S2 or R2 geometry calculations
21+
#sf_use_s2(FALSE) # Set sf to use R2 calculations as we get errors using S2
22+
23+
24+
# Convert the boundary of Trafford and its immediate environs (created in Plotter) from GeoJSON into a ShapeFile ---------------------------
25+
read_sf("trafford_and_environs_boundary.geojson") %>%
26+
# This creates 4 files with the extensions .dbf, .prj, .shp and .shx
27+
write_sf("trafford_and_environs_boundary.shp", driver = "ESRI Shapefile")
28+
29+
# The above process creates 4 files which we need to ZIP up, create a list with their names so that we can reuse it in the following 2 lines below
30+
shp_files <- c("trafford_and_environs_boundary.dbf", "trafford_and_environs_boundary.prj", "trafford_and_environs_boundary.shp", "trafford_and_environs_boundary.shx")
1931

32+
# Add them to a ZIP ready to upload
33+
zip(zipfile = "trafford_and_environs_boundary", files = shp_files)
2034

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.
35+
# Remove the 4 individual files as they are no longer needed
36+
file.remove(shp_files)
2437

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)
2938

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)
39+
# Manually download the flood risk data from the Environment Agency ---------------------------
40+
# 1. Visit https://environment.data.gov.uk/explore/96ab4342-82c1-4095-87f1-0082e8d84ef1?download=true
41+
# 2. Change the "Area of interest" drop-down to "Upload sharefile"
42+
# 3. Use the "Browse..." button to select the "trafford_and_environs_boundary.zip" file created above
43+
# 4. Change the "Layers" drop-down to "rofs_4band" (NOTE: data is also available for risk of flooding to a depth of 0.2m, 0.3m, 0.6m, 0.9m and 1.2m)
44+
# 5. Change the "File format" drow-down to "GeoJSON"
45+
# 6. Select the "Download file" button
46+
# 7. Copy the downloaded file "rofs_4band.json" from your "Downloads" folder to the "flood_risk" folder containing this script
47+
48+
49+
# Load raw flood risk data and tidy up the variables ---------------------------
50+
trafford_flood_risk <- read_sf("rofrs_4band.json") %>%
51+
rename(flood_risk = risk_band) %>%
52+
filter(st_geometry_type(geometry) != "POINT") %>% # Just in case there is any point data, remove it as this will show up as a marker pin on the map which will be confusing. The previous version of this dataset had 6 within Trafford.
53+
select(object_id = objectid, flood_risk, geometry)
3754

3855

3956
# write data ---------------------------
40-
st_write(trafford_flood_risk, "trafford_flood_risk.geojson", driver = "GeoJSON")
57+
file.remove("trafford_flood_risk.geojson") # first remove the previous file
58+
write_sf(trafford_flood_risk, "trafford_flood_risk.geojson", driver = "GeoJSON")
59+
60+
61+
# Clean up the filesystem removing the downloaded flood risk JSON file and the shapefile ZIP ---------------------------
62+
file.remove(c("rofrs_4band.json", "trafford_and_environs_boundary.zip"))
4163

42-
sf_use_s2(is_sf_using_s2) # Reset whether sf is using S2 or R2 geometry calculations
64+
# reset R's spherical geometry if required ---------------------------
65+
#sf_use_s2(is_sf_using_s2) # Reset whether sf is using S2 or R2 geometry calculations

flood_risk/styling.R

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44
library(tidyverse); library(sf)
55

66
# read un-styled, cleaned data ---------------------------
7-
geojson <- st_read("trafford_flood_risk.geojson")
7+
trafford_flood_risk <- read_sf("trafford_flood_risk.geojson")
88

99
# apply styles ---------------------------
10-
geojson_styles <- geojson %>%
11-
mutate(stroke =
12-
case_when(
13-
flood_risk == "Very Low" ~ "#bdd7e7",
14-
flood_risk == "Low" ~ "#6baed6",
15-
flood_risk == "Medium" ~ "#2171b5",
16-
flood_risk == "High" ~ "#3E4388"),
17-
`stroke-width` = 3,
18-
`stroke-opacity` = 1,
19-
fill = stroke,
20-
`fill-opacity` = 0.8)
10+
trafford_flood_risk_styled <- trafford_flood_risk %>%
11+
mutate(stroke = case_when(
12+
flood_risk == "Very low" ~ "#C4E1FF",
13+
flood_risk == "Low" ~ "#A2CFFF",
14+
flood_risk == "Medium" ~ "#6699CD",
15+
flood_risk == "High" ~ "#3D4489",
16+
TRUE ~ "#ff0000"), # To visually indicate that something has gone wrong),
17+
`stroke-width` = 3,
18+
`stroke-opacity` = 1,
19+
fill = stroke,
20+
`fill-opacity` = 0.8)
2121

22-
# write data ---------------------------
23-
st_write(geojson_styles, "trafford_flood_risk_styled.geojson")
22+
# delete the old and then create the new data ---------------------------
23+
file.remove("trafford_flood_risk_styled.geojson")
24+
write_sf(trafford_flood_risk_styled, "trafford_flood_risk_styled.geojson")
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {
7+
"featureNum": 1,
8+
"featureAlias": "Trafford and environs"
9+
},
10+
"geometry": {
11+
"type": "Polygon",
12+
"coordinates": [
13+
[
14+
[
15+
-2.325067,
16+
53.48271
17+
],
18+
[
19+
-2.314496,
20+
53.481599
21+
],
22+
[
23+
-2.308722,
24+
53.479959
25+
],
26+
[
27+
-2.285093,
28+
53.475622
29+
],
30+
[
31+
-2.279141,
32+
53.468638
33+
],
34+
[
35+
-2.271146,
36+
53.474659
37+
],
38+
[
39+
-2.264128,
40+
53.476511
41+
],
42+
[
43+
-2.256844,
44+
53.473284
45+
],
46+
[
47+
-2.246895,
48+
53.46286
49+
],
50+
[
51+
-2.248138,
52+
53.456682
53+
],
54+
[
55+
-2.262885,
56+
53.447472
57+
],
58+
[
59+
-2.277986,
60+
53.444666
61+
],
62+
[
63+
-2.283849,
64+
53.437042
65+
],
66+
[
67+
-2.269814,
68+
53.428
69+
],
70+
[
71+
-2.260753,
72+
53.422333
73+
],
74+
[
75+
-2.26706,
76+
53.412268
77+
],
78+
[
79+
-2.283849,
80+
53.408841
81+
],
82+
[
83+
-2.30357,
84+
53.403331
85+
],
86+
[
87+
-2.285359,
88+
53.385628
89+
],
90+
[
91+
-2.277009,
92+
53.374665
93+
],
94+
[
95+
-2.281273,
96+
53.363316
97+
],
98+
[
99+
-2.292466,
100+
53.354844
101+
],
102+
[
103+
-2.314141,
104+
53.350387
105+
],
106+
[
107+
-2.350385,
108+
53.36052
109+
],
110+
[
111+
-2.373037,
112+
53.356915
113+
],
114+
[
115+
-2.41159,
116+
53.373198
117+
],
118+
[
119+
-2.450055,
120+
53.386064
121+
],
122+
[
123+
-2.479992,
124+
53.388291
125+
],
126+
[
127+
-2.495626,
128+
53.400269
129+
],
130+
[
131+
-2.479903,
132+
53.402371
133+
],
134+
[
135+
-2.45654,
136+
53.422079
137+
],
138+
[
139+
-2.428469,
140+
53.433254
141+
],
142+
[
143+
-2.414255,
144+
53.456848
145+
],
146+
[
147+
-2.388139,
148+
53.468532
149+
],
150+
[
151+
-2.357403,
152+
53.477837
153+
],
154+
[
155+
-2.325067,
156+
53.48271
157+
]
158+
]
159+
]
160+
}
161+
}
162+
]
163+
}

0 commit comments

Comments
 (0)