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
sorry this is my first time using
gistr
I can authenticate to create new gists but not to edit an existing gist apparently. I've tried your suggestions here: https://gist.github.com/brfitzpatrick/05bf7e518477a69a815b790864f49a1b