degree: decimal degree coordinate conversion

Description Usage Arguments Value Author(s) See Also Examples

Description

Convert latitude-longitude coordinates between decimal representation and degree-minute-second notation

Usage

1
2
degree(lat, long, data, todms = !is.character(lat), digits = 1,
  drop = FALSE)

Arguments

lat, long

Latitude (North/South) and longitude (East/West) coordinates in decimal degrees

data

Optional: data.frame with the columns lat and long

todms

Logical specifying direction of conversion. If FALSE, converts to decimal degree notation, splitting coordinates at the symbols for degree, minute and second (\U00B0, ', "). DEFAULT: !is.character(lat)

digits

Number of digits the seconds are rounded to. DEFAULT: 1

drop

Drop to lowest dimension? DEFAULT: FALSE

Value

data.frame with x and y as character strings or numerical values, depending on conversion direction

Author(s)

Berry Boessenkool, berry-b@gmx.de, Aug 2016

See Also

earthDist, projectPoints for geographical reprojection, sp::char2dms

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# DECIMAL to DMS notation: --------------------------------------------------
degree(52.366360, 13.024181)
degree(c(52.366360, -32.599203), c(13.024181,-55.809601))
degree(52.366360, 13.024181, drop=TRUE) # vector
degree(47.001, -13.325731, digits=5)

# Use table with values instead of single vectors:
d <- read.table(header=TRUE, sep=",", text="
lat, long
 52.366360,  13.024181
-32.599203, -55.809601")
degree(lat, long, data=d)

# DMS to DECIMAL notation: --------------------------------------------------
# You can use the degree symbol and escaped quotation mark (\") as well.
degree("52'21'58.9'N", "13'1'27.1'E")
print(degree("52'21'58.9'N", "13'1'27.1'E"), digits=15)

d2 <- read.table(header=TRUE, stringsAsFactors=FALSE, text="
lat long
52'21'58.9'N 13'01'27.1'E
32'35'57.1'S 55'48'34.6'W") # columns cannot be comma-separated!
degree(lat, long, data=d2)

# Rounding error checks: ----------------------------------------------------
oo <- options(digits=15)
d
degree(lat, long, data=degree(lat, long, d))
degree(lat, long, data=degree(lat, long, d, digits=3))
options(oo)
stopifnot(all(degree(lat,long,data=degree(lat,long,d, digits=3))==d))

OSMscale documentation built on May 2, 2019, 8:35 a.m.