get_elev_point {elevatr} | R Documentation |
Get Point Elevation
Description
This function provides access to point elevations using either the USGS
Elevation Point Query Service (US Only) or by extracting point elevations
from the AWS Terrain Tiles. The function accepts a data.frame
of x
(long) and y (lat) or a sf
POINT
or MULTIPOINT
object as
input. A sf
POINT
or MULTIPOINT
object is returned with
elevation and elevation units as an added data.frame
.
Usage
get_elev_point(
locations,
prj = NULL,
src = c("epqs", "aws"),
overwrite = FALSE,
...
)
Arguments
locations |
Either a |
prj |
A valid input to |
src |
A character indicating which API to use, either "epqs" or "aws"
accepted. The "epqs" source is relatively slow for larger numbers
of points (e.g. > 500). The "aws" source may be quicker in these
cases provided the points are in a similar geographic area. The
"aws" source downloads a DEM using |
overwrite |
A logical indicating that existing |
... |
Additional arguments passed to get_epqs or get_aws_points. When using "aws" as the source, pay attention to the 'z' argument. A defualt of 5 is used, but this uses a raster with a large ~4-5 km pixel. Additionally, the source data changes as zoom levels increase. Read https://github.com/tilezen/joerd/blob/master/docs/data-sources.md#what-is-the-ground-resolution for details. |
Value
Function returns an sf
object in the projection specified by
the prj
argument.
Examples
## Not run:
library(elevatr)
library(sf)
library(terra)
mts <- data.frame(x = c(-71.3036, -72.8145),
y = c(44.2700, 44.5438),
names = c("Mt. Washington", "Mt. Mansfield"))
ll_prj <- 4326
mts_sf <- st_as_sf(x = mts, coords = c("x", "y"), crs = ll_prj)
#Empty Raster
mts_raster <- rast(mts_sf, nrow = 5, ncol = 5)
# Raster with cells for each location
mts_raster_loc <- terra::rasterize(mts_sf, rast(mts_sf, nrow = 10, ncol = 10))
get_elev_point(locations = mts, prj = ll_prj)
get_elev_point(locations = mts, units="feet", prj = ll_prj)
get_elev_point(locations = mts_sf)
get_elev_point(locations = mts_raster)
get_elev_point(locations = mts_raster_loc)
# Code to split into a loop and grab point at a time.
# This is usually faster for points that are spread apart
library(dplyr)
elev <- vector("numeric", length = nrow(mts))
for(i in seq_along(mts)){
elev[i]<-get_elev_point(locations = mts[i,], prj = ll_prj, src = "aws",
z = 10)$elevation}
mts_elev <- cbind(mts, elev)
mts_elev
## End(Not run)