-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWet_01_load_spatial.R
304 lines (246 loc) · 11.3 KB
/
Wet_01_load_spatial.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
## Demo 1.
# determine sampling points for a fish monitoring survey
source('header.R')
# bring in BC boundary
bc <- bcmaps::bc_bound()
ProvRast<-raster(nrows=15744, ncols=17216, xmn=159587.5, xmx=1881187.5,
ymn=173787.5, ymx=1748187.5,
res = c(100,100), vals = 1)
crs(ProvRast)<-crs(bc)
saveRDS(ProvRast,file='tmp/ProvRast')
ESI_file <- file.path("tmp/ESI")
if (!file.exists(ESI_file)) {
#Load ESI boundary
ESIin <- read_sf(file.path(ESIDir,'Data/Skeena_ESI_Boundary'), layer = "ESI_Skeena_Study_Area_Nov2017") %>%
st_transform(3005)
ESI <- st_cast(ESIin, "MULTIPOLYGON")
saveRDS(ESI, file = ESI_file)
#Load ESI supporting wetland data
#Wetlands with full attributes
WetW_gdb <-file.path(SyncDir,'Wetland/Tier 1/Assessment/Data/Skeena_ESI_T1_Wetland_200612.gdb')
wet_list <- st_layers(WetW_gdb)
Wetlands <- readOGR(dsn=WetW_gdb, layer = "Skeena_ESI_T1_Wetland_Update_200612") %>%
as('sf')
#Read in ESI_basic_Wetland_Complexes_190912 to link to plot data
WetlandRaw <- st_read(file.path(SyncDir,'Wetland/Wetland Features/Consolidated Wetland and Wetland Complexes Spatial/ESI_basic_Wetland_Complexes_190912.gpkg')) %>%
as('sf') %>%
mutate(Wetland_Co=Wetland_Complex_ID) %>%
dplyr::select(Wetland_Co, OBJECTID) %>%
st_drop_geometry()
Wetlands<-Wetlands %>%
left_join(WetlandRaw,by = 'Wetland_Co')
Wetlands <- Wetlands %>%
mutate(wet_id=as.numeric(rownames(Wetlands))) %>%
mutate(Wet_plotLink=OBJECTID)
st_crs(Wetlands)<-3005
saveRDS(Wetlands, file = 'tmp/Wetlands')
#Read in all the fire layers
WetInData<-file.path(WetspatialDir,'Wetland_Assessment_Level1_InputData.gdb')
wetin_list <- st_layers(WetInData)
Wildfire_2018 <- readOGR(dsn=WetInData, layer = "Wildfire_2018_181128") %>%
as('sf')
st_crs(Wildfire_2018)<-3005
saveRDS(Wildfire_2018,'tmp/Wildfire_2018')
Wildfire_Historical <- readOGR(dsn=WetInData, layer = "Wildfire_Historical_181128") %>%
as('sf')
st_crs(Wildfire_Historical)<-3005
saveRDS(Wildfire_Historical,'tmp/Wildfire_Historical')
BurnSeverity_2018 <- readOGR(dsn=WetInData, layer = "BurnSeverity_2018_181128") %>%
as('sf')
st_crs(BurnSeverity_2018)<-3005
saveRDS(BurnSeverity_2018,'tmp/BurnSeverity_2018')
BurnSeverity_2017 <- readOGR(dsn=WetInData, layer = "BurnSeverity_2017_181128") %>%
as('sf')
st_crs(BurnSeverity_2017)<-3005
saveRDS(BurnSeverity_2017,'tmp/BurnSeverity_2017')
# 1. Water Drainage data
# read in the water drainage data set to set up and AOI:
# https://catalogue.data.gov.bc.ca/dataset/water-survey-of-canada-sub-sub-drainage-areas
# download the water drainage and use as an area of interest using the bcdata package
#ws <- get_layer("wsc_drainages", class = "sf") %>%
# select(SUB_DRAINAGE_AREA_NAME, SUB_SUB_DRAINAGE_AREA_NAME) %>%
# filter(SUB_DRAINAGE_AREA_NAME %in% c("Nechako", "Skeena - Coast"))
ws <- get_layer("wsc_drainages", class = "sf") %>%
select(SUB_DRAINAGE_AREA_NAME, SUB_SUB_DRAINAGE_AREA_NAME)
st_crs(ws)<-3005
saveRDS(ws, file = 'tmp/ws')
#mapview(ws) + mapview(ESI)
## plot the data to verify locations
#plot(ws["SUB_DRAINAGE_AREA_NAME"], key.pos = NULL)
#mapview::mapview(ws)
#FWA_Streams
#Streams <- read_sf(Wet_gdb, layer = "FWA_Streams")
Streams <- read_sf(WetInData, layer = "FWA_Streams")
st_crs(Streams) <- 3005
saveRDS(Streams, file = 'tmp/Streams')
#FWA_Rivers
Rivers <- read_sf(WetInData, layer = "FWA_Rivers")
st_crs(Rivers) <- 3005
saveRDS(Rivers, file = 'tmp/Rivers')
#FWA_Lakes
waterbodies <- read_sf(WetInData, layer = "FWA_Lakes")
st_crs(waterbodies) <- 3005
saveRDS(waterbodies, file = 'tmp/waterbodies')
# read in the VRI data
vri <- read_sf(WetInData, layer = 'VRI_LYRR1_181128')
st_crs(vri) <- 3005
saveRDS(vri, file = 'tmp/vri')
#First Nation house groups/wilps/yinta
ESI_OW <- read_sf(file.path(ESIDir,'Data/Library/FN'), layer = "Wetsuweten_House") %>%
st_transform(3005)
saveRDS(ESI_OW, file='tmp/ESI_OW')
ESI_LBN <- read_sf(file.path(ESIDir,'Data/Library/FN'), layer = "LBN_subwatershed") %>%
st_transform(3005)
saveRDS(ESI_LBN, file='tmp/ESI_LBN')
ESI_Gitxsan <- read_sf(file.path(ESIDir,'Data/Library/FN'), layer = "gitxsan_houses_v5") %>%
st_transform(3005)
saveRDS(ESI_Gitxsan, file='tmp/ESI_Gitxsan')
ESI_Gitxsan_wshd <- read_sf(file.path(ESIDir,'Data/Library/FN'), layer = "gitxsan_admin_watershed_v2") %>%
st_transform(3005)
saveRDS(ESI_Gitxsan_wshd, file='tmp/ESI_Gitxsan_wshd')
FN_boundaries <- read_sf(file.path(ESIDir,'Data/FN_Boundaries'), layer = "FN_Boundaries") %>%
st_transform(3005)
saveRDS(FN_boundaries, file='tmp/FN_boundaries')
ESI_Gitanyow <- read_sf(file.path(ESIDir,'Data/Library/FN'), layer = "Gitanyow_Houses") %>%
st_transform(3005)
saveRDS(ESI_Gitanyow, file='tmp/ESI_Gitanyow')
FN_boundaries <- st_read(file.path(ESIDir,'Data/FN_Boundaries',"SSAF_coreFN_200513.gpkg")) %>%
st_transform(3005)
saveRDS(FN_boundaries, file='tmp/FN_boundaries')
waterpt<-st_read(file.path(spatialOutDir,"waterpt.gpkg"))
#Aggregated First Nation areas:
# Download BEC - # Gets bec_sf zone shape and filters the desired subzones
bec_sf <- bec(class = "sf") %>%
select(ZONE, MAP_LABEL, ZONE_NAME ) %>%
st_cast("MULTIPOLYGON")
saveRDS(bec_sf, file='tmp/bec_sf')
#Roads - use latest CE roads
Rd_gdb <- list.files(file.path(RoadDir, "CE_Roads/2017"), pattern = ".gdb", full.names = TRUE)[1]
fc_list <- st_layers(Rd_gdb)
# Read as sf and calculate road lengths
roads_sf <- read_sf(Rd_gdb, layer = "integrated_roads") %>%
mutate(rd_len = st_length(.))
st_crs(roads_sf) <- 3005
saveRDS(roads_sf, file='tmp/roads_sf')
#Read DEM
ESI_DEM <- raster(file.path(ESIDir,'Data/Library/DEM25.tif'))
saveRDS(ESI_DEM, file = 'tmp/ESI_DEM')
#Read in Landform file and mask to ESI area
LForm<-
#raster(file.path('../GB_Data/data/Landform',"Landform_BCAlbs.tif")) %>%
raster(file.path('/Users/darkbabine/Dropbox (BVRC)/_dev/Bears/GB_Data/data/Landform',"LForm.tif"))
saveRDS(LForm, file = 'tmp/LForm')
#mapview(LForm, maxpixels = 271048704)
#LFormFlat[!(LFormFlat[] %in% c(1000,5000,6000,7000,8000))]<-NA
# ID Landform colour
# 1000 Valley #358017
# 2000 Hilltop in Valley #f07f21
# 3000 Headwaters #7dadc3
# 4000 Ridges and Peaks #ebebf1
# 5000 Plains #c9de8d
# 6000 Local Ridge in Plain #f0b88a
# 7000 Local Valley in Plain #4cad25
# 8000 Gentle Slopes #bbbbc0
# 9000 Steep Slopes #8d8d91
LForm_LUT <- data.frame(LFcode = c(1000,2000,3000,4000,5000,6000,7000,8000,9000),
Landform = c('Valley','Hilltop in Valley','Headwaters','Ridges and Peaks',
'Plains','Local Ridge in Plain','Local Valley in Plain',
'Gentle Slopes','Steep Slopes'),
colourC = c('#358017','#f07f21','#7dadc3','#ebebf1','#c9de8d','#f0b88a',
'#4cad25','#bbbbc0','#8d8d91'))
saveRDS(LForm_LUT, file = 'tmp/LForm_LUT')
LandCover<-
raster(file.path(ESIDir,'Data/DataScience/SkeenaESI_LandCover_Age_Human_Footprint/OutRaster','LandCover.tif'))
saveRDS(LandCover, file = 'tmp/LandCover')
LandCover_LUT <- read_excel(file.path(ESIDir,'Data/DataScience/SkeenaESI_LandCover_Age_Human_Footprint/LUT','LandCoverLookUp_LUT.xlsx'),sheet=1)
saveRDS(LandCover_LUT, file = 'tmp/LandCover_LUT')
LandCoverAndAge<-
raster(file.path(ESIDir,'Data/DataScience/SkeenaESI_LandCover_Age_Human_Footprint/OutRaster','LandCoverAndAge.tif'))
saveRDS(LandCoverAndAge, file = 'tmp/LandCoverAndAge')
Age<-
raster(file.path(ESIDir,'Data/DataScience/SkeenaESI_LandCover_Age_Human_Footprint/OutRaster','Age.tif'))
saveRDS(Age, file = 'tmp/Age')
LogYear<-
raster(file.path(ESIDir,'Data/DataScience/SkeenaESI_LandCover_Age_Human_Footprint/OutRaster','LogYear.tif'))
saveRDS(LogYear, file = 'tmp/LogYear')
DEM<-
raster(file.path(ESIDir,'Data/DataScience/SkeenaESI_LandCover_Age_Human_Footprint/OutRaster','DEM.tif'))
saveRDS(DEM, file = 'tmp/DEM')
#Raster rail
RailRoads<-
raster(file.path(ESIDir,'Data/DataScience/SkeenaESI_LandCover_Age_Human_Footprint/OutRaster','RailRoads.tif'))
saveRDS(RailRoads, file = 'tmp/RailRoads')
#Raster pipeline
Pipe<-
raster(file.path(ESIDir,'Data/DataScience/SkeenaESI_LandCover_Age_Human_Footprint/OutRaster','Pipe_PrinceRupertGasTransmissionLtd.tif'))
saveRDS(Pipe, file = 'tmp/Pipe')
#Raster HydroTransmission
HydroTransmission<-
raster(file.path(ESIDir,'Data/DataScience/SkeenaESI_LandCover_Age_Human_Footprint/OutRaster','HydroTransmission.tif'))
saveRDS(HydroTransmission, file = 'tmp/HydroTransmission')
#Raster roads
RoadType<-
raster(file.path(ESIDir,'Data/DataScience/SkeenaESI_LandCover_Age_Human_Footprint/OutRaster','roadType.tif'))
saveRDS(RoadType, file = 'tmp/roadType')
RoadType_LUT <- read_csv(file.path(ESIDir,'Data/DataScience/SkeenaESI_LandCover_Age_Human_Footprint/LUT','RoadType_LUT.csv'))
saveRDS(RoadType_LUT, file = 'tmp/RoadType_LUT')
ExtensiveFootprint<-
raster(file.path(ESIDir,'Data/DataScience/SkeenaESI_LandCover_Age_Human_Footprint/OutRaster','ExtensiveFootprint.tif'))
saveRDS(ExtensiveFootprint, file = 'tmp/ExtensiveFootprint')
#Load ESI Wetlands
ESI_gdb <-file.path(ESIData,'ESI_Data.gdb')
#wet_list <- st_layers(ESI_gdb)
RoadKisp <- readOGR(dsn=ESI_gdb, layer = "SSAF_Ext_Clip_ConsRd_inclKispBulk_DSS_190918") %>%
as('sf')
st_crs(RoadKisp)<-3005
saveRDS(RoadKisp, file = 'tmp/RoadKisp')
#Load FREP blocks
FREP_gdb <- file.path(FREPDir,'2020_PossibleFREP_Wetlands_Locations_20200605.gdb')
FREP_list <- st_layers(FREP_gdb)
FREPblocksDSS <- readOGR(dsn=FREP_gdb, layer=FREP_list$name[1]) %>%
as('sf') %>%
dplyr::select(OPENING_ID, DISTRICT_NAME, OPENING_GROSS_AREA, DISTURBANCE_END_DATE)
st_crs(FREPblocksDSS)<-3005
FREPblocksNA <- readOGR(dsn=FREP_gdb, layer=FREP_list$name[2]) %>%
as('sf') %>%
dplyr::select(OPENING_ID, DISTRICT_NAME, OPENING_GROSS_AREA, DISTURBANCE_END_DATE)
st_crs(FREPblocksNA)<-3005
FREPblocks <- rbind(FREPblocksDSS, FREPblocksNA)
saveRDS(FREPblocks, file = 'tmp/FREPblocks')
#CGL wetlands
CGLpoints <- st_read(file.path(CGLDir, "CGL.gpkg")) %>%
st_transform(st_crs(ESI))
saveRDS(CGLpoints, file = 'tmp/CGLpoints')
} else {
vri <- readRDS(file = 'tmp/vri')
ws <- readRDS(file = 'tmp/ws')
Wetlands <- readRDS(file = 'tmp/Wetlands')
waterbodies <- readRDS(file = 'tmp/waterbodies')
Streams <- readRDS(file = 'tmp/Streams')
bec_sf <- readRDS(file= 'tmp/bec_sf')
ESI <- readRDS(file = 'tmp/ESI')
roads_sf <- readRDS(file = 'tmp/roads_sf')
LForm <- readRDS(file = 'tmp/LForm')
LForm_LUT <- readRDS(file= 'tmp/LForm_LUT')
LandCover <- readRDS(file= 'tmp/LandCover')
LandCover_LUT <- readRDS(file= 'tmp/LandCover_LUT')
Age <- readRDS(file= 'tmp/Age')
LandCoverAndAge <- readRDS(file= 'tmp/LandCoverAndAge')
ExtensiveFootprint <- readRDS(file= 'tmp/ExtensiveFootprint')
RoadType <- readRDS(file= 'tmp/RoadType')
HydroTransmission <- readRDS(file= 'tmp/HydroTransmission')
Pipe <- readRDS(file= 'tmp/Pipe')
RailRoads <- readRDS(file= 'tmp/RailRoads')
LogYear <- readRDS(file= 'tmp/LogYear')
Wildfire_2018 <- readRDS(file= 'tmp/Wildfire_2018')
Wildfire_Historical <- readRDS(file= 'tmp/Wildfire_Historical')
BurnSeverity_2018 <- readRDS(file= 'tmp/BurnSeverity_2018')
BurnSeverity_2017 <- readRDS(file= 'tmp/BurnSeverity_2017')
RoadKisp <- readRDS(file= 'tmp/RoadKisp')
ESI_DEM <- readRDS(file = 'tmp/ESI_DEM')
ESI_OW <-readRDS(file='tmp/ESI_OW')
ESI_LBN <-readRDS(file='tmp/ESI_LBN')
ESI_Gitxsan <-readRDS(file='tmp/ESI_Gitxsan')
ESI_Gitanyow <-readRDS(file='tmp/ESI_Gitanyow')
FREPblocks <-readRDS(file='tmp/FREPblocks')
}