Skip to content

Commit 32f3ac3

Browse files
committed
squareness
1 parent 9f57d36 commit 32f3ac3

5 files changed

Lines changed: 42 additions & 8 deletions

File tree

R/getCell2Fire.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ getCell2Fire <- function(
8080
}
8181
# browser()
8282
return(invisible(out))
83-
}
83+
}

inst/app/functions_makeCmd.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ proc <- function(dry = TRUE) {
5353

5454
elev <- rast(input$ELEVATION)
5555
for(tt in names(terrain)){
56-
if(!file.exists(terrain[[tt]])){
56+
pout <- file.path(input$inputfolder, sprintf("%s.tif", tt) )
57+
if(!file.exists(terrain[[tt]]) && !file.exists(pout)){
5758
shiny::showNotification(ui =sprintf("%s raster NOT present,
5859
but elevation raster is - I will create it for you...
5960
This is a one-time operation, please be patient.", tt), type = "warning")
6061
if(tt=="slope") ttt <- terra::terrain(elev, v = "slope", unit = "degrees")
6162
if(tt=="saz") ttt <- terra::terrain(elev, v = "aspect", unit = "degrees")
6263
if(tt=="cur") ttt <- spatialEco::curvature(elev, type = "total")
6364

64-
pout <- file.path(input$inputfolder, sprintf("%s.tif", tt) )
65+
6566
writeRaster(ttt, pout )
6667
assign(tt, pout)
6768
}

inst/app/functions_server.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ processSimulationOutputFolder <- function(resDir){
100100

101101
rfl <- readLines(fl )
102102
session$sendCustomMessage("appendLog", list(out=rfl))
103-
103+
104104
simout <- tryCatch({
105105
parse_fire_log(rfl )
106106
}, warning=function(e){

inst/app/server.R

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,24 +430,57 @@ Work in progress....",
430430
detail = sprintf("Adding layer %s", layerName))
431431

432432
r2 <- terra::rast(fi)
433-
terra.rasters[[layerName]] <<- r2
433+
if(terra::is.lonlat(r2)){
434+
showNotification(HTML(
435+
sprintf(
436+
"Raster %s is in geographic coordinates (latitude and longitude). <br>
437+
This will not work with fire spread simulations -
438+
I will force this to EPSG:3857 (PseudoMercator projection) and
439+
<u>square pixel rounded to nearest meter</u>.
440+
<b>Raster will be overwritten. </b>
441+
<br>If this is not what you want please remove the dataset and reload a projected dataset.
442+
",
443+
basename(fi)
444+
)
445+
), duration = ifelse(length(rasters) > 0, 10, 20), type = "info")
446+
447+
448+
449+
if(length(rasters) > 0){
450+
rt <- terra::project(r2, terra::rast(rasters[[1]]))
451+
} else {
452+
r_3857 <- terra::project(r2, "epsg:3857")
453+
exact_res <- mean(res(r_3857))
454+
455+
##
456+
rt <- project(r2, "EPSG:3857", res = round(exact_res), method = "near")
457+
diff(res(rt))
458+
}
459+
terra::writeRaster(rt, filename = fi, overwrite=T)
460+
r2 <- terra::rast(fi)
461+
}
462+
463+
464+
434465
## check alignment between rasters -----
435466
if (length(rasters) > 0) {
436467
if (!compareGeom(terra::rast(rasters[[1]]), r2, stopOnError = FALSE)) {
437468
showNotification(HTML(
438469
sprintf(
439470
"<b>Raster %s NOT aligned with raster stack %s!</b> Either CRS,
440-
origin or resolution are different. It will be removed! Please reload dataset with clean set of aligned rasters.",
471+
origin or resolution are different. The system will try to align the landscape stack.
472+
Reload the dataset for better control.",
441473
basename(rasters[[1]]) ,
442474
basename(sources(r2))
443475
)
444476
),
445477
duration = 12,
446478
type = "error")
447-
next
479+
448480
}
449481
}
450482

483+
terra.rasters[[layerName]] <<- r2
451484

452485

453486
if (terra::crs(r2) == "") {

man/run_cell2fire.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)