Turns a raster into a matrix suitable for rayshader.

raster_to_matrix(raster, verbose = interactive())

Arguments

raster

The input raster. Either a RasterLayer object, a terra SpatRaster object, or a filename.

verbose

Default `interactive()`. Will print dimensions of the resulting matrix.

Examples

#Save montereybay as a raster and open using the filename.
if(rayshader:::run_documentation()) {
temp_raster_filename = paste0(tempfile(),".tif")
raster::writeRaster(raster::raster(t(montereybay)),temp_raster_filename)
elmat = raster_to_matrix(temp_raster_filename)
elmat %>%
 sphere_shade() %>%
 plot_map()
}
#> Please note that rgdal will be retired during October 2023,
#> plan transition to sf/stars/terra functions using GDAL and PROJ
#> at your earliest convenience.
#> See https://r-spatial.org/r/2023/05/15/evolution4.html and https://github.com/r-spatial/evolution
#> rgdal: version: 1.6-7, (SVN revision 1203)
#> Geospatial Data Abstraction Library extensions to R successfully loaded
#> Loaded GDAL runtime: GDAL 3.5.3, released 2022/10/21
#> Path to GDAL shared files: /Users/runner/work/_temp/Library/rgdal/gdal
#>  GDAL does not use iconv for recoding strings.
#> GDAL binary built with GEOS: TRUE 
#> Loaded PROJ runtime: Rel. 9.1.0, September 1st, 2022, [PJ_VERSION: 910]
#> Path to PROJ shared files: /Users/runner/work/_temp/Library/rgdal/proj
#> PROJ CDN enabled: FALSE
#> Linking to sp version:1.6-1
#> To mute warnings of possible GDAL/OSR exportToProj4() degradation,
#> use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.