makeGrid | R Documentation |
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
)
dem |
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
If SpatVector or SpatialPolygons*, the extent of possible movement. |
nx |
The integer-number of columns in the output grid |
ny |
The integer-number of rows in the output grid |
path |
(Optional) The filepath or URL of the source DEM. Ignored if
|
sources |
Logical. Should source information be saved as attributes
to the grid for use in |
extension |
A character vector representing the extension of the source
path. Required only if |
proj |
A |
prefix |
A character string containing the prefix to name individual sectors.
Default is |
crop |
Logical. If TRUE (the default), the output polygons will be cropped
by the original |
zoom |
Considered only if |
var |
If the polygons point to a data source, what will be the variable name in the internal GIS? Default is 'z' for elevation. |
overlap |
How much should adjacent polygons overlap to ensure there's
contiguity between different tiles? Default is |
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)]
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.