Creates a transformation object that transforms coordinates in a wk pipeline.
proj_trans_create(
source_crs,
target_crs,
use_z = NA,
use_m = NA,
options = character()
)Source/Target CRS definition, coerced with wk::wk_crs_proj_definition()
Used to declare the output type. Use TRUE to
ensure the output has that dimension, FALSE to ensure it does not,
and NA to leave the dimension unchanged.
character vector of "KEY=VALUE" options passed to the PROJ
library when choosing the coordinate operation, see Details
A PROJ transformation object
options are passed to the PROJ library function
proj_create_crs_to_crs_from_pj(). The options PROJ accepts are
AUTHORITY=name restrict candidate operations to one authority (e.g.
"EPSG"), or "any"
ACCURACY=value minimum desired accuracy in metres
ALLOW_BALLPARK=YES/NO set to NO to disallow ballpark
transformations
FORCE_OVER=YES/NO (PROJ >= 9.1.1) set to YES to force the +over
flag, so longitudes are not wrapped to -180..180. This is what you want
when transforming data that straddles the antimeridian, see the example
ONLY_BEST=YES/NO (PROJ >= 9.2) set to YES to error rather than fall
back to a worse operation when the best one needs a grid that is not
available
An option the linked PROJ library predates is dropped with a warning. Any other unrecognized option is an error from PROJ.
(trans <- proj_trans_create("EPSG:4326", "EPSG:3857"))
#> <proj_trans at 0x563095c83500>
#> type: Concatenated Operation
#> id: pipeline
#> description: axis order change (2D) + Popular Visualisation Pseudo-Mercator
#> definition: proj=pipeline step proj=unitconvert xy_in=deg xy_out=rad step proj=webmerc lat_0=0 lon_0=0 x_0=0 y_0=0 ellps=WGS84
#> area_of_use:
#> name: World
#> bounds: [-180 -90 180 90]
#> source_crs:
#> type: Geographic 2D CRS
#> id: EPSG:4326
#> name: WGS 84
#> area_of_use:
#> name: World.
#> bounds: [-180 -90 180 90]
#> target_crs:
#> type: Projected CRS
#> id: EPSG:3857
#> name: WGS 84 / Pseudo-Mercator
#> area_of_use:
#> name: World between 85.06°S and 85.06°N.
#> bounds: [-180 -85.06 180 85.06]
wk::wk_transform(wk::xy(1:5, 1:5), trans)
#> <wk_xy[5]>
#> [1] (111319.5 111325.1) (222639.0 222684.2) (333958.5 334111.2)
#> [4] (445278.0 445640.1) (556597.5 557305.3)
## longitude wrapping at the antimeridian: just past the western edge of
## Web Mercator comes back as +180 by default, -180 with FORCE_OVER
xmin <- -20037508.3427892
inv <- proj_trans_create("EPSG:3857", "EPSG:4326")
wk::wk_transform(wk::xy(xmin - 0.001, 0), inv)
#> <wk_xy[1]>
#> [1] (180 0)
if (proj_version() >= "9.1.1") {
over <- proj_trans_create("EPSG:3857", "EPSG:4326", options = "FORCE_OVER=YES")
wk::wk_transform(wk::xy(xmin - 0.001, 0), over)
}
#> <wk_xy[1]>
#> [1] (-180 0)
library(wk)
(invtrans <- wk_trans_inverse(trans))
#> <proj_trans at 0x563095eb4a10>
#> type: Concatenated Operation
#> id: pipeline
#> description: axis order change (2D) + Popular Visualisation Pseudo-Mercator
#> definition: proj=pipeline step proj=unitconvert xy_in=deg xy_out=rad step proj=webmerc lat_0=0 lon_0=0 x_0=0 y_0=0 ellps=WGS84
#> area_of_use:
#> name: World
#> bounds: [-180 -90 180 90]
#> source_crs:
#> type: Projected CRS
#> id: EPSG:3857
#> name: WGS 84 / Pseudo-Mercator
#> area_of_use:
#> name: World between 85.06°S and 85.06°N.
#> bounds: [-180 -85.06 180 85.06]
#> target_crs:
#> type: Geographic 2D CRS
#> id: EPSG:4326
#> name: WGS 84
#> area_of_use:
#> name: World.
#> bounds: [-180 -90 180 90]
h <- 1852 * 60
## the stretch of Mercator to a square
wk::wk_transform(wk::xy(c(-h * 180, 0, h * 180), c(-h * 180,0, h * 180)), invtrans)
#> <wk_xy[3]>
#> [1] (-179.6774 -85.02322) ( 0.0000 0.00000) ( 179.6774 85.02322)