I am recently trying to make a terrain map of Switzerland and to that end, I need to get the elevation data for that particular country using the elevatr package in R. However when I run the following code chunk, which is something similar to what I have seen online for similar maps,

library(elevatr)
library(rgeoboundaries)
library(rgdal)

swiss_bound <- rgeoboundaries::geoboundaries("Switzerland")
elevation_data <- get_elev_raster(locations = swiss_bound, z = 10)

I get the following error

Error in if ((is.null(locs) | is.na(locs)) & is.null(prj)) { :  zero length argument

which does not make sense and I could not find any solution on the web to that problem, either why it does occur and what the solution is. So, I highly appreciate your assistance and thank you for your attention beforehand.

1

There are 1 best solutions below

1
On BEST ANSWER

I cannot re-create your exact error, but what I do see with rgeoboundaries is that it returns an sf object, but does not include the CRS which isn't great... It looks like it is in EPSG:4326. Making that assumption, the following code should work for you. But be careful with this as not having the CRS specified from rgeoboundaries leaves a lot of room for problems.

library(elevatr)
library(rgeoboundaries)
library(rgdal)
library(sf)

swiss_bound <- rgeoboundaries::geoboundaries("Switzerland")
st_crs(swiss_bound) <- 4326
elevation_data <- get_elev_raster(locations = swiss_bound, z = 10)