how to convert latitudes longitudes(in degrees,minutes,seconds) to utm coordinates

I have a set of data in excel. That data is of latitudes and longitudes of various points. I want to convert them into UTM coordinates and then plot them on a map. How to convert these latitudes and longitudes(degrees,minutes,seconds) into utm coordinates ?

This is an unusual use case; latitude and longitude is in most cases enough to draw on a map, and when you convert to an UTM zone coordinates you usually have a specific zone in mind. But unusual does not mean impossible.

I am using a toy example of plotting the location of statue of Sir Winston Churchill in front of the Prague School of Economics.

The first step is convert your regular data frame to a spatial structure: for this use sf::st_transform(), if your data is in lat / lon specify as CRS 4326 (this is the EPSG code for WGS84).

Note that at this point your coordinates should be good for most point mapping use cases - see the leaflet printscreen I used to double check (I am terrible at remembering the order of latitude and longitude; I swap them all of the time and need to check often).

To project to a UTM zone coordinates it is easiest to specify projection via a PROJ4 string of a sf::st_transform() call.

Note that it is technically possible to project a point to more zones than one - in my toy example I project sir Winston both to zone 33 (which is the appropriate zone for Prague) and to zone 34 (which is not). Note that the code will work (coordinates are projected) in both cases = it is necessary to have some idea what is your UTM zone of interest.

library(sf)
library(tidyverse)
library(leaflet)

# input data - your excel should look like this
src_data <- data.frame(landmark = "Statue of Winston Churchill",
                       lon = 14.4411733,
                       lat = 50.0845878)

# transform "regular" data to spatial data frame (sf)
sir_winston <- src_data %>% 
  sf::st_as_sf(coords = c("lon", "lat"), crs = 4326)

# check structure (and CRS)
print(sir_winston)

Simple feature collection with 1 feature and 1 field
geometry type:  POINT
dimension:      XY
bbox:           xmin: 14.44117 ymin: 50.08459 xmax: 14.44117 ymax: 50.08459
geographic CRS: WGS 84
                     landmark                  geometry
1 Statue of Winston Churchill POINT (14.44117 50.08459)

# double check: draw a point on map (yup, it is him!)
leaflet(sir_winston) %>% 
  addProviderTiles("Stamen.Toner") %>% 
  addCircleMarkers(stroke = F, fillOpacity = 1)

# project sir winston to UTM zone 33
sir_winston_33 <- sir_winston %>% 
  sf::st_transform(crs = "+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs")

print(sir_winston_33)

Simple feature collection with 1 feature and 1 field
geometry type:  POINT
dimension:      XY
bbox:           xmin: 460020.9 ymin: 5548185 xmax: 460020.9 ymax: 5548185
CRS:            +proj=utm +zone=33 +datum=WGS84 +units=m +no_defs
                     landmark                 geometry
1 Statue of Winston Churchill POINT (460020.9 5548185)

# project sir winston to UTM zone 34
sir_winston_34 <- sir_winston %>% 
  sf::st_transform(crs = "+proj=utm +zone=34 +datum=WGS84 +units=m +no_defs")

print(sir_winston_34)

Simple feature collection with 1 feature and 1 field
geometry type:  POINT
dimension:      XY
bbox:           xmin: 30955.23 ymin: 5568668 xmax: 30955.23 ymax: 5568668
CRS:            +proj=utm +zone=34 +datum=WGS84 +units=m +no_defs
                     landmark                 geometry
1 Statue of Winston Churchill POINT (30955.23 5568668)

To triple check that all three points are the same I draw the three versions of sir Winston within a polygon of Prague city borders (I vary the size & color of the dot to make it easy to see it marks the same spot)

library(tmap)

tm_shape(subset(RCzechia::kraje(), KOD_CZNUTS3 == "CZ010")) + tm_polygons() +
  tm_shape(sir_winston) + tm_dots(size = 6, col = "red") +
  tm_shape(sir_winston_33) + tm_dots(size = 3, col = "blue") +
  tm_shape(sir_winston_34) + tm_dots(size = 1, col = "green")

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.