Package 'proj4'

Title: A simple interface to the PROJ.4 cartographic projections library
Description: A simple interface to lat/long projection and datum transformation of the PROJ.4 cartographic projections library. It allows transformation of geographic coordinates from one projection and/or datum to another.
Authors: Simon Urbanek <[email protected]>
Maintainer: Simon Urbanek <[email protected]>
License: GPL-2
Version: 1.0-14
Built: 2024-11-19 06:43:03 UTC
Source: CRAN

Help Index


Projection of coordinates

Description

Projection of lat/long coordinates or its inverse.

Usage

project(xy, proj, inverse = FALSE, degrees = TRUE, silent = FALSE,
        ellps.default="sphere")

Arguments

xy

input (list, matrix or 2d-array) - see details below.

proj

projection definition

inverse

if TRUE inverse projection is performed (from a cartographic projection into lat/long), otherwise projects from lat/long into a cartographic projection.

degrees

if TRUE then the lat/long data is assumed to be in degrees, otherwise in radians

silent

if set to TRUE, warnings will be suppressed

ellps.default

default ellipsoid that will be added if no datum or ellipsoid parameter is specified in proj. Older versions of PROJ.4 didn't require a datum (and used sphere by default), but 4.5.0 and higher always require a datum or an ellipsoid. Set to NA if no datum should be added to proj (e.g. if you specify an ellipsoid directly).

Details

The input can be a list of two or more vectors (if the list contains more than two entries, only first two entries are used and a warning is issued), a two-dimensional matrix or array (the number of columns or rows must be exactly two) or a vector of the length 2. For a 2x2 input the columns are taken as x and y. If the input is a list then the result will be a list with the entries named x and y, otherwise the result is a matrix with two columns.

When the list form is used, inputs are recycled with a warning when necessary.

proj specifies the target (or source if inverse) projection. The format can be either a single (unnamed) string which contains all parameters: "+proj=lcc +lat_1=33 +lat_2=45 +lat_0=39 +lon_0=-96" or an unnamed vector of complete individual parameters: c("+proj=lcc","+lat_1=33","+lat_2=45","+lat_0=39","+lon_0=-96") or a named vector or list that will be composed into parameters: list(proj="lcc", lat_1=33, lat_2=45, lat_0=39, lon_0=-96)

if degrees is TRUE then the latitude and longitude are expected to be in degrees, if FALSE then in radians.

Value

A two column matrix or list of coordinates. If the input was a list then the output will be a list, otherwise a matrix.

References

https://proj.org/

Examples

## this is just very simple, because we don't want to depend on
## maps package, so we can't show more useful stuff..
data(state)
s <- project(state.center, "+proj=merc")
plot(s, type='n', asp=1)
text(s,, state.abb)

Transform geographic coordinates from one projection into another

Description

Transformation of geographics coordinates from one projection to another, using PROJ.4 library.

Usage

ptransform(data, src.proj, dst.proj, silent=TRUE)

Arguments

data

input (list, matrix or 2d-array) - see details below.

src.proj

description of the source projection

dst.proj

description of the destination projection

silent

if set to TRUE, warnings will be suppressed

Details

The data can be a list of vectors (if the list contains more than three entries, only first three entries are used and a warning is issued), a two-dimensional matrix or array (the number of columns or rows must be at most three). If the input is a list then the result will be a list with the entries named x, y and z, otherwise the result is a matrix with three columns.

When the list form is used, inputs are recycled with a warning when necessary. All unspecified coordinates are set to zero.

Note that the project specification must include an ellipsoid or a datum. Add ellps='sphere' to obtain the same result as older PROJ.4 versions with no datum specification.

Datum files must be installed in order to be able to perform datum shifts (on Windows they should be located in c:\proj) - see PROJ.4 website for the download of datum files.

Value

A matrix with three columns or list with projected coordinates. If the input was a list then the output will be a list, otherwise a matrix.

Author(s)

Simon Urbanek

References

https://proj.org/

Examples

data(state)
sc <- cbind(state.center$x, state.center$y)
## this is essentially the same as project except
## that the default lat/long input is in radians
tr <- ptransform(sc/180*pi, '+proj=latlong +ellps=sphere',
                 '+proj=merc +ellps=sphere')
## we can compare it with the project result
res <- project(sc, c(proj="merc"))
## ptransform has z coordinate which is 0 for this projection
summary(tr - cbind(res, 0))