defineWorld | R Documentation |
Function that defines the grid that can be traversed–the "world"–as well as the cells that can be accessed from each individual cell. This is the most time-intensive function.
defineWorld(
source,
source_id = "TILEID",
z_min = NULL,
grid = NULL,
proj = NULL,
grid_id = "TILEID",
cut_slope = Inf,
directions = 16,
neighbor_distance = 10,
z_fix = NULL,
unit = "m",
vals = "location",
precision = 2,
dist = "proj",
r = 6378137,
f = 1/298.257223563,
b = 6356752.3142,
FUN = NULL,
sampling = "bilinear",
water = FALSE,
water_speed = "speed",
uv = TRUE,
priority = "water",
overwrite = FALSE,
filt = 0,
dir = tempdir(),
cols = c("x_i", "y_i", "dz", "dl", "dr"),
...
)
source |
An object of class SpatVector, or potential inputs to
|
source_id |
A character string representing the name of the column in the
|
z_min |
The minimum allowable elevation. Useful if DEM source includes
ocean bathymetry as does the SRTM data from AWS. Default is |
grid |
An object of class SpatVector representing
the partitioning grid for the maximum possible travel area. Smaller grids increase
the amount of area that can be read into the memory, but require more I/O operations.
Default is |
proj |
A crs object or character string representing the output projection.
Default projection is |
grid_id |
A character string representing the name of the column
in the |
cut_slope |
A number representing the dimensionless maximum slope
of ascent/descent. To ignore, set |
directions |
One of the integers |
neighbor_distance |
An integer representing the distance in meters that tiles are buffered. In other words, to ensure that all transitions in the 'world' are recorded, files for each tile will contain a number of observations that fall outside of the tile in other ones. Default is 100 m, but adjust on raster size. |
z_fix |
A SpatRaster or Raster* that will define the resolution, origin, and
projection information for the entire "world" of possible movement. Note that
it does NOT need the same extent. Default resolution is 5, and offset is 0.
Default projection is |
unit |
One of |
vals |
A character string or a SpatRaster or Raster* object. Ignored unless the
|
precision |
An integer representing the number of decimals to retain
in the x and y directions. For grid sizes with nice, round numbers precisions
can be low. This factor is controled by |
dist |
A character string representing the way distances should be
calculated. Default is |
r |
The earth's radius. Employed only if one of the geodesic methods is used.
Default is |
f |
The earth's ellipsoidal flattening. Employed only if
|
b |
The earth's semiminor axis. Employed only if |
FUN |
Function to deal with overlapping values for overlapping sectors.
Default is NA, which uses |
sampling |
How to resample rasters. Default is |
water |
Optional. One of (1) SpatialPolygon* or SpatVector polygon representing
the area covered by water, in which case |
water_speed |
A character representing the column name in
|
uv |
Logical. If |
priority |
One of |
overwrite |
If a directory with a |
filt |
Numeric. Size of moving window to apply a low-pass filter. Default
is |
dir |
A filepath to the directory being used as the workspace.
Default is |
cols |
A character vector. Default is c("x_i","y_i","dz","dl","dr"), and dictates which columns are returned but final values for x and y and final/initial z values are also available |
... |
Additional arguments to pass to |
It first checks to see if the required
files contained within a '/World/'
directory have already been created
in the dir
workspace. If not it creates them; if the '/World/'
directory exists though, then an error is thrown (default) OR the user has the option
to overwrite the directory.
The default parameters are sufficient for a workflow involving calculating
costs with the calculateCosts
function.
A /World/
directory, containing /Loc/
, /Diff/
,
and /Raw/
, directories where cropped and transformed files will be stored,
and /callVars.gz/
, /z_sources/
, /z_grid/
,
/z_fix.fst/
, and /z_fix.fstproj/
files defining the world.
# 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)]
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.