Transform or convert coordinates of a simple feature or bounding box object
Source:R/st_transform_ext.R
st_transform_ext.Rd
This function wraps sf::st_transform()
but supports a wider range of input
objects and, using the as_sf_class()
function, returns a wider range of
objects. Typically, takes a sf
, sfc
, or bbox
object and transform to
coordinate reference system to match the value of crs or the object provided
to crs. If x
is a data.frame or if x
is NULL
and allow_null
is TRUE
(defaults to FALSE
) it is returned as is.
Usage
st_transform_ext(
x,
crs = NULL,
class = NULL,
rotate = 0,
allow_null = FALSE,
allow_list = TRUE
)
st_omerc(x, rotate = 0)
st_wgs84(x)
Arguments
- x
An
sf
,sfc
, orbbox
object, a list of sf objects, or adata.frame
object (always returned as is).- crs
A character or numeric reference to a coordinate reference system supported by
sf::st_crs()
or anothersf
,sfc
, orbbox
object that is used to provide crs.- class
Class of object to return (
sf
orbbox
). If x is an sf list, the returned object remains a list but may be converted tobbox
ifclass = "sf"
.- rotate
If rotate is greater or less than 0,
st_transform_ext()
callsst_omerc()
and returns an object with the Oblique Mercator projection passing the value of rotate to the gamma parameter of the projection. rotate must be between -45 and 45 degrees.- allow_null
If
TRUE
and x isNULL
return x without an error. Defaults toFALSE
.- allow_list
If
TRUE
, x can be a list ofsf
,sfc
, orbbox
objects. IfFALSE
, onlysf
,sfc
, orbbox
objects are supported. Defaults toTRUE
.
Examples
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf"))
nc_bbox <- sf::st_bbox(nc)
nc_3857 <- st_transform_ext(nc, 3857)
st_transform_ext(nc_bbox, crs = 4326)
#> xmin ymin xmax ymax
#> -84.32379 33.88210 -75.45656 36.58981
sf::st_crs(st_transform_ext(nc_3857, crs = nc))$input
#> [1] "NAD27"
sf::st_crs(st_wgs84(nc_3857))$input
#> [1] "EPSG:4326"