Skip to contents

Transform longitude/latitude columns to an equal-distance UTM coordinate reference system with sf::st_transform().

Usage

add_utm_columns(
  dat,
  ll_names = c("longitude", "latitude"),
  ll_crs = 4326,
  utm_names = c("X", "Y"),
  utm_crs = get_crs(dat, ll_names),
  units = c("km", "m")
)

Arguments

dat

Data frame containing longitude and latitude columns.

ll_names

Character names of longitude then latitude columns.

ll_crs

Input coordinate reference system.

utm_names

Names for the two new coordinate columns.

utm_crs

Output UTM CRS; by default inferred with get_crs().

units

Output coordinate units: kilometres or metres.

Value

A copy of dat with the requested UTM coordinate columns.

Examples

d <- data.frame(lat = c(52.1, 53.4), lon = c(-130, -131.4))
add_utm_columns(d, c("lon", "lat"))
#> Using UTM zone 9N (EPSG:32609).
#>    lat    lon        X        Y
#> 1 52.1 -130.0 431.5034 5772.632
#> 2 53.4 -131.4 340.4411 5919.452