Last active
July 26, 2021 16:53
-
-
Save lehostert/715c8ce5568f048c0810ae0569883e1e to your computer and use it in GitHub Desktop.
Convert Geo Coordinates from Degree-Decimal-Minutes to Decimal-Degrees
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Example function for converting geo coordinates from degree-decimal minutes to decimal degrees. | |
## For full discussion please see StackOverflow #14404596 | |
## https://stackoverflow.com/questions/14404596/converting-geo-coordinates-from-degree-to-decimal | |
library(tidyr) | |
library(dplyr) | |
df <- tribble( | |
~site, ~lat, ~lon, | |
"105252", "30°25.264", "9°01.331", | |
"105253", "30°39.237", "8°10.811", | |
"105255", "31°37.760", "8°06.040", | |
"105258", "31°41.190", "8°06.557", | |
"105259", "31°41.229", "8°06.622", | |
"105260", "31°38.891", "8°06.281",) | |
# unicode for degree symbol | |
# deg <- "\u00b0" | |
deg_decmin_to_decdeg <- function(df) { | |
x <- df %>% | |
separate(lat, paste("lat",c("d","m"), sep= "_"), sep="\u00b0") %>% | |
separate(lon, paste("lon",c("d","m"), sep= "_"), sep="\u00b0") %>% | |
mutate(lat_d = as.numeric(lat_d), | |
lat_m = as.numeric(lat_m), | |
lon_d = as.numeric(lon_d), | |
lon_m = as.numeric(lon_m)) %>% | |
transmute(site = site, | |
lat_dec = lat_d + lat_m/60, | |
lon_dec = lon_d + lon_m/60) | |
return(x) | |
} | |
cord2 <- deg_decmin_to_decdeg(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment