mosaic_crop | R Documentation |
This function allows cropping of a raster mosaic interactively or programmatically:
Interactive Mode: If neither shapefile
nor mosaic2
is provided, an interactive map
is shown via mosaic_view()
, allowing users to draw a rectangle to define the cropping area.
Shapefile Mode: If a SpatVector
is provided in shapefile
, cropping or masking is performed
based on its extent or exact shape, optionally with a buffer.
Raster Mode: If mosaic2
is provided, mosaic
will be cropped to match the extent of mosaic2
.
For disk-based mosaics, cropping with shapefiles uses GDAL (sf::gdal_utils()
) to improve efficiency.
mosaic_crop(
mosaic,
r = 3,
g = 2,
b = 1,
re = 4,
nir = 5,
shapefile = NULL,
in_memory = FALSE,
mosaic2 = NULL,
buffer = 0,
show = c("rgb", "index"),
index = "R",
max_pixels = 5e+05,
downsample = NULL,
type = c("crop", "mask"),
...
)
mosaic |
A |
r , g , b , re , nir |
Integer indices representing the red, green, blue, red-edge, and near-infrared bands of the input mosaic. Default assumes BGR format (b = 1, g = 2, r = 3). |
shapefile |
An optional |
in_memory |
Logical. If |
mosaic2 |
A second |
buffer |
A numeric value indicating a buffer (in CRS units) to apply around the shapefile geometry. |
show |
A character value indicating what to display in the interactive viewer. Either |
index |
The index to show if |
max_pixels |
Maximum number of pixels to render in the interactive viewer. |
downsample |
Optional downsampling factor for display purposes. |
type |
Either
|
... |
Additional arguments passed to |
Crop or mask a SpatRaster
object (mosaic
) based on user input from an
interactive map or by using a provided shapefile or another raster.
A cropped or masked SpatRaster
object.
if (interactive() && requireNamespace("EBImage")) {
library(pliman)
# Load a sample raster
mosaic <- mosaic_input(system.file("ex/elev.tif", package = "terra"))
# Interactive cropping with drawn rectangle
cropped <- mosaic_crop(mosaic)
# View result
mosaic_view(cropped)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.