I am trying to use the function get_elevation_points in a data frame, but keep getting the same error:
Thanks!
> #get the API key : et an API Key from https://mapzen.com/developers. Since elevatr will search the environment for the appropriate key,
> #it is suggested that you store this in your .Renviron file. To do this:
>
> require(sf)
require(sp)
>
> cat("mapzen_key=mapzen-XXXXXXX\n", file =
> file.path(normalizePath("~/"), ".Renviron"),
> append = TRUE) mydata <- st_as_sf(x = Coordinates_alt,
> coords = c("Longitude", "Latitude"),
> crs = "+proj=longlat +datum=WGS84")
>
> coordinates(Coordinates_alt) <- cbind(Coordinates_alt$Longitude ,
> Coordinates_alt$Latitude) proj4string(Coordinates_alt) =
> CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
>
> require(elevatr)
>
> prj_dd <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
>
> mydata1 <- SpatialPointsDataFrame(df, proj4string = CRS(prj_dd), data
> = df)
>
> head(mydata1)
>
> df_elev <- get_elev_point(mydata1, prj = prj_dd, src = "mapzen")
df_elev <- get_elev_point(df, prj = prj_dd, src = "mapzen") Error in locations$elevation[idx_s[i]:idx_e[i]] <- unlist(resp$height) :
replacement has length zero In addition: Warning message: src 'mapzen' is deprecated and will cease to function after 2018-01-31 due to shutdown of Mapzen; Use 'epqs' instead for US locations. Still searching for a global elevation service replacement.
Sorry for delay in responding. I am not terribly active on SO, but given the few
elevatr
questions I will be!The issue you are having is that the
src = "mapzen"
, is an old source as all of the Mapzen services have been shut down. If your coordinates are in the US, you can use thesrc = "epqs"
, if they are outside of the US, you can usesrc = "aws"
but depending on how many points and the extent of your bounding box that may take some time. Also be sure to read the docs forelevatr::get_elev_point()
as there is some additional information in there about setting the z value for theaws
source. Something likeelevatr::get_elev_point(mydata1, prj = prj_dd, src = "aws", z = 5)
will be quick(ish) but resolution of the source raster data is pretty coarse. You can change z (up to 14) but higher values will add time to the download depending, again, on the extent of your coordinates.