Convert the Format of "coords" and "waypoints" Objects
convert.RdConvert 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 functionas_coords(), or class"waypoints"created by functionas_waypoints().- ...
further arguments passed to or from other methods.
- fmt
integer,1L,2Lor3L, specifying the required coordinate format.
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.
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().
To format or print "coords" or "waypoints" in another coordinate format without
modifying the original object, use format() or
print() with the required fmt argument as above.
See also
"coords", "waypoints" and validate().
Examples
## Continuing example from `as_coords()`...
## Named "coords" object in degrees and minutes with
## eight values each of latitude and longitude
dm
#> Nelson's Column 51°30.4659′ N
#> Ostravice 49°32.7726′ N
#> Tally Ho 48°06.4339′ N
#> Washington Monument 38°53.3696′ N
#> Null Island 0°00.0000′ N
#> Tristan da Cunha 37°06.7044′ S
#> Mawson Peak 53°06.2869′ S
#> Silvio Pettirossi International Airport 25°14.4093′ S
#> Nelson's Column 0°07.6754′ W
#> Ostravice 18°23.9137′ E
#> Tally Ho 122°46.7203′ W
#> Washington Monument 77°02.1145′ W
#> Null Island 0°00.0000′ E
#> Tristan da Cunha 12°17.3178′ W
#> Mawson Peak 73°31.0370′ E
#> Silvio Pettirossi International Airport 57°31.1536′ W
## Convert to degrees, minutes and seconds (fmt = 3)
convert(dm, 3)
#> Nelson's Column 51°30′27.95″ N
#> Ostravice 49°32′46.36″ N
#> Tally Ho 48°06′26.03″ N
#> Washington Monument 38°53′22.18″ N
#> Null Island 0°00′00.00″ N
#> Tristan da Cunha 37°06′42.26″ S
#> Mawson Peak 53°06′17.21″ S
#> Silvio Pettirossi International Airport 25°14′24.56″ S
#> Nelson's Column 0°07′40.52″ W
#> Ostravice 18°23′54.82″ E
#> Tally Ho 122°46′43.22″ W
#> Washington Monument 77°02′06.87″ W
#> Null Island 0°00′00.00″ E
#> Tristan da Cunha 12°17′19.07″ W
#> Mawson Peak 73°31′02.22″ E
#> Silvio Pettirossi International Airport 57°31′09.22″ W
## Convert to decimal degrees (fmt = 1)
convert(dm, 1)
#> Nelson's Column 51.507765° lat
#> Ostravice 49.546210° lat
#> Tally Ho 48.107232° lat
#> Washington Monument 38.889493° lat
#> Null Island 0.000000° lat
#> Tristan da Cunha -37.111740° lat
#> Mawson Peak -53.104782° lat
#> Silvio Pettirossi International Airport -25.240155° lat
#> Nelson's Column -0.127923° lon
#> Ostravice 18.398562° lon
#> Tally Ho -122.778672° lon
#> Washington Monument -77.035242° lon
#> Null Island 0.000000° lon
#> Tristan da Cunha -12.288630° lon
#> Mawson Peak 73.517283° lon
#> Silvio Pettirossi International Airport -57.519227° lon
## Show converted values as an ordinary R numeric vector
as.numeric(dm)
#> [1] 5130.4659 4932.7726 4806.4339 3853.3696 0.0000 -3706.7044
#> [7] -5306.2869 -2514.4093 -7.6754 1823.9137 -12246.7203 -7702.1145
#> [13] 0.0000 -1217.3178 7331.0370 -5731.1536
###
## Continuing example from `as_waypoints()`...
## "waypoints" object in degrees, minutes and seconds
wp
#> Latitude Longitude
#> ______________ _______________
#> Nelson's Column 51°30′27.95″ N 0°07′40.53″ W
#> Ostravice 49°32′46.36″ N 18°23′54.82″ E
#> Tally Ho 48°06′26.04″ N 122°46′43.22″ W
#> Washington Monument 38°53′22.18″ N 77°02′06.87″ W
#> Null Island 0°00′00.00″ N 0°00′00.00″ E
#> Tristan da Cunha 37°06′42.26″ S 12°17′19.07″ W
#> Mawson Peak 53°06′17.21″ S 73°31′02.22″ E
#> Silvio Pettirossi International Airport 25°14′24.56″ S 57°31′09.21″ W
## Convert to degrees and minutes (fmt = 2)
convert(wp, 2)
#> Latitude Longitude
#> _____________ ______________
#> Nelson's Column 51°30.4658′ N 0°07.6755′ W
#> Ostravice 49°32.7727′ N 18°23.9137′ E
#> Tally Ho 48°06.4340′ N 122°46.7203′ W
#> Washington Monument 38°53.3697′ N 77°02.1145′ W
#> Null Island 0°00.0000′ N 0°00.0000′ E
#> Tristan da Cunha 37°06.7043′ S 12°17.3178′ W
#> Mawson Peak 53°06.2868′ S 73°31.0370′ E
#> Silvio Pettirossi International Airport 25°14.4093′ S 57°31.1535′ W
## Convert to decimal degrees (fmt = 1)
convert(wp, 1)
#> Latitude Longitude
#> ___________ ____________
#> Nelson's Column 51.507764° -0.127925°
#> Ostravice 49.546211° 18.398561°
#> Tally Ho 48.107233° -122.778672°
#> Washington Monument 38.889494° -77.035242°
#> Null Island 0.000000° 0.000000°
#> Tristan da Cunha -37.111739° -12.288631°
#> Mawson Peak -53.104781° 73.517283°
#> Silvio Pettirossi International Airport -25.240156° -57.519225°
## Show converted values as an ordinary R data frame
as.data.frame(wp)
#> name lat lon
#> 1 Nelson's Column 513028.0 -740.53
#> 2 Ostravice 493246.4 182354.82
#> 3 Tally Ho 480626.0 -1224643.22
#> 4 Washington Monument 385322.2 -770206.87
#> 5 Null Island 0.0 0.00
#> 6 Tristan da Cunha -370642.3 -121719.07
#> 7 Mawson Peak -530617.2 733102.22
#> 8 Silvio Pettirossi International Airport -251424.6 -573109.21
rm(dm, wp)