I'm trying to load elevation data from AWS using the elevatr
package, with a region defined as a Simple Features Collection from the sf
package. Here's a simple example:
library(elevatr)
library(sf)
library(USAboundaries)
counties <- us_counties(map_date = "1930-01-01", resolution = "high", states = c("NY"))
elevation <- get_elev_raster(counties$geometry, z = 9, src = "aws")
This gives an error:
Error in if (attributes(class(locations)) %in% c("raster", "sp")) { :
argument is of length zero
In addition: Warning messages:
1: In if (class(locations) == "data.frame") { :
the condition has length > 1 and only the first element will be used
2: In if (class(locations) == "SpatialPoints") { :
the condition has length > 1 and only the first element will be used
3: In if (class(locations) == "SpatialPointsDataFrame") { :
the condition has length > 1 and only the first element will be used
Presumably because the sfc is a collection of polygons and MULTIPOINT
objects, which aren't supported by the get_elev_raster
function of the elevatr
package.
Is there any way to use these packages together? With the end result being an sfc object that also has various forms of elevation data for each point?
I'm getting the data this way because it doesn't seem like the st_read
function from the sf
package can read ESRI ASCII files.