Some functions for use with (latitude, longitude) coordinates.
Usage
geoFrame(lat, lon = NULL, ..., pair.lat.lon = TRUE)
geoBearing(lat, lon = NULL, ...)
geoDistance(lat, lon = NULL, units = "m", ...)
geoElevation(
lat,
lon = NULL,
units = "m",
...,
method = "google.elevation",
n = 10
)
geoDestination(
lat,
lon = NULL,
bearing = NULL,
distance = NULL,
units = "m",
...
)
geoConvertBNG2LatLon(east, north = NULL, ..., crs = 27700)
geoConvertLatLonDec2Deg(lat, lon = NULL, ..., format = NULL, test = FALSE)
Arguments
- lat, lon
Latitudes and longitudes to be used in geographical calculations. Note: This can be supplied as two vectors or as a list or data.frame containing lat and lon vectors.
- ...
Additional arguments, currently ignored.
- pair.lat.lon
(Logical) Should
lat
andlon
be paired? IfTRUE
(as in default)lat
andlon
series lengths are matched and extra values are discarded.- units
(Character) The units that results should be reported in. For, geoDistance,
geoElevation
andgeoDestination
, the current options are (the default)"m"
and"km"
.- method
(For
geoElevation
) the elevation method. Currently, the only enabled option is'google.elevation'
which uses the Google Elevation API.- n
(For
geoElevation
) the single request size limit. Some elevation data request methods cannot handle large numbers oflat, lon
at a go. So, where this is casegeoElevation
generates and merges multiple requests.n
sets the maximum number oflat, lon
per request.- bearing, distance
(For
geoDestination
) the bearing (relative to North) and distance to move from the start pointlat
,lon
.- east, north
(For
geoConvertBNG2LatLon
) Easting and Northing coordinates, respectively.- crs
(For
geoConvertBNG2LatLon
) the coordinate reference system for suppliedeasting
andnorthing
, by default 27700, the EPSG code for British National Grid coordinates.- format
(For
geoConvertLatLonDev2Deg
) formatting for suppliedlat
andlon
assumed to be supplied in degrees (deg/min/sec) format. The defaultNULL
assumeslat
andlon
are not formatted.- test
(For
geoConvertLatLonDev2Deg
) test suppliedlat
andlon
coordinates before converting. This generates a WARNING only if any look like a suspect case for conversion, e.g alat > 90
,lon > 180
, degrees > 60, etc...
Value
geoFrame
is data handler used by other geo...
functions. It returns a list containing the named components
lat
and lon
. if latitude, longitude pairing has
been applied pair.lat.lon = TRUE
these components will
be the same length.
geoBearing
returns a vector of bearings for supplied lat, lon
combinations. NOTE: Bearings length will be one less than the length
number of lat (or lon) because bearings are measured prior point to
latter point.
geoDistance
returns a vector of distances between supplied lat,
lon points in a supplied series, so again one less the supplied number
of points. By default, this will be supplied in meters, but units can
be modified as part of the call using, e.g. units = "km"
to get
distance(s) in kilometers.
geoElevation
returns a vector of elevations, one for each
lat, lon pair supplied. By default, this will be supplied in meters,
but units can be modified as part of the call using, e.g.
units = "km"
to get elevations(s) in kilometers.
geoDestination
returns a list of named lat/lon pairs for
the path from the supplied lat/lon start point, assuming the
journey described by the supplied bearings and distance.
geoConvertBNG2LatLon
converts British National
Grid (BNG) Easting/Northing coordinates to (WGS84)
Latitude/Longitude coordinates.
geoConvertLatLonDeg2Dem
converts Latitude/Longitude coordinates
logged in degrees to decimal.
Note
All functions currently require or convert to
lat
and lon
in WGS84 coordinates and
conventional decimal format.
geoBearing
DETAILS NEEDED.
geoDistance
uses the haversine formula to account to the
Earth's surface curvature, and uses 6371 km as the radius of earth.
geoElevation
uses the Google elevation API to get elevations,
so required R to be internet enabled.
geoDestination
DETAILS NEEDED.
Examples
#example 1
lat <- 1:10
lon <- 1:10
#get the distance point1 to point2, point2 to point2, etc.
dist <- geoDistance(lat, lon)
#get the bearing point1 to point2, point2 to point2, etc.
bear <- geoBearing(lat, lon)
#reconstruct the journey from start point,
#using distances and bearings
geoDestination(lat[1], lon[1], bear, dist)
#> $lat
#> [1] 1.000000 1.999797 2.999442 3.998935 4.998278 5.997470 6.996512 7.995407
#> [9] 8.994155 9.992758
#>
#> $lon
#> [1] 1.000000 2.000203 3.000558 4.001066 5.001725 6.002536 7.003499
#> [8] 8.004613 9.005878 10.007293
#>
#(very nearly...)