
Create an sf object from UTM coordinates, handling multiple zones correctly.
Source:R/create_sf_from_utm.R
create_sf_from_utm.RdThis function takes a data frame with UTM coordinates (xcoord, ycoord) and a utmzone column, and creates an sf object with the correct CRS for each zone.
Arguments
- df
A data frame with numeric columns
xcoord(easting),ycoord(northing) andutmzone, and a character columnhemisphere("S"for the southern hemisphere; any other value is treated as northern).- output_crs
(Optional) The EPSG code or CRS string for the desired output CRS. If NULL, the CRS of the first UTM zone will be used.
Examples
# \donttest{
df <- data.frame(
xcoord = c(500000, 501000),
ycoord = c(5600000, 5601000),
utmzone = c(32, 32),
hemisphere = c("North", "North")
)
sf_obj <- create_sf_from_utm(df, output_crs = "EPSG:4326")
# }