Add a uniform buffer around a bounding box for geographic coordinates
Add a uniform buffer around a bounding box for geographic coordinates
add_bbox_buffer calculates the great circle distance both corners of your bounding box are from the centroid and extends those by a set distance. Due to using Haversine/great circle distance, latitude/longitude calculations will not be exact.
set_bbox_side_length is a thin wrapper around add_bbox_buffer which sets all sides of the bounding box to (approximately) a specified length.
Both of these functions are intended to be used with geographic coordinate systems (data using longitude and latitude for position). For projected coordinate systems, a more sane approach is to use sf::st_buffer to add a buffer, or combine sf::st_centroid with the buffer to set a specific side length.
add_bbox_buffer(data, distance, distance_unit ="meters", error_crs =NULL)## S3 method for class 'sf'add_bbox_buffer(data, distance, distance_unit ="meters", error_crs =NULL)## S3 method for class 'Raster'add_bbox_buffer(data, distance, distance_unit ="meters", error_crs =NULL)## S3 method for class 'SpatRaster'add_bbox_buffer(data, distance, distance_unit ="meters", error_crs =NULL)set_bbox_side_length( data, distance, distance_unit ="meters", error_crs =NULL)## S3 method for class 'sf'set_bbox_side_length( data, distance, distance_unit ="meters", error_crs =NULL)## S3 method for class 'Raster'set_bbox_side_length( data, distance, distance_unit ="meters", error_crs =NULL)## S3 method for class 'SpatRaster'set_bbox_side_length( data, distance, distance_unit ="meters", error_crs =NULL)
Arguments
data: The original data to add a buffer around. Must be either an sf
or SpatRaster object.
distance: The distance to add or to set side lengths equal to.
distance_unit: The units of the distance to add to the buffer, passed to units::as_units .
error_crs: Logical: Should this function error if data has no CRS? If TRUE, function errors; if FALSE, function quietly assumes EPSG:4326. If NULL, the default, function assumes EPSG:4326 with a warning.