Find a fixed-width extent from reference points
Usage
hsi_find_extent(
x,
points,
width,
filename = "",
overwrite = FALSE,
insert = FALSE,
layer = "",
...
)Arguments
- x
A
SpatRasterwith hyperspectral data.- points
A
SpatVectorwith exactly 2 point geometries marking the vertical extent of the region of interest. Must be in the same coordinate space asx.- width
Positive integer. Width of the output extent in pixels.
- filename
Character. Output filename. Default
""skips writing.- overwrite
Logical. Overwrite existing file. Default
FALSE.- insert
Logical. Insert layer into an existing file. Default
FALSE.- layer
Character. Layer name for vector output. Default
"".- ...
Additional arguments passed to
terra::writeVector().
Value
A SpatVector polygon snapped to the
grid of x.
Details
The output polygon spans vertically between the two reference points and
horizontally by width pixels centered on the mean x-coordinate of the
points. The extent is snapped to cell boundaries of x with
terra::align() using snap = "near".
The function aborts if the requested extent falls outside the raster bounds.
Reduce width or adjust the reference points to fit within x.
See also
hsi_set_extent() to assign physical units to a raster extent.
Other Utilities:
hsi_bind_rows(),
hsi_subset(),
hsi_subset_range(),
wavelength_position()
Examples
if (FALSE) { # \dontrun{
x <- terra::rast("REFLECTANCE_testdata.tif")
ends <- terra::vect("spatials.gpkg", layer = "ends")
x_extent <- hsi_find_extent(x, points = ends, width = 100)
x_cropped <- terra::crop(x, x_extent)
x_extent <- hsi_find_extent(
x,
points = ends,
width = 900,
filename = "spatials.gpkg",
insert = TRUE,
layer = "extent"
)
} # }