Skip to content

Commit acad939

Browse files
committed
Amended to use the flood risk data at certain depths as well as the overall risk data. Styling amended to include the Unavailable option.
1 parent e69a7ee commit acad939

12 files changed

Lines changed: 4324 additions & 22 deletions

flood_risk/pre-processing.R

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,46 @@ file.remove(shp_files)
4444
# 5. Change the "File format" drow-down to "GeoJSON"
4545
# 6. Select the "Download file" button
4646
# 7. Copy the downloaded file "rofs_4band.json" from your "Downloads" folder to the "flood_risk" folder containing this script
47+
# 8. Repeat steps 4 - 7 for each of the other flood risk layers based on depths from 0.2m - 1.2m
4748

4849

49-
# Load raw flood risk data and tidy up the variables ---------------------------
50-
trafford_flood_risk <- read_sf("rofrs_4band.json") %>%
50+
# Function to load raw flood risk data and tidy up the variables ---------------------------
51+
get_flood_risk <- function(raw_data_filename) {
52+
read_sf(raw_data_filename) %>%
5153
rename(flood_risk = risk_band) %>%
5254
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.
5355
select(object_id = objectid, flood_risk, geometry)
54-
55-
56-
# write data ---------------------------
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"))
63-
64-
# reset R's spherical geometry if required ---------------------------
56+
}
57+
58+
59+
# Write data ---------------------------
60+
# First remove the previous files
61+
file.remove(c("trafford_flood_risk.geojson",
62+
"trafford_flood_risk_0_2m_depth.geojson",
63+
"trafford_flood_risk_0_3m_depth.geojson",
64+
"trafford_flood_risk_0_6m_depth.geojson",
65+
"trafford_flood_risk_0_9m_depth.geojson",
66+
"trafford_flood_risk_1_2m_depth.geojson"))
67+
68+
# Now create the files again based on the new data
69+
write_sf(get_flood_risk("rofrs_4band.json"), "trafford_flood_risk.geojson", driver = "GeoJSON")
70+
write_sf(get_flood_risk("rofrs_4band_0_2m_depth.json"), "trafford_flood_risk_0_2m_depth.geojson", driver = "GeoJSON")
71+
write_sf(get_flood_risk("rofrs_4band_0_3m_depth.json"), "trafford_flood_risk_0_3m_depth.geojson", driver = "GeoJSON")
72+
write_sf(get_flood_risk("rofrs_4band_0_6m_depth.json"), "trafford_flood_risk_0_6m_depth.geojson", driver = "GeoJSON")
73+
write_sf(get_flood_risk("rofrs_4band_0_9m_depth.json"), "trafford_flood_risk_0_9m_depth.geojson", driver = "GeoJSON")
74+
write_sf(get_flood_risk("rofrs_4band_1_2m_depth.json"), "trafford_flood_risk_1_2m_depth.geojson", driver = "GeoJSON")
75+
76+
77+
# Clean up the filesystem ---------------------------
78+
# Removing the downloaded flood risk JSON files and the shapefile ZIP
79+
file.remove(c("rofrs_4band.json",
80+
"rofrs_4band_0_2m_depth.json",
81+
"rofrs_4band_0_3m_depth.json",
82+
"rofrs_4band_0_6m_depth.json",
83+
"rofrs_4band_0_9m_depth.json",
84+
"rofrs_4band_1_2m_depth.json",
85+
"trafford_and_environs_boundary.zip"))
86+
87+
88+
# Reset R's spherical geometry if required ---------------------------
6589
#sf_use_s2(is_sf_using_s2) # Reset whether sf is using S2 or R2 geometry calculations

flood_risk/styling.R

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
11
## Styling flood risk features ##
22

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

6-
# read un-styled, cleaned data ---------------------------
7-
trafford_flood_risk <- read_sf("trafford_flood_risk.geojson")
86

9-
# apply styles ---------------------------
10-
trafford_flood_risk_styled <- trafford_flood_risk %>%
7+
# Remove the previous files ---------------------------
8+
file.remove(c("trafford_flood_risk_styled.geojson",
9+
"trafford_flood_risk_0_2m_depth_styled.geojson",
10+
"trafford_flood_risk_0_3m_depth_styled.geojson",
11+
"trafford_flood_risk_0_6m_depth_styled.geojson",
12+
"trafford_flood_risk_0_9m_depth_styled.geojson",
13+
"trafford_flood_risk_1_2m_depth_styled.geojson"))
14+
15+
16+
# Function to apply styles ---------------------------
17+
style_flood_risk <- function(unstyled_data_filename) {
18+
read_sf(unstyled_data_filename) %>%
1119
mutate(stroke = case_when(
1220
flood_risk == "Very low" ~ "#C4E1FF",
1321
flood_risk == "Low" ~ "#A2CFFF",
1422
flood_risk == "Medium" ~ "#6699CD",
1523
flood_risk == "High" ~ "#3D4489",
16-
TRUE ~ "#ff0000"), # To visually indicate that something has gone wrong),
24+
TRUE ~ "#b1b3b4"), # Likely "Unavailable"
1725
`stroke-width` = 3,
1826
`stroke-opacity` = 1,
1927
fill = stroke,
2028
`fill-opacity` = 0.8)
29+
}
30+
2131

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")
32+
# Create the new styled data ---------------------------
33+
write_sf(style_flood_risk("trafford_flood_risk.geojson"), "trafford_flood_risk_styled.geojson", driver = "GeoJSON")
34+
write_sf(style_flood_risk("trafford_flood_risk_0_2m_depth.geojson"), "trafford_flood_risk_0_2m_depth_styled.geojson", driver = "GeoJSON")
35+
write_sf(style_flood_risk("trafford_flood_risk_0_3m_depth.geojson"), "trafford_flood_risk_0_3m_depth_styled.geojson", driver = "GeoJSON")
36+
write_sf(style_flood_risk("trafford_flood_risk_0_6m_depth.geojson"), "trafford_flood_risk_0_6m_depth_styled.geojson", driver = "GeoJSON")
37+
write_sf(style_flood_risk("trafford_flood_risk_0_9m_depth.geojson"), "trafford_flood_risk_0_9m_depth_styled.geojson", driver = "GeoJSON")
38+
write_sf(style_flood_risk("trafford_flood_risk_1_2m_depth.geojson"), "trafford_flood_risk_1_2m_depth_styled.geojson", driver = "GeoJSON")

flood_risk/trafford_flood_risk_0_2m_depth.geojson

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

flood_risk/trafford_flood_risk_0_2m_depth_styled.geojson

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

flood_risk/trafford_flood_risk_0_3m_depth.geojson

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

flood_risk/trafford_flood_risk_0_3m_depth_styled.geojson

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

flood_risk/trafford_flood_risk_0_6m_depth.geojson

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

flood_risk/trafford_flood_risk_0_6m_depth_styled.geojson

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

0 commit comments

Comments
 (0)