-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecoConnect_tool_prep.R
70 lines (50 loc) · 2.93 KB
/
ecoConnect_tool_prep.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
'ecoConnect_tool_prep' <- function(iei = TRUE, ecoConnect = TRUE, shindex = TRUE) {
# Prep ecoConnect and IEI for ecoConnect_tool web app
# Before running,
# - run and post-process IEI
# - run ECOCONNECT and rescale.ecoConnect.R
# - run prep.ecoConnect.quantiles to create shindex.tif, stateinfo.txt, and hucinfo.txt
# Arguments:
# iei process IEI if TRUE
# ecoConnect process ecoConnect if TRUE
# shindex process shindex if TRUE
# Produces final integerized TIFFs in Web Mercator, with overviews, ready to post on GeoServer
# B. Compton, 30 May 2024
library(terra)
source('x:/LCC/Code/Web/geoTIFF4web.R')
iei.source.path <- 'x:/LCC/GIS/Final/NER/caps_phase5/post_2020/scaled/'
iei.result.path <- 'x:/LCC/GIS/Final/GeoServer/IEI/'
connect.source.path <- 'x:/LCC/GIS/Final/ecoRefugia/ecoConnect_final/ecoConnect_'
connect.result.path <- 'x:/LCC/GIS/Final/GeoServer/ecoConnect/'
shindex.source.path <- 'x:/LCC/GIS/Final/ecoRefugia/ecoConnect_final/'
shindex.result.path <- 'x:/LCC/GIS/Final/GeoServer/ecoConnect/'
iei.source <- c('full/iei-r', 'states/iei-s', 'ecoregions/iei-e', 'huc6/iei-h6')
iei.result <- c('iei_regional', 'iei_state', 'iei_ecoregion', 'iei_huc6')
connect.source <- c('forests', 'ridgetops', 'wetlands', 'floodplains')
connect.result <- c('Forest_fowet', 'Ridgetop', 'Nonfo_wet', 'LR_floodplain_forest')
if(iei)
for(i in 1:length(iei.source)) {
cat('\nProcessing ', iei.source[i], '...\n', sep = '')
geoTIFF4web(paste0(iei.source.path, iei.source[i], '.tif'), iei.result[i],
resultpath = iei.result.path, auto = TRUE)
}
if(ecoConnect)
for(i in 1:length(connect.source)) {
cat('\nProcessing ', connect.source[i], '...\n', sep = '')
geoTIFF4web(paste0(connect.source.path, connect.source[i], '.tif'), connect.result[i],
resultpath = connect.result.path, auto = FALSE, type = 'INT1U')
}
if(shindex) {
cat('\nProcessing shindex and template...\n', sep = '')
geoTIFF4web(paste0(shindex.source.path, 'shindex.tif'), 'shindex',
resultpath = shindex.result.path, auto = FALSE, type = 'INT2U', overviewResample = 'nearest')
template <- !is.na(rast(paste0(shindex.source.path, 'shindex.tif')))
writeRaster(template, paste0(shindex.source.path, 'template.tif'), overwrite = TRUE, datatype = 'INT1U',
NAflag = assessType('Byte')$noDataValue)
geoTIFF4web(paste0(shindex.source.path, 'template.tif'), 'template',
resultpath = shindex.result.path, auto = FALSE, type = 'INT1U', buildOverviews = FALSE)
file.copy(paste0(shindex.source.path, 'hucinfo.txt'), shindex.result.path, overwrite = TRUE)
file.copy(paste0(shindex.source.path, 'stateinfo.txt'), shindex.result.path, overwrite = TRUE)
}
cat('\nAll done.\n')
}