@@ -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 ) == " " ) {
0 commit comments