google_elevation: Google elevation

View source: R/google_elevation.R

google_elevationR Documentation

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 = get_api_key("elevation"),
  simplify = TRUE,
  curl_proxy = NULL
)

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 - TRUE indicates the returned JSON will be coerced into a list. FALSE indicates the returend JSON will be returned as a string

curl_proxy

a curl proxy object

Details

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

Value

Either list or JSON string of the elevation data

API use and limits

The amount of queries you can make to Google's APIs is dependent on both the service and the API you are using.

Each API has specific quotas and limits. Check Google's API documentation for details.

View your usage at the Google Cloud Console https://console.cloud.google.com/

Each API can only accept and return one request at a time. If you write a loop to make multiple API calls you should ensure you don't go over your quota / limits during the loop.

Examples

## Not run: 

set_key("YOUR_GOOGLE_API_KEY")
## elevation data for the MCG in Melbourne
df <- data.frame(lat = -37.81659,
                 lon = 144.9841)

google_elevation(df_locations = df,
                 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,
                       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()

## End(Not run)



googleway documentation built on Aug. 22, 2023, 9:13 a.m.