A function that for a given region imports all cells from the transition .fst files. If such files have not yet been generated, they can be created by passing along the necessary parameters to this function as with calculateCosts.

importWorld(
  region,
  banned = NULL,
  dir = tempdir(),
  vars = NULL,
  costFUN = energyCosts,
  ...
)

Arguments

region

An object of class SpatRraster, Raster* or SpatialPolygons* representing the total area where movement is possible.

banned

An object of class Raster* or SpatialPolygons* representing the total area where movement is prohibited. Must lie within the area defined by polys

dir

A filepath to the directory being used as the workspace, the same one instantiated with defineWorld. Default is tempdir() but unless the analyses will only be performed a few times it is highly recommended to define a permanent workspace.

vars

The variable names to import.

costFUN

A cost function such as (timeCosts or energyCosts). The input to such a function should be a data.table object with column names present in the makeWorld file (initially c('x_i','x_f','y_i','y_f','z_i','z_f','dz','dl','dr')), and the output should be an data.table object with the same number of rows and the desired output variables as the only column names. Constants can be passed in the ... slot. Default is costFUN = energyCosts.

...

Additional arguments to pass to calculateCosts and costFUN.

Value

An object of class data.table containing at least three columns:

(1) $from, a character string of all possible origin cells in format "x,y",

(2) $to, a character string of all possible destination cells in format "x,y"

(3+) a numeric representing the imported costs(s)

Details

The default parameters are sufficient for a workflow involving calculating costs with the energyCosts function. However, if non-energetic analyses are desired, the user must define their own.

Examples

# Generate a DEM
n <- 5
dem <- expand.grid(list(x = 1:(n * 100),
                        y = 1:(n * 100))) / 100
dem <- as.data.table(dem)
dem[, z := 250 * exp(-(x - n/2)^2) + 
      250 * exp(-(y - n/2)^2)]
#>            x    y         z
#>      1: 0.01 0.01 1.0146139
#>      2: 0.02 0.01 1.0404641
#>      3: 0.03 0.01 1.0675194
#>      4: 0.04 0.01 1.0958300
#>      5: 0.05 0.01 1.1254477
#>     ---                    
#> 249996: 4.96 5.00 1.0711366
#> 249997: 4.97 5.00 1.0428260
#> 249998: 4.98 5.00 1.0157707
#> 249999: 4.99 5.00 0.9899205
#> 250000: 5.00 5.00 0.9652271
dem <- rast(dem)
ext(dem) <- c(10000, 20000, 30000, 40000)
crs(dem) <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +datum=WGS84"

# Export it so it doesn't just exist on the memory
dir <- tempdir()
writeRaster(dem, paste0(dir,"/DEM.tif"),overwrite=TRUE)


# Import raster, get the grid
dem <- rast(paste0(dir,"/DEM.tif"))
grid <- makeGrid(dem = dem, nx = n, ny = n, sources = TRUE)

# Select all tiles that exist between x = (12000,16000) and y = (32000,36000)
tiles <- ext(c(12000,16000,32000,36000))
tiles <- as.polygons(tiles)
crs(tiles) <- crs(grid)
tiles <- whichTiles(region = tiles, polys = grid)

#' # Make a world but limit it to the DEM grid size
defineWorld(source = grid, cut_slope = 0.5, 
            res = res(dem), dir = dir, overwrite=TRUE)

# Make a world but limit it to the DEM grid size
world <- importWorld(grid[8,], dir = dir, vars = 'dE_l', costFUN = energyCosts,
m = 70, v_max = 1.5, BMR = 76, k = 3.5, s = 0.05, l_s = 1,
L = 0.8)
#> [1] "Cropping Tile SECTOR_01 (1 of 4)"
#> [1] "Cropping Tile SECTOR_02 (2 of 4)"
#> [1] "Cropping Tile SECTOR_06 (3 of 4)"
#> [1] "Cropping Tile SECTOR_07 (4 of 4)"
#> [1] "Cropping Tile SECTOR_03 (1 of 2)"
#> [1] "Cropping Tile SECTOR_08 (2 of 2)"
#> [1] "Cropping Tile SECTOR_11 (1 of 2)"
#> [1] "Cropping Tile SECTOR_12 (2 of 2)"
#> [1] "Cropping Tile SECTOR_13 (1 of 1)"
#> [1] "Cropping Tile SECTOR_16 (1 of 2)"
#> [1] "Cropping Tile SECTOR_17 (2 of 2)"
#> [1] "Cropping Tile SECTOR_18 (1 of 1)"
#> [1] "Cropping Tile SECTOR_09 (1 of 3)"
#> [1] "Cropping Tile SECTOR_14 (2 of 3)"
#> [1] "Cropping Tile SECTOR_19 (3 of 3)"
#> [1] "Cropping Tile SECTOR_21 (1 of 2)"
#> [1] "Cropping Tile SECTOR_22 (2 of 2)"
#> [1] "Cropping Tile SECTOR_23 (1 of 1)"
#> [1] "Cropping Tile SECTOR_24 (1 of 1)"
#> [1] "Cropping Tile SECTOR_04 (1 of 1)"
#> [1] "Cropping Tile SECTOR_05 (1 of 2)"
#> [1] "Cropping Tile SECTOR_10 (2 of 2)"
#> [1] "Cropping Tile SECTOR_15 (1 of 1)"
#> [1] "Cropping Tile SECTOR_20 (1 of 1)"
#> [1] "Cropping Tile SECTOR_25 (1 of 1)"
#> Imported  9  Sectors