library(magrittr)
library(viridis)
library(raster)
library(rayshader)
Using the DEM available here which the source states is using the LV03 (a.k.a. EPSG 21781) coordinate reference system:
dem.200m.rast <- raster('~/Downloads/data/DHM200.asc')
crs(dem.200m.rast) <- crs('+init=epsg:21781')
Visualising the elevation raster with raster::plot
plot(dem.200m.rast, col = viridis(n = 1e3))
My extraction of the data from the raster
to a matrix
results in a distorted image:
dem.200m.mat <- raster::as.matrix(dem.200m.rast)
apply(X = dem.200m.mat, MARGIN = 2, FUN = rev) %>%
t() %>%
graphics::image(x = ., col = viridis(n = 1e3))
So I guess what we're seeing here is that raster::plot
is adjusting the aspect ratio of the plot in accordance with the coordinate reference system while there is no such information associated with the matrix for image
or rayshader
to use (though I don't think either of these have the functionality to estimate such an adjustment from the CRS).
dem.200m.mat.t <- t(dem.200m.mat)
system.time(
rayshader::sphere_shade(dem.200m.mat.t, texture = 'bw') %>%
rayshader::plot_map()
)
## user system elapsed
## 3.192 0.108 3.300
That's the one. I picked it to make this example reproducible. I have access to a 5m DEM that I'm not allowed share which uses the same CRS and has the projection info included in the file, visualising that (probably aggregated lightly) is the end goal for me at the moment.