-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_data.R
53 lines (44 loc) · 1.46 KB
/
get_data.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
library(weathercan)
library(dplyr)
library(stringr)
library(sf)
library(janitor)
library(rnaturalearth)
# Get protected areas
# f <- "CPCAD-BDCAPC_Dec2019.gdb.zip"
# ff <- str_remove(f, ".zip")
# if(!dir.exists(ff)){
# download.file(file.path("https://cws-scf.ca", f), destfile = f)
# unzip(f)
# unlink(f)
# }
# Filter Protected areas to MB
# st_layers(ff)
# pa <- st_read(ff, layer = "CPCAD_Dec2019") %>%
# clean_names() %>%
# filter(str_detect(loc_e, "Arctic|Manitoba"))
#
# mb_pa <- ne_states(country = "Canada", returnclass = "sf") %>%
# filter(name_en == "Manitoba") %>%
# st_transform(crs = st_crs(pa)) %>%
# st_join(pa, ., left = FALSE)
# Get climate data
if(!file.exists("mb_2020.rds")){
s <- filter(stations, prov == "MB", start <= 2020, end >= 2020, interval == "day")
mb <- weather_dl(s$station_id, start = "2020-01-01", end = "2020-12-31", interval = "day")
saveRDS(mb, "mb_2020.rds")
}
# Get Eco regions
if(!file.exists("env_ecological_areas.shp")) {
download.file(file.path("http://mli2.gov.mb.ca/environment/shp_zip_files",
"env_ecological_areas_py_shp.zip"),
destfile = "ecological_shp.zip")
unzip("ecological_shp.zip")
file.remove("ecological_shp.zip")
}
region <- st_read("env_ecological_areas.shp") %>%
clean_names() %>%
filter(manitoba == "yes") %>%
select(region_nam, region_nom, prov_name, prov_nom, zone_name, zone_nom) %>%
st_transform(crs = 3347)
saveRDS(region, "mb_regions.rds")