bbox_transform() is a convenience function to transform the coordinates
of a boundary from their current spatial reference system to a new target
spatial reference system.
Arguments
- bbox
Numeric vector of length four containing a bounding box (xmin, ymin, xmax, ymax) to transform.
- srs_from
Character string specifying the spatial reference system for
pts. May be in WKT format or any of the formats supported bysrs_to_wkt().- srs_to
Character string specifying the output spatial reference system. May be in WKT format or any of the formats supported by
srs_to_wkt().- use_transform_bounds
Logical value,
TRUEto usetransform_bounds()(the default, requires GDAL >= 3.4). IfFALSE, transformation is done withg_transform().
Details
With use_transform_bounds = TRUE (the default) this function returns:
See Details for transform_bounds() for cases where the bounds crossed the
antimeridian.
With use_transform_bounds = FALSE, this function returns:
See the Note for g_transform() for cases where the bounds crossed the
antimeridian.
Examples
bb <- c(-1405880.72, -1371213.76, 5405880.72, 5371213.76)
# the default assumes GDAL >= 3.4
if (gdal_version_num() >= gdal_compute_version(3, 4, 0)) {
bb_wgs84 <- bbox_transform(bb, "EPSG:32661", "EPSG:4326")
} else {
bb_wgs84 <- bbox_transform(bb, "EPSG:32661", "EPSG:4326",
use_transform_bounds = FALSE)
}
print(bb_wgs84)
#> [1] -180.00000 48.65641 180.00000 90.00000