if (FALSE) {
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
}
Run the code above in your browser using DataLab