When I plot aerial photographs in mapview a black rectangle is displayed around the picture, which I believe contains NA values and which I would like to remove. Due to the lack of easily available example data I have uploaded my actual geotif here (password: 1_sillyQuestion).
test_image <- terra::rast("yourpath\\test-image.tif") %>%
satellite::brick()
viewRGB(test_image,
r = 1,
g = 2,
b = 3,
quantiles = NULL)
Using data provided with the plainview package, I am able to remove the grey area surrounding the raster (which I think is analogous to my issue) by setting the na.color argument to "transparent".
Border present:
mapview::viewRGB(plainview::poppendorf, 4, 3, 2)
Border removed:
mapview::viewRGB(plainview::poppendorf, 4, 3, 2, na.color = "transparent")
Unfortunately this doesn't produce any changes, when applied to my problem:
viewRGB(gtiff_small,
r = 1,
g = 2,
b = 3,
quantiles = NULL,
na.color = "transparent")
Any suggestions about how to remove the black rectangle around my aerial image will be much appreciated!



na.colorhas no effect here because there aren't any NAs in the data. Your image is an RGB image where the black pixels are encodedas rgb(0, 0, 0)- black. The right thing to do is to specify a NA value upon the creation of the image (GDAL has an option to do this IIRC). Below is a solution that replaces allrgb(0, 0, 0)pixels with NA. But be careful, this will also set any real black pixels to NA (that's why it should really be done upon image creation).Created on 2022-08-11 by the reprex package (v2.0.1)