Creates a transformation object that transforms coordinates in a wk pipeline.

proj_trans_create(source_crs, target_crs, use_z = NA, use_m = NA)

Arguments

source_crs, target_crs

Source/Target CRS definition, coerced with wk::wk_crs_proj_definition()

use_z, use_m

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.

Value

A PROJ transformation object

Examples

(trans <- proj_trans_create("EPSG:4326", "EPSG:3857"))
#> <proj_trans at 0x562ab060f460>
#> 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)

library(wk)
(invtrans <- wk_trans_inverse(trans))
#> <proj_trans at 0x562ab00944b0>
#> 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)