Get elevation for lat/long points from a data.frame or list of points.

Description

Get elevation for lat/long points from a data.frame or list of points.

Usage

1
2
elevation(input = NULL, latitude = NULL, longitude = NULL,
  latlong = NULL, key, ...)

Arguments

input

A data.frame of lat/long data. There must be columns decimalLatitude and decimalLongitude.

latitude

A vector of latitude's. Must be the same length as the longitude vector.

longitude

A vector of longitude's. Must be the same length as the latitude vector.

latlong

A vector of lat/long pairs. See examples.

key

(character) Required. An API key. See Details.

...

Further named parameters, such as query, path, etc, passed on to modify_url within GET call. Unnamed parameters will be combined with config.

Details

To get an API key, see instructions at https://developers.google.com/maps/documentation/elevation/#api_key - It should be an easy process. Once you have the key pass it in to the key parameter. You can store the key in your .Rprofile file and read it in via getOption as in the examples below.

Value

A new column named elevation in the supplied data.frame or a vector with elevation of each location in meters.

References

Uses the Google Elevation API at the following link https://developers.google.com/maps/documentation/elevation/start

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Not run: 
apikey <- getOption("g_elevation_api")
key <- name_suggest('Puma concolor')$key[1]
dat <- occ_search(taxonKey=key, return='data', limit=300, hasCoordinate=TRUE)
head( elevation(dat, key = apikey) )

# Pass in a vector of lat's and a vector of long's
elevation(latitude=dat$decimalLatitude, longitude=dat$decimalLongitude, key = apikey)

# Pass in lat/long pairs in a single vector
pairs <- list(c(31.8496,-110.576060), c(29.15503,-103.59828))
elevation(latlong=pairs, key = apikey)

# Pass on options to httr
library('httr')
pairs <- list(c(31.8496,-110.576060), c(29.15503,-103.59828))
elevation(latlong=pairs, config=verbose(), key = apikey)

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.