@@ -664,13 +664,23 @@ prepInputsFireYear <- function(..., rasterToMatch, fireField = "YEAR", earliestY
664
664
665
665
# # invalid NFDB polygons will cause Rstudio to crash during postProcess as of 8/21/2024
666
666
# # removing invalid polygons is far faster than fixing the 0.1% of data
667
- postProcessArgs <- dots [names(dots ) %in% c(" to" , " maskTo" , " projectTo" , " cropTo" )]
667
+ # projectTo must be rasterToMatch due to terra rasterize
668
+ # but don't project yet because of NFDB
669
+ postProcessArgs <- dots [names(dots ) %in% c(" to" , " projectTo" , " studyArea" , " maskTo" )]
668
670
if (length(postProcessArgs ) == 0 ) {
669
- postProcessArgs $ to <- rasterToMatch
671
+ postProcessArgs $ cropTo <- rasterToMatch
672
+ postProcessArgs $ projectTo <- rasterToMatch
673
+ postProcessArgs $ maskTo = rasterToMatch
670
674
}
675
+ postProcessArgs $ projectTo <- rasterToMatch
671
676
672
677
preProcessArgs <- dots [! names(dots ) %in% names(postProcessArgs )]
678
+ # you can crop without worrying about geometry
679
+ preProcessArgs $ cropTo <- rasterToMatch
680
+
673
681
allFires <- do.call(prepInputs , append(list (fun = fun ), preProcessArgs ))
682
+
683
+ # the reason this isn't combined into one function is due to geometry issues in NFDB
674
684
allFires <- allFires [terra :: is.valid(allFires ), ] # # drop invalid geometries
675
685
676
686
# # This may potentially result in dots intended for postProcess being lost.
@@ -692,7 +702,9 @@ prepInputsFireYear <- function(..., rasterToMatch, fireField = "YEAR", earliestY
692
702
if (! is(d , " SpatVector" )) {
693
703
d <- vect(d )
694
704
}
695
- fireRas <- terra :: rasterize(d , rasterToMatch , field = fireField )
705
+
706
+ # fun = max to take the most recent fire year
707
+ fireRas <- terra :: rasterize(d , rasterToMatch , field = fireField , fun = max )
696
708
fireRas [! is.na(terra :: values(fireRas , mat = FALSE )) &
697
709
terra :: values(fireRas , mat = FALSE ) < earliestYear ] <- NA
698
710
} else {
0 commit comments