
Convert Degrees, Minutes, Seconds (DMS) to Decimal Degrees (DD)
dms_to_decimal.RdThis function converts geographic coordinates from Degrees, Minutes, and Seconds (DMS) format to Decimal Degrees (DD). The input can be either a data frame with separate columns for degrees, minutes, and seconds, or a single column with DMS represented by symbols (e.g., 34°30'45"N).
Arguments
- data
A data frame containing either separate columns for degrees, minutes, and seconds, or a single column with DMS formatted values for latitude and longitude.
- lat_col
The name of the column representing latitude or vector. It can either be a single column with DMS notation or separate columns for degrees.
- lon_col
The name of the column representing longitude. It can either be a single column with DMS notation or separate columns for degrees.
- is_dms_symbol
If TRUE (default), assumes the latitude and longitude columns are in DMS notation with symbols (e.g.,
34°30'45"N).- verbose
Logical. If
TRUE, prints messages about the conversion process. Default isFALSE.
Value
A data frame with two new columns: lat_dd for latitude in decimal degrees and lon_dd for longitude in decimal degrees.
Examples
# Example with DMS symbol notation
data <- data.frame(
latitude = c("34°30'00\"N", "40°45'00\"N"),
longitude = c("118°15'00\"W", "73°58'00\"W")
)
result <- dms_to_decimal(data, "latitude", "longitude", is_dms_symbol = TRUE)
print(result)
#> latitude longitude lat_dd lon_dd
#> 1 34°30'00"N 118°15'00"W 34.50 -118.25000
#> 2 40°45'00"N 73°58'00"W 40.75 -73.96667
# Example with separate columns
data <- data.frame(
lat_deg = c(34, 40),
lat_min = c(30, 45),
lat_sec = c(0, 0),
lon_deg = c(118, 73),
lon_min = c(15, 58),
lon_sec = c(0, 0)
)
result <- dms_to_decimal(data, "lat_deg", "lon_deg", is_dms_symbol = FALSE)
#> Error in get(paste0(lat_col, "_min")): object 'lat_deg_min' not found
print(result)
#> latitude longitude lat_dd lon_dd
#> 1 34°30'00"N 118°15'00"W 34.50 -118.25000
#> 2 40°45'00"N 73°58'00"W 40.75 -73.96667