Convert between geographic coordinates and a local Cartesian coordinate system centered at a specified origin. The local system uses East-North-Up (ENU) axes.

localcartesian_fwd(x, lon0, lat0, h = 0, h0 = 0)

localcartesian_rev(x, y, z, lon0, lat0, h0 = 0)

Arguments

x

For forward conversion: a two-column matrix or data frame of coordinates (longitude, latitude) in decimal degrees, or a list with longitude and latitude components. Can also be a length-2 numeric vector for a single point. For reverse conversion: numeric vector of x (east) coordinates in meters.

lon0

Longitude of the origin in decimal degrees.

lat0

Latitude of the origin in decimal degrees.

h

Numeric vector of heights above the ellipsoid in meters. Default is 0.

h0

Height of the origin above the ellipsoid in meters. Default is 0.

y

Numeric vector of y (north) coordinates in meters.

z

Numeric vector of z (up) coordinates in meters.

Value

  • localcartesian_fwd(): Data frame with columns:

    • x: East coordinate in meters

    • y: North coordinate in meters

    • z: Up coordinate in meters

    • lon, lat, h: Input coordinates (echoed)

  • localcartesian_rev(): Data frame with columns:

    • lon: Longitude in decimal degrees

    • lat: Latitude in decimal degrees

    • h: Height above ellipsoid in meters

    • x, y, z: Input coordinates (echoed)

Details

The local Cartesian coordinate system is useful for:

  • Local surveys where a flat Earth approximation is valid

  • Converting GPS positions to a local reference frame

  • Robotics and navigation applications

The coordinate system is:

  • x: positive east

  • y: positive north

  • z: positive up (away from Earth's center)

This is also known as an ENU (East-North-Up) coordinate system.

See also

geocentric_fwd() for Earth-Centered Earth-Fixed (ECEF) coordinates

Examples

# Set up local system centered on London
london <- c(-0.1, 51.5)

# Convert nearby points to local coordinates
pts <- cbind(
  lon = c(-0.1, -0.2, 0.0),
  lat = c(51.5, 51.6, 51.4)
)
localcartesian_fwd(pts, lon0 = london[1], lat0 = london[2])
#>           x         y         z  lon  lat h
#> 1     0.000      0.00   0.00000 -0.1 51.5 0
#> 2 -6928.841  11130.61 -13.47326 -0.2 51.6 0
#> 3  6959.234 -11120.93 -13.48954  0.0 51.4 0

# Round-trip conversion
fwd <- localcartesian_fwd(pts, lon0 = -0.1, lat0 = 51.5)
localcartesian_rev(fwd$x, fwd$y, fwd$z, lon0 = -0.1, lat0 = 51.5)
#>             lon  lat             h         x         y         z
#> 1 -1.000000e-01 51.5 -1.409643e-09     0.000      0.00   0.00000
#> 2 -2.000000e-01 51.6  0.000000e+00 -6928.841  11130.61 -13.47326
#> 3  5.577971e-18 51.4 -1.409635e-09  6959.234 -11120.93 -13.48954