Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

char2dms

Convert character vector to DMS-class object


Description

These two helper functions convert character vectors and decimal degree vectors to the DMS-class representation of degrees, minutes, and decimal seconds. "DMS" objects cannot contain NAs.

Usage

char2dms(from, chd = "d", chm = "'", chs = "\"")
dd2dms(dd, NS = FALSE)

Arguments

from

character vector of degree, minute, decimal second data

chd

degree character terminator

chm

minute character terminator

chs

second character terminator

dd

numeric vector of decimal degrees

NS

logical, TRUE for north/south decimal degrees, FALSE for east/west decimal degrees

Details

In char2dms, the input data vector should use a regular format, such as that used in the PROJ.4 library, with a trailing capital (NSWE) indicating compass direction.

Value

Both functions return a "DMS" object.

Methods

from = "DMS", to = "numeric"

coerce a "DMS" object to a "numeric" vector

from = "DMS", to = "character"

coerce a "DMS" object to a "character" vector (the as.character.DMS S3 method is also available)

Author(s)

Roger Bivand Roger.Bivand@nhh.no

See Also

Examples

data(state)
str(state.center$y)
stateN <- dd2dms(state.center$y, NS=TRUE)
str(attributes(stateN))
ch.stateN <- as.character(stateN)
str(ch.stateN)
stateNa <- char2dms(ch.stateN)
str(attributes(stateNa))
ch.stateN <- as(stateN, "character")
str(ch.stateN)
stateNa <- char2dms(ch.stateN)
str(attributes(stateNa))

sp

Classes and Methods for Spatial Data

v1.4-5
GPL (>= 2)
Authors
Edzer Pebesma [aut, cre], Roger Bivand [aut], Barry Rowlingson [ctb], Virgilio Gomez-Rubio [ctb], Robert Hijmans [ctb], Michael Sumner [ctb], Don MacQueen [ctb], Jim Lemon [ctb], Finn Lindgren [ctb], Josh O'Brien [ctb], Joseph O'Rourke [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.