-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatershed_analysis.R
83 lines (71 loc) · 3.94 KB
/
watershed_analysis.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
tar_load(c(og_watershed, prot_watershed, priority_og_watershed, priority_prot_watershed, watershed_data))
og_watershed_sum <-og_watershed %>%
mutate(og_watershed_area = st_area(.),
og_watershed_area =as.numeric(set_units(og_watershed_area, ha))) %>%
st_set_geometry(NULL) %>%
group_by(cw_name, cw_source_name, cw_source_type, source_category,
source_comments, water_treatment_type, water_treatment_location) %>%
summarise(og_watershed_area = sum(og_watershed_area)) %>%
ungroup()
og_prot_watershed_sum <- prot_watershed %>%
mutate(prot_og_watershed_area = st_area(.),
prot_og_watershed_area =as.numeric(set_units(prot_og_watershed_area, ha))) %>%
st_set_geometry(NULL) %>%
group_by(cw_name, cw_source_name, cw_source_type, source_category,
source_comments, water_treatment_type, water_treatment_location) %>%
summarise(prot_og_watershed_area = sum(prot_og_watershed_area)) %>%
ungroup()
priority_og_watershed_sum <-priority_og_watershed %>%
mutate(og_watershed_area = st_area(.),
og_watershed_area =as.numeric(set_units(og_watershed_area, ha))) %>%
st_set_geometry(NULL) %>%
group_by(cw_name, cw_source_name, cw_source_type, source_category,
source_comments, water_treatment_type, water_treatment_location) %>%
summarise(priority_og_watershed_area = sum(og_watershed_area)) %>%
ungroup()
priority_og_prot_watershed_sum <- priority_prot_watershed %>%
mutate(prot_og_watershed_area = st_area(.),
prot_og_watershed_area =as.numeric(set_units(prot_og_watershed_area, ha))) %>%
st_set_geometry(NULL) %>%
group_by(cw_name, cw_source_name, cw_source_type, source_category,
source_comments, water_treatment_type, water_treatment_location) %>%
summarise(priority_prot_og_watershed_area = sum(prot_og_watershed_area)) %>%
ungroup()
output <- watershed_data %>%
mutate(watershed_area = st_area(.),
watershed_area=as.numeric(set_units(watershed_area, ha))) %>%
st_set_geometry(NULL) %>%
left_join(og_watershed_sum) %>%
left_join(og_prot_watershed_sum) %>%
left_join(priority_og_watershed_sum) %>%
left_join(priority_og_prot_watershed_sum) %>%
mutate_if(is.numeric, ~replace(., is.na(.),0)) %>%
mutate(og_percentage = round(og_watershed_area/watershed_area * 100, digits=2),
prot_percentage = round(prot_og_watershed_area/og_watershed_area * 100, digits=2),
unprot_area = og_watershed_area-prot_og_watershed_area,
perc_unprot_area = round(unprot_area/og_watershed_area * 100, digits=2),
#
priority_og_percentage = round(priority_og_watershed_area/watershed_area * 100, digits=2),
priority_prot_percentage = round(priority_prot_og_watershed_area/priority_og_watershed_area * 100, digits=2),
priority_unprot_area = priority_og_watershed_area -priority_prot_og_watershed_area,
priority_perc_unprot = round(priority_unprot_area/priority_og_watershed_area * 100, digits=2),
#
perc_unprot_priority = priority_unprot_area/unprot_area*100
)
output_og <- output %>%
filter(og_watershed_area > 0)
output_priority_og <- output %>%
filter(priority_og_watershed_area > 0)
write.csv(output_og, "out/og-community-watersheds_Nov2.csv")
og_watershed_summary <-output_og %>%
summarise(og_watershed_area = sum(og_watershed_area),
unprot_area = sum(unprot_area),
watershed_area = sum(watershed_area),
#
priority_og_watershed_area = sum(priority_og_watershed_area),
priority_unprot_area = sum(priority_unprot_area)) %>%
mutate(overall_og_perc = round(og_watershed_area/watershed_area * 100, digits=2),
priority_og_perc = priority_og_watershed_area/watershed_area*100,
perc_unprot = unprot_area/og_watershed_area*100,
perc_unprot_priority = priority_unprot_area/unprot_area*100
)