Learn R Programming

RandomFields (version 3.0.5)

RMtrafo: Transformation of coordinate systems

Description

The functions transform a coordinate system into another. Currently, essentially only from the earth system to cartesian. RMtrafo is the internal basic function that also allows to reduce vectors to their norm.

Usage

RMtrafo(phi, isotropy)
RFearth2cartesian(coord, units=NULL, system="cartesian", grid=FALSE)
RFearth2dist(coord, units=NULL, system="cartesian", grid=FALSE, ...)

Arguments

isotropy
integer or character. One of the values RC_ISOTROPIC, RC_SPACEISOTROPIC,
phi
optional submodel
coord
matrix or vector of earth coordinates
units
"km" or "miles"; if not given and RFoptions()$general$units != "" the latter is used. Otherwise "km".
system
integer or character. The coordinate system, e.g. "cartesian", "gnomonic", or "orthographic".
grid
logical. Whether the given coordinates are considered to be on a grid given by c(start, step, length).

Default: FALSE

...
the optional arguments of dist

Value

  • The function RMtrafo returns a matrix, in general. For fixed column, the results, applied to each row of the matrix, are returned.

    The function RFearth2cartesian returns a matrix in one-to-one correspondance with coord assuming that the earth is an ellipsoid.

    The function RFearth2dist calculates distances, cf. dist, assuming that the earth is an ellipsoid.

Details

The functions transform between different coordinate systems.

References

For calculating the earth coordinates as ellipsoid:
  • en.wikipedia.org/wiki/Geographic_coordinate_system
  • nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html

See Also

link{constants}, RMangle

Examples

Run this code
data(weather)
(coord <- weather[1:5, 3:4])

(z <- RFfctn(RMtrafo(isotropy=RC_CARTESIAN_COORD), coord))
(z1 <- RFearth2cartesian(coord)) ## equals t(z)
z1 - t(z) ## 0, i.e., z1 and t(z) are the same
dist(t(z))


(d <- RFearth2dist(coord)) 
d - dist(t(z)) ## 0, i.e., d and dist(t(z)) are the same


## projecction onto planes
RFoptions(zenit=c(-122,   47))
RFearth2cartesian(coord, system="gnomonic")
RFearth2cartesian(coord, system="orthographic")

\dontrun{ # OK

## RFearth2dist is more precise !!!
library("fields")
(unix.time(z2 <- rdist.earth(coord, miles=FALSE)))
z2

(z2 - as.matrix(d)) / z2 * 100 ## RFearth2dist is more precise


# 
n <- 10000
unix.time(for (i in 1:n) d <- RFearth2dist (coord))) ## the same as dist(t(z))

unix.time(for (i in 1:n)z2 <- rdist.earth(xx)))


data(weather)
xx <- matrix(weather[, 3:4], ncol=2) [ 1:5, ]

xx <- weather[, 3:4][ 1:5, ]
Print(xx)
Print(yy <- RFfctn(RMtrafo(isotropy=RC_CARTESIAN_COORD), xx), units="miles")

(z1 <- as.matrix(dist(t(yy))))

library(fields)
(z2 <- rdist.earth(xx))

(z1-z2) / z1 * 100
z1
}


FinalizeExample()

Run the code above in your browser using DataLab