Create a raster of fire perimeters

prepInputsFireYear(..., rasterToMatch, fireField = "YEAR", earliestYear = 1950)

Arguments

...

Additional arguments passed to reproducible::prepInputs()

rasterToMatch

A RasterLayer objects to use as the template for all subsequent raster operations (i.e., the one used throughout the simulation).

fireField

field used to rasterize fire polys

earliestYear

the earliest fire date to allow

Value

a SpatRaster layer of fire perimeters with fire year values.

Examples

library(SpaDES.tools)
library(terra)
#> terra 1.7.78
#> 
#> Attaching package: ‘terra’
#> The following object is masked from ‘package:SpaDES.tools’:
#> 
#>     wrap
#> The following object is masked from ‘package:data.table’:
#> 
#>     shift
#> The following object is masked from ‘package:LandR’:
#> 
#>     rescale
library(reproducible)
#> 
#> Attaching package: ‘reproducible’
#> The following object is masked from ‘package:LandR’:
#> 
#>     rasterRead

options("reproducible.useTerra" = TRUE, "reproducible.rasterRead" = "terra::rast")

targetCRS <- crs(randomStudyArea())
randomPoly <- randomStudyArea(
  center = vect(cbind(-115, 50), crs = targetCRS),
  size = 1e+7,
)
buffExt <- buffer(randomPoly, 1e+3) |> ext()
ras2match <- rast(res = 10, ext = ext(randomPoly), crs = crs(randomPoly))
ras2match <- rasterize(randomPoly, ras2match)

firePerimeters <- prepInputsFireYear(
  url = paste0("https://cwfis.cfs.nrcan.gc.ca/downloads",
               "/nfdb/fire_poly/current_version/NFDB_poly.zip"),
  destinationPath = tempdir(),
  rasterToMatch = ras2match,
  earliestYear = 1930
)
#> No cachePath supplied and getOption('reproducible.cachePath') is
#>   inside a temporary directory;
#>   this will not persist across R
#>   sessions.
#>  Running `prepInputs`
#>   Running `preProcess`
#>    alsoExtract is unspecified; assuming that all files must be
#>      extracted
#>    No targetFile supplied. Checksumming all files in archive
#>    ...downloading...
#>    Downloading
#>      https://cwfis.cfs.nrcan.gc.ca/downloads/nfdb/fire_poly/current_version/NFDB_poly.zip
#>      ...
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |                                                                      |   1%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |==                                                                    |   4%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   6%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |=====                                                                 |   8%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |=======                                                               |   9%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |=======                                                               |  11%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |=========                                                             |  14%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |===========                                                           |  15%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  16%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |============                                                          |  18%
  |                                                                            
  |=============                                                         |  18%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |==============                                                        |  19%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |==============                                                        |  21%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |===============                                                       |  22%
  |                                                                            
  |================                                                      |  22%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |================                                                      |  24%
  |                                                                            
  |=================                                                     |  24%
  |                                                                            
  |=================                                                     |  25%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |==================                                                    |  26%
  |                                                                            
  |===================                                                   |  26%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |===================                                                   |  28%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  29%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |=====================                                                 |  31%
  |                                                                            
  |======================                                                |  31%
  |                                                                            
  |======================                                                |  32%
  |                                                                            
  |=======================                                               |  32%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |=======================                                               |  34%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |========================                                              |  35%
  |                                                                            
  |=========================                                             |  35%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |==========================                                            |  36%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |==========================                                            |  38%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |===========================                                           |  39%
  |                                                                            
  |============================                                          |  39%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |============================                                          |  41%
  |                                                                            
  |=============================                                         |  41%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |==============================                                        |  42%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |==============================                                        |  44%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |=================================                                     |  46%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |=================================                                     |  48%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |==================================                                    |  49%
  |                                                                            
  |===================================                                   |  49%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |===================================                                   |  51%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |====================================                                  |  52%
  |                                                                            
  |=====================================                                 |  52%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |=====================================                                 |  54%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |=======================================                               |  55%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |========================================                              |  56%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |========================================                              |  58%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==========================================                            |  59%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |==========================================                            |  61%
  |                                                                            
  |===========================================                           |  61%
  |                                                                            
  |===========================================                           |  62%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |============================================                          |  63%
  |                                                                            
  |============================================                          |  64%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |=============================================                         |  65%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |===============================================                       |  66%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |===============================================                       |  68%
  |                                                                            
  |================================================                      |  68%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |=================================================                     |  71%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |===================================================                   |  72%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |===================================================                   |  74%
  |                                                                            
  |====================================================                  |  74%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |=====================================================                 |  75%
  |                                                                            
  |=====================================================                 |  76%
  |                                                                            
  |======================================================                |  76%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |======================================================                |  78%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |=======================================================               |  79%
  |                                                                            
  |========================================================              |  79%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |========================================================              |  81%
  |                                                                            
  |=========================================================             |  81%
  |                                                                            
  |=========================================================             |  82%
  |                                                                            
  |==========================================================            |  82%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |==========================================================            |  84%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |===========================================================           |  85%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  86%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |==============================================================        |  88%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |===============================================================       |  89%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |===============================================================       |  91%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |=================================================================     |  92%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |=================================================================     |  94%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |===================================================================   |  95%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |====================================================================  |  96%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |====================================================================  |  98%
  |                                                                            
  |===================================================================== |  98%
  |                                                                            
  |===================================================================== |  99%
  |                                                                            
  |======================================================================|  99%
  |                                                                            
  |======================================================================| 100%
#>    Hardlinked version of file(s) created:
#>    ... no copy/copies made.
#>    From:
#>      /tmp/RtmpU0Xt8U/NFDB_poly.zip  
#>      Extracting
#>                                               files
#>    <char>
#>    1:                  BNDFFC_documentation_FR.pdf
#>    2:             BNDFFC_FR_End-User Agreement.pdf
#>    3:                    NFDB_documentation_EN.pdf
#>    4:               NFDB_EN_End-User Agreement.pdf
#>    5:                       NFDB_poly_20210707.CPG
#>    6:                       NFDB_poly_20210707.dbf
#>    7:                       NFDB_poly_20210707.prj
#>    8:                       NFDB_poly_20210707.sbn
#>    9:                       NFDB_poly_20210707.sbx
#>    10:                       NFDB_poly_20210707.shp
#>    11:                   NFDB_poly_20210707.shp.xml
#>    12:                       NFDB_poly_20210707.shx
#>    13:          NFDB_poly_20210707_shp_metadata.pdf
#>    14:    NFDB_Poly_metadata_NAP_ISO_19115_2003.xml
#>    15: NFDB_Poly_metadata_NAP_ISO_19115_2003_EN.pdf
#>    16: NFDB_Poly_metadata_NAP_ISO_19115_2003_FR.pdf
#>    17:                     NFDB_poly_update_log.txt
#> ⠙ 9 extracted | 689 MB (233 MB/s) | 3s
#> ⠹ 9 extracted | 1.4 GB (232 MB/s) | 6s
#>           ... Done extracting 18 files
#>    Appending checksums to CHECKSUMS.txt. If you see this message
#>      repeatedly, you can specify targetFile (and optionally alsoExtract)
#>      so it knows what to look for.
#>    targetFile was not specified. Trying terra::vect on
#>      /tmp/RtmpU0Xt8U/NFDB_poly_20210707.shp. If that is not correct,
#>      please specify a different targetFile and/or fun.
#>   `preProcess` done; took 15.48169 secs
#>   Running `process` (i.e., loading file into R)
#>    targetFile located at /tmp/RtmpU0Xt8U/NFDB_poly_20210707.shp
#>    Loading object into R
#> Warning: In {    st_as_sf(do.call(prepInputs, append(list(to = to, maskTo = maskTo,         fun = fun), dots)))}(): [vect] Z coordinates ignored
#>   Running `postProcessTo`
#>    cropping...
#>    It looks like the cropping results in no data (do not overlap or
#>      no intersection)
#>    done! took:  1.69 secs
#>    projecting...
#>    done! took:  0.00811 secs
#>    cropping...
#>    It looks like the cropping results in no data (do not overlap or
#>      no intersection)
#>    done! took:  0.0178 secs
#>   postProcessTo done! took:  1.72 secs
#>  `prepInputs` done; took 22.66511 secs
#> Saved! Cache file: 4ba5267a80c7f4e3.rds; fn: st_as_sf

if (interactive()) {
  plot(firePerimeters)
  plot(randomPoly, add = TRUE)
}