Compute Combined Extent (Bounding Box) from Multiple Raster Files
Source:R/ngr_spk_ext_raster.R
ngr_spk_ext_raster.Rd
Computes the combined spatial extent (bounding box) from one or more raster files.
It ensures that all input rasters share the same CRS and optionally reprojects the bounding box
to a specified CRS. The function relies on terra::ext()
, terra::crs()
, and sf::st_bbox()
for extent extraction and CRS handling.
Arguments
- x
character A vector of file paths, URLs, or database connection strings to raster data sources. Each path must exist and be accessible to GDAL.
- crs_out
character or NULL Optional. A CRS string (e.g., "EPSG:4326") to reproject the combined bounding box. If
NULL
, the CRS of the input rasters is retained. Default isNULL
.
Value
A bounding box object with:
xmin
: Minimum x-coordinate.xmax
: Maximum x-coordinate.ymin
: Minimum y-coordinate.ymax
: Maximum y-coordinate. Ifcrs_out
is specified, the bounding box is reprojected to the target CRS.
Details
This function ensures all input rasters share the same CRS before computing the union of their extents.
The resulting bounding box can be reprojected to a target CRS if crs_out
is provided.
It uses terra::ext()
to extract extents, terra::crs()
to check CRS consistency, and sf::st_bbox()
for constructing and reprojecting the bounding box.
See also
Other spacehakr:
ngr_spk_gdalwarp()
,
ngr_spk_odm()
,
ngr_spk_poly_to_points()
,
ngr_spk_res()
Examples
if (FALSE) { # \dontrun{
# Define input files
files_in <- c(
"/path/to/file1.tif",
"/path/to/file2.tif",
"/path/to/file3.tif"
)
# Get the combined extent without reprojection
bbox_combined <- ngr_spk_ext_raster(files_in)
# Get the combined extent and reproject to EPSG:4326
bbox_reprojected <- ngr_spk_ext_raster(files_in, crs_out = "EPSG:4326")
} # }