Convert geographic coordinates (longitude/latitude/height) to geocentric Earth-Centered Earth-Fixed (ECEF) Cartesian coordinates (X/Y/Z), or convert ECEF coordinates back to geographic coordinates.

geocentric_fwd(x, h = 0)

geocentric_rev(x, y, z)

Arguments

x

For forward conversion: a two or three-column matrix or data frame of coordinates (longitude, latitude) or (longitude, latitude, height) in decimal degrees and meters. Can also be a list with lon, lat, and optionally h components. For reverse conversion: numeric vector of X coordinates in meters.

h

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

y

Numeric vector of Y coordinates in meters for reverse conversion.

z

Numeric vector of Z coordinates in meters for reverse conversion.

Value

Data frame with columns:

  • For forward conversion:

    • X, Y, Z: Geocentric ECEF coordinates in meters

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

  • For reverse conversion:

    • lon: Longitude in decimal degrees

    • lat: Latitude in decimal degrees

    • h: Height above ellipsoid in meters

    • X, Y, Z: Input coordinates (echoed)

Details

The geocentric coordinate system (also called ECEF - Earth-Centered Earth-Fixed) is a Cartesian coordinate system with:

  • Origin at the Earth's center of mass

  • X-axis pointing to the intersection of the equator and prime meridian

  • Y-axis pointing to the intersection of the equator and 90°E

  • Z-axis pointing to the North Pole

This coordinate system is commonly used in GPS and satellite applications. All calculations use the WGS84 ellipsoid.

See also

utmups_fwd() for projected coordinates.

Examples

# Convert London to ECEF
geocentric_fwd(c(-0.1, 51.5))
#>         X         Y       Z  lon  lat h
#> 1 3978642 -6944.048 4968362 -0.1 51.5 0

# With height
geocentric_fwd(c(-0.1, 51.5), h = 100)
#>         X         Y       Z  lon  lat   h
#> 1 3978705 -6944.157 4968441 -0.1 51.5 100

# Multiple points
pts <- cbind(lon = c(0, 90, -90), lat = c(0, 0, 0))
geocentric_fwd(pts)
#>         X        Y Z lon lat h
#> 1 6378137        0 0   0   0 0
#> 2       0  6378137 0  90   0 0
#> 3       0 -6378137 0 -90   0 0

# Round-trip
fwd <- geocentric_fwd(c(-0.1, 51.5, 100))
geocentric_rev(fwd$X, fwd$Y, fwd$Z)
#>    lon  lat   h       X         Y       Z
#> 1 -0.1 51.5 100 3978705 -6944.157 4968441