Package 'PROJ'

Title: Generic Coordinate System Transformations Using 'PROJ'
Description: A wrapper around the generic coordinate transformation software 'PROJ' that transforms coordinates from one coordinate reference system ('CRS') to another. This includes cartographic projections as well as geodetic transformations. The intention is for this package to be used by user-packages such as 'reproj', and that the older 'PROJ.4' and version 5 pathways be provided by the 'proj4' package.
Authors: Michael D. Sumner [aut, cre] , Jeroen Ooms [ctb] (provided PROJ library support on Windows, and assistance with Windows configuration), Simon Urbanek [cph, ctb] (wrote original code versions for PROJ version 6), Dewey Dunnington [ctb] (key code contributions), Anthony North [ctb]
Maintainer: Michael D. Sumner <[email protected]>
License: GPL-3
Version: 0.5.0
Built: 2024-11-09 03:52:37 UTC
Source: https://github.com/hypertidy/PROJ

Help Index


Is 'PROJ library >= 6' available

Description

[Deprecated]

Test for availability of 'PROJ' system library version 6 or higher.

Usage

ok_proj6()

Details

On unix-alikes, this function is run in .onLoad() to check that version 6 functionality is available. On Windows, the load process sets the data file location with the version 6 API, and that is used as a test instead.

If 'PROJ' library version 6 is not available, the package still compiles and installs but is not functional.

The lack of function can be simulated by setting options(reproj.mock.noproj6 = TRUE), designed for use with the reproj package.

Value

logical, TRUE if the system library 'PROJ >= 6'

Examples

ok_proj6()

Generate a projection string.

Description

Input any accepted format of 'PROJ' coordinate reference system specification. Return value is a string in the requested format.

Usage

proj_crs_text(source, format = 0L)

Arguments

source

input projection specification one of ('PROJ4', 'WKT2', 'EPSG', 'PROJJSON', ... see the library documentation link in Details)

format

integer, 0 for 'WKT', 1 for 'PROJ', 2 for 'PROJJSON'

Details

This function requires PROJ version 6.0 or higher to be useful. If not, this function simply returns 'NA'.

See the library documentation for details on input and output formats.

Value

character string in requested format

warning

Note that a PROJ string is not a full specification, in particular this means that a string like "+proj=laea" cannot be converted to full WKT, because it is technically a transformation step not a crs. To get the full WKT form use a string like "+proj=laea +type=crs".

Examples

cat(proj_crs_text("EPSG:4326", format = 0L))
proj_crs_text("EPSG:4326", format = 1L)
south55 <- "+proj=utm +zone=55 +south +ellps=GRS80 +units=m +no_defs +type=crs"
proj_crs_text(proj_crs_text(south55), 1L)

Transform coordinates

Description

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

Usage

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.

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".

Value

Transformed geometries whose format is dependent on input.

References

see the PROJ library documentation for details on the underlying functionality

Examples

proj_trans(cbind(147, -42), "+proj=laea +type=crs", "EPSG:4326")
proj_trans(cbind(147, -42, -2), "+proj=laea +type=crs", "EPSG:4326")
proj_trans(cbind(147, -42, -2, 1), "+proj=laea +type=crs", "EPSG:4326")
proj_trans(wk::xy(147, -42, crs = "EPSG:4326"), "+proj=laea +type=crs")
proj_trans(wk::wkt("POLYGON ((1 1, 0 1, 0 0, 1 0, 1 1))", crs = "EPSG:4326"), 3112)

Create a transformation object

Description

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

Usage

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"))
wk::wk_transform(wk::xy(1:5, 1:5), trans)

library(wk)
(invtrans <- wk_trans_inverse(trans))

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)

Report PROJ library version

Description

This function returns NA if PROJ lib is not available.

Usage

proj_version()

Value

character string (major.minor.patch)

Examples

proj_version()

xymap data for testing

Description

A copy of the xymap data set from the quadmesh package.

Details

A matrix of longitude/latitude values of the world coastline.