Image output:
The output shows the cropped area but there is no colour.
Some notes about data preparation:
I am attemping to overlay a cropped out part of the single-band forest layer raster (mos_rm_rgb) on the v_mat (DEM) matrix layer:
I input and converted the DEM geotif to matrix R (in RStudio):
v_mat <- raster_to_matrix("dem_0012deg.tif")
Save geotif:
writeRaster(mos_rm, filename = "mos_rm.tif", overwrite=TRUE)
Using QGIS (to symbolise and export a 3-band tif file) the single-band geotiff file is converted to a 3-band geotif file. From the add-overlay documentation, I see that a 3 or 4-band RGB matrix is needed. I also tried adding a matrix based on a 3-band raster without success (using GIMP to remove the alpha band).
Read 4-band geotif file into R:
mos_rm_rgb <- rast("mos_rm_rgb_noalpha.tif")
Convert the forest SpatRaster to a matrix object:
mos_mat <- raster_to_matrix(mos_rm_rgb)
I removed negative values in v_mat which seemed to giving an error when running the above rayshader code.
v_mat_nas[v_mat_nas < 0] <- 0
I also transposed the forest layer as the image is distorted (and just black and white).
mos_tr <- t(mos_mat_rs)
I'm trying to add an image overlay (from a single-band geotiff file) using rayshader to save as a 2d png file.
I've reviewed various documents and content online but cannot get the image to render properly.
I'd be grateful for any pointers.
I have a single-band geotif file (forest cover) which I would like to overlay on a DEM using the add_overlay function.
Everything works fine with the following code except when including the add_overlay(image) layer.
This is the code (on my latest attempt), which gives the following image (pasted after code):
Calculate shade layers
Image output: The output shows the cropped area but there is no colour.
Some notes about data preparation: I am attemping to overlay a cropped out part of the single-band forest layer raster (mos_rm_rgb) on the v_mat (DEM) matrix layer:
I input and converted the DEM geotif to matrix R (in RStudio):
v_mat <- raster_to_matrix("dem_0012deg.tif")
Input forest layers:
Mosaic files:
Crop out the forest layer:
Resample and mask:
Save geotif:
writeRaster(mos_rm, filename = "mos_rm.tif", overwrite=TRUE)
Using QGIS (to symbolise and export a 3-band tif file) the single-band geotiff file is converted to a 3-band geotif file. From the add-overlay documentation, I see that a 3 or 4-band RGB matrix is needed. I also tried adding a matrix based on a 3-band raster without success (using GIMP to remove the alpha band).
Read 4-band geotif file into R:
mos_rm_rgb <- rast("mos_rm_rgb_noalpha.tif")
Convert the forest SpatRaster to a matrix object:
mos_mat <- raster_to_matrix(mos_rm_rgb)
I removed negative values in v_mat which seemed to giving an error when running the above rayshader code.
v_mat_nas[v_mat_nas < 0] <- 0
I also transposed the forest layer as the image is distorted (and just black and white).
mos_tr <- t(mos_mat_rs)