makeGrid.Rd
Generate a partitioning grid for a single raster source representing regional
elevations. Smaller partitioning grids (i.e. a greater value of nx * ny
)
results in a greater number of saved files and a greater number of
read-write operations in future operations, but reduces the amount of
memory employed.
makeGrid(
dem,
nx,
ny,
path = NA,
sources = FALSE,
extension = NULL,
proj = NULL,
prefix = "SECTOR_",
crop = TRUE,
zoom = 13,
var = "z",
overlap = 0.005
)
One of either a single character string, SpatVector (polygon), SpatialPolygons*, SpatRaster, or Raster
If character, SpatRaster, Raster, such an object or (filepath to one)
containing the elevations for the maximum possible extent imaginable for a study.
Note that SpatRaster and Raster only work
rasters that have been read in, not those that exist exclusively in the memory.
If you have just generated the raster and it is in memory, export it first with
writeRaster
then use the filepath string as dem
or
re-import it with rast
before using the SoatRaster object.
If SpatVector or SpatialPolygons*, the extent of possible movement.
The integer-number of columns in the output grid
The integer-number of rows in the output grid
(Optional) The filepath or URL of the source DEM. Ignored if
dem
is of class raster or SpatRaster. If a SpatVector or SpatialPolygons
is provided but no path, getMap
will use
get_elev_raster
to download topographic data.
Logical. Should source information be saved as attributes
to the grid for use in getMap
and
defineWorld
? Default is sources = FALSE
.
A character vector representing the extension of the source
path. Required only if sources = TRUE
and the extension is not apparent
from the URL stored in the var
column.
A crs
or something coercible to it representing
the desired output projection. Default is the input raster's projection.
A character string containing the prefix to name individual sectors.
Default is prefix = "SECTOR_"
Logical. If TRUE (the default), the output polygons will be cropped
by the original dem
(if SpatVector or SpatialPolygons*), or by
the area covered by non-NA cells (if raster or SpatRaster).
Considered only if var = 'z'
and no data source is set.
The zoom level to be downloaded. See documentation for the z
parameter
in get_elev_raster
for further information.
Default is 13, but see documentation for the z
parameter in
get_elev_raster
.
If the polygons point to a data source, what will be the variable name in the internal GIS? Default is 'z' for elevation.
How much should adjacent polygons overlap to ensure there's
contiguity between different tiles? Default is overlap = 0.005
.
Polygons of class SpatVector representing the individual sectors ('tiles'), with a dataframe containing three columns: the "TILEID", the raster's filepath, and a dummy column indicating that the grid was made using the makeGrid function. This will be necessary for future functions. The object MUST be stored on the disk, it should not be stored in the memory
# Generate a DEM, export it
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"
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)