convert: Convert the Format of "coords" and "waypoints" Objects

View source: R/CoordBase.R

convertR Documentation

Convert the Format of "coords" and "waypoints" Objects

Description

Convert the format of objects of class "coords" or "waypoints" between (i) decimal degrees, (ii) degrees and minutes, and (iii) degrees, minutes and seconds.

Usage

convert(x, ...)

## S3 method for class 'coords'
convert(x, fmt, ...)

## S3 method for class 'waypoints'
convert(x, fmt, ...)

Arguments

x

object of class "coords" created by function as_coords(), or class "waypoints" created by function as_waypoints().

...

further arguments passed to or from other methods.

fmt

integer, 1L, 2L or 3L, specifying the required coordinate format.

Details

The fmt argument should be 1L to convert to decimal degrees, 2L, to convert to degrees and minutes, and 3L to convert to degrees, minutes and seconds. On conversion of a "coords" object, the original argument x is modified to have a decimal point after the number of whole degrees in the case of decimal degrees, after the number of whole minutes in the case of degrees and minutes, and after the number of whole seconds in the case of degrees, minutes and seconds.

Prior to conversion, the "coords" or "waypoints" object to be converted is checked to ensure its values represent valid geographic locations as described under validate().

Value

The original argument x, an object of class "coords" or "waypoints" with values converted as described under details and a revised "fmt" attribute reflecting the new format.

See Also

"coords", "waypoints" and validate().

Other coordsandway: coords, waypoints

Examples

## Continuing example from `as_coords()`...


## Named "coords" object in degrees and minutes with
## eight values each of latitude and longitude
dm

## Convert to degrees, minutes and seconds (fmt = 3)
convert(dm, 3)

## Convert to decimal degrees (fmt = 1)
convert(dm, 1)

## Show converted values as an ordinary R numeric vector
as.numeric(dm)

###
## Continuing example from `as_waypoints()`...


## "waypoints" object in degrees, minutes and seconds
wp

## Convert to degrees and minutes (fmt = 2)
convert(wp, 2)

## Convert to decimal degrees (fmt = 1)
convert(wp, 1)

## Show converted values as an ordinary R data frame
as.data.frame(wp)

rm(dm, wp)



Waypoint documentation built on April 11, 2025, 6:12 p.m.