Transforms all coordinates in x using wk::wk_handle() and proj_trans_create().

proj_trans(x, target_crs, source_crs = NULL, ..., use_z = NA, use_m = NA)

Arguments

x

Input geometry/geography. May take any of the following forms:

  • A coordinate matrix containing 2, 3 or 4 columns. If named, expects column names "x", "y" and optionally "z" and/or "m". If not named, columns are assumed in xyzm order. Non-coordinate columns are removed.

  • A data.frame containing coordinates as columns. Expects names "x", "y" and optionally "z" and/or "m". Non-coordinate columns are retained.

  • A data.frame containing a geometry vector which is readable by wk::wk_handle(), including sfc columns.

  • A geometry vector which is readable by wk::wk_handle(), including sfc columns.

source_crs, target_crs

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

...

Additional parameters forwarded to wk::wk_handle()

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

Transformed geometries whose format is dependent on input.

Details

Values that are detected out of bounds by library PROJ are allowed, we return Inf in this case, rather than the error "tolerance condition error".

References

see the PROJ library documentation for details on the underlying functionality

Examples

proj_trans(cbind(147, -42), "+proj=laea +type=crs", "EPSG:4326")
#>            x        y
#> [1,] 5969744 -9803200
proj_trans(cbind(147, -42, -2), "+proj=laea +type=crs", "EPSG:4326")
#>            x        y  z
#> [1,] 5969744 -9803200 -2
proj_trans(cbind(147, -42, -2, 1), "+proj=laea +type=crs", "EPSG:4326")
#>            x        y  z m
#> [1,] 5969744 -9803200 -2 1
proj_trans(wk::xy(147, -42, crs = "EPSG:4326"), "+proj=laea +type=crs")
#> <wk_xy[1] with CRS=+proj=laea +type=crs>
#> [1] (5969744 -9803200)
proj_trans(wk::wkt("POLYGON ((1 1, 0 1, 0 0, 1 0, 1 1))", crs = "EPSG:4326"), 3112)
#> <wk_wkt[1] with CRS=EPSG:3112>
#> [1] POLYGON ((-1.351177e+07 -7779443, -1.357183e+07 -7887200, -1.346498e+07 -7946204, -1.340539e+07 -7839296, -1.351177e+07 -7779443))