divide | R Documentation |
Divide a SpatRaster
into n
parts with approximately the same sum of weights (cell values).
Divides a SpatVector
of polygons into n
compact and approximately equal area parts. The results are not deterministic so you should use set.seed to be able to reproduce your results. If you get a warning about non-convergence, you can increase the number of iterations used with additional argument iter.max
## S4 method for signature 'SpatRaster'
divide(x, n=2, start="ns", as.raster=FALSE, na.rm=TRUE)
## S4 method for signature 'SpatVector'
divide(x, n=5, w=NULL, alpha=1, ...)
x |
SpatRaster or SpatVector of polygons |
n |
numeric. Can be a single positive integer to indicate the number of parts (SpatVector) or the number of splits (SpatRaster). If If |
start |
character. To indicate the initial direction of splitting the raster. "ns" for North-South (horizontal) or "ew" for East-West (vertical) |
as.raster |
logical. If |
na.rm |
logical. If |
w |
SpatRaster with, for example, environmental data |
alpha |
numeric. One or two numbers that act as weights for the x and y coordinates |
... |
additional arguments such as |
SpatVector or SpatRaster, or a list with both
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
x <- divide(r, 3)
# plot(r); lines(x)
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
d <- divide(v, 3)
dv <- divide(v, list(h=.5))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.