get_elev_point {elevatr}R Documentation

Get Point Elevation


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.


  prj = NULL,
  src = c("epqs", "aws"),
  overwrite = FALSE,



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 string defining the projection of the locations argument. The string needs to be an acceptable SRS_string for CRS-class for your version of PROJ. If a sf object, a sp object or a raster object is provided, the 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.


A logical indicating that existing elevation and elev_units columns should be overwritten. Default is FALSE and get_elev_point will error if these columns already exist.


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 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 <- "EPSG:4326"
mts_sp <- sp::SpatialPoints(sp::coordinates(mts), 
                            proj4string = sp::CRS(SRS_string = ll_prj))
mts_spdf <- sp::SpatialPointsDataFrame(mts_sp, 
                                       data = data.frame(name = 
                                       c("Mt. Washington", "Mt. Mansfield"))) 
mts_raster <- raster::raster(mts_sp, ncol = 2, nrow = 2)
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)
get_elev_point(locations = mts_spdf)
get_elev_point(locations = mts_raster)

# Code to split into a loop and grab point at a time.
# This is usually faster for points that are spread apart 

elev <- vector("numeric", length = nrow(mts))
pb <- progress_estimated(length(elev))
for(i in seq_along(mts)){
elev[i]<-suppressMessages(get_elev_point(locations = mts[i,], prj = ll_prj, 
                                        src = "aws", z = 14)$elevation)
mts_elev <- cbind(mts, elev)

## End(Not run)

[Package elevatr version 0.4.1 Index]