| 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] (ORCID: <https://orcid.org/0000-0002-2471-7511>), 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.7.0.9006 |
| Built: | 2026-10-15 11:47:47 UTC |
| Source: | https://github.com/hypertidy/PROJ |
Test for availability of 'PROJ' system library version 6 or higher.
ok_proj6()ok_proj6()
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.
logical, TRUE if the system library 'PROJ >= 6'
ok_proj6()ok_proj6()
Input any accepted format of 'PROJ' coordinate reference system specification. Return value is a string in the requested format.
proj_crs_text(source, format = 0L)proj_crs_text(source, format = 0L)
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' |
See the library documentation for details on input and output formats.
character string in requested format
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".
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)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)
Returns the path of the proj.db that the PROJ library resolves, its metadata (the PROJ version that built it, database layout version, EPSG version), whether the copy of PROJ data bundled with this package (if any) is active, and the PROJ library version.
proj_data_info()proj_data_info()
If path is NA the library cannot find a usable proj.db: EPSG codes and
other database lookups will fail, though '+proj=' strings still work.
a list with elements 'db' (named character), 'bundled_active' (logical), 'proj_version' (character), and 'message' (character, or NULL): the startup message explaining why a bundled copy was ignored, if that happened
proj_data_info()proj_data_info()
Computes map projection factors (distortion measures) for a set of geographic coordinates and a given projected CRS. Returns a matrix with one row per input coordinate and one column per factor.
proj_factors(lp, crs)proj_factors(lp, crs)
lp |
A two-column numeric matrix of geographic coordinates (longitude, latitude) in decimal degrees. |
crs |
A PROJ CRS definition string for the target projection
(e.g. a PROJ string, WKT, or authority code such as |
Rows for coordinates where the factors computation fails (for
example latitudes outside +/-90) are filled with NaN. Missing input
coordinates give NA output.
A numeric matrix with nrow(lp) rows and the following columns:
Meridional scale factor (h)
Parallel scale factor (k)
Areal scale factor (s)
Angular distortion (omega), in radians
Meridian-parallel angle (theta prime), in radians
Meridian convergence (conv), in radians
Tissot semimajor axis (a)
Tissot semiminor axis (b)
Partial derivative dx/dlambda
Partial derivative dx/dphi
Partial derivative dy/dlambda
Partial derivative dy/dphi
# Lambert Azimuthal Equal Area proj_factors(cbind(147, -42), "+proj=laea +lon_0=147 +lat_0=-42 +type=crs") # Multiple coordinates pts <- cbind(c(130, 147, 160), c(-20, -42, -35)) proj_factors(pts, "EPSG:3112")# Lambert Azimuthal Equal Area proj_factors(cbind(147, -42), "+proj=laea +lon_0=147 +lat_0=-42 +type=crs") # Multiple coordinates pts <- cbind(c(130, 147, 160), c(-20, -42, -35)) proj_factors(pts, "EPSG:3112")
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, options = character() )proj_trans( x, target_crs, source_crs = NULL, ..., use_z = NA, use_m = NA, options = character() )
x |
Input geometry/geography. May take any of the following forms:
|
source_crs, target_crs
|
Source/Target CRS definition, coerced with |
... |
Additional parameters forwarded to |
use_z, use_m
|
Used to declare the output type. Use |
options |
character vector of |
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".
Transformed geometries whose format is dependent on input.
see the PROJ library documentation for details on the underlying functionality
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)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)
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() )proj_trans_create( source_crs, target_crs, use_z = NA, use_m = NA, options = character() )
source_crs, target_crs
|
Source/Target CRS definition, coerced with |
use_z, use_m
|
Used to declare the output type. Use |
options |
character vector of |
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.
A PROJ transformation object
(trans <- proj_trans_create("EPSG:4326", "EPSG:3857")) wk::wk_transform(wk::xy(1:5, 1:5), trans) ## 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) 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) } 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)(trans <- proj_trans_create("EPSG:4326", "EPSG:3857")) wk::wk_transform(wk::xy(1:5, 1:5), trans) ## 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) 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) } 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)
This function returns NA if PROJ lib is not available.
proj_version()proj_version()
character string (major.minor.patch)
proj_version()proj_version()
A copy of the xymap data set from the quadmesh package.
A matrix of longitude/latitude values of the world coastline.