Learn R Programming

googleway (version 2.0.0)

google_elevation: Google elevation

Description

The Google Maps Elevation API provides elevation data for all locations on the surface of the earth, including depth locations on the ocean floor (which return negative values).

Usage

google_elevation(df_locations = NULL, polyline = NULL,
  location_type = c("individual", "path"), samples = NULL, key,
  simplify = TRUE)

Arguments

df_locations

data.frame of with two columns called 'lat' and 'lon' (or 'latitude' / 'longitude') used as the locations

polyline

string encoded polyline

location_type

string Specifies the results to be returned as individual locations or as a path. One of 'individual' or 'path'. If 'path', the data.frame df_locations must contain at least two rows. The order of the path is determined by the order of the rows.

samples

integer Required if location_type == "path". Specifies the number of sample points along a path for which to return elevation data. The samples parameter divides the given path into an ordered set of equidistant points along the path.

key

string A valid Google Developers Elevation API key

simplify

logical Indicates if the returned JSON should be coerced into a list

Value

Either list or JSON string of the elevation data

Details

Locations can be specified as either a data.frame containing both a lat/latitude and lon/longitude column, or a single encoded polyline

Examples

Run this code
# NOT RUN {
## elevation data for the MCG in Melbourne
df <- data.frame(lat = -37.81659,
                 lon = 144.9841)

google_elevation(df_locations = df,
                 key = "<your valid api key>",
                 simplify = TRUE)



## elevation data from the MCG to the beach at Elwood (due south)
df <- data.frame(lat = c(-37.81659, -37.88950),
                 lon = c(144.9841, 144.9841))

df <- google_elevation(df_locations = df,
                       location_type = "path",
                       samples = 20,
                       key = "<your valid api key>",
                       simplify = TRUE)

## plot results
library(ggplot2)
df_plot <- data.frame(elevation = df$results$elevation,
                       location = as.integer(rownames(df$results)))

ggplot(data = df_plot, aes(x = location, y = elevation)) +
 geom_line()
# }
# NOT RUN {

# }

Run the code above in your browser using DataLab