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 SpatialPoints
/SpatialPointsDataFame
as
input. A SpatialPointsDataFrame is returned with elevation as an added
data.frame
.
get_elev_point(locations, prj = NULL, src = c("epqs", "aws"), ...)
Either a data.frame
with x (e.g. longitude) as the
first column and y (e.g. latitude) as the second column, a
SpatialPoints
/SpatialPointsDataFrame
, or a
sf
POINT
or MULTIPOINT
object.
Elevation for these points will be returned in the
originally supplied class.
A PROJ.4 string defining the projection of the locations argument.
If a SpatialPoints
or SpatialPointsDataFrame
is
provided, the PROJ.4 string will be taken from that. This
argument is required for a data.frame
of locations.
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 get_elev_raster
and then
extracts the elevation for each point.
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.
Function returns a SpatialPointsDataFrame
or sf
object
in the projection specified by the prj
argument.
# NOT RUN {
mt_wash <- data.frame(x = -71.3036, y = 44.2700)
mt_mans <- data.frame(x = -72.8145, y = 44.5438)
mts <- rbind(mt_wash,mt_mans)
ll_prj <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
mts_sp <- sp::SpatialPoints(sp::coordinates(mts),
proj4string = sp::CRS(ll_prj))
get_elev_point(locations = mt_wash, prj = ll_prj)
get_elev_point(locations = mt_wash, units="feet", prj = ll_prj)
get_elev_point(locations = mt_wash, units="meters", prj = ll_prj)
get_elev_point(locations = mts_sp)
# 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))
pb <- progress_estimated(length(elev))
for(i in seq_along(mts)){
pb$tick()$print()
elev[i]<-suppressMessages(get_elev_point(locations = mts[i,], prj = ll_prj,
src = "aws", z = 14)$elevation)
}
mts_elev <- cbind(mts, elev)
mts_elev
# }
Run the code above in your browser using DataLab