1

I have taken aerial photographs with a drone and stitched those together into a .geotiff file, using third party software. I would like to add this file as a layer to an interactive leaflet map, e.g. as produced by mapview. I can produce an interactive map, but this only shows data, e.g. digital elevation not the actual photograph.

.geotiff files aren't very freely available, so see this link for an example file from naturalearth: https://www.naturalearthdata.com/downloads/50m-raster-data/50m-cross-blend-hypso/

library(magrittr)

exmpl <- terra::rast(".\\HYP_50M_SR.tif") %>% 
  raster::brick()

mapview::mapview(exmpl)

I am only interested in showing change over time as documented by repeated aerial photography and not interested in extracting data from the raster image. I have previously only worked with vector data, so please go easy on me if this is not a smart question. I like using mapview for it's simplicity, but base leaflet, tmap or any other interactive, R based solution would be fine by me. Thanks a lot!

M.Teich
  • 575
  • 5
  • 22

1 Answers1

2

I guess you ar looking for the mapview::viewRGB() function.

Please find below a little reprex.

Reprex

library(mapview)
library(magrittr)

exmpl <- terra::rast(".\\HYP_50M_SR.tif") %>% 
  raster::brick()

plotRGB(exmpl)

mapview::viewRGB(exmpl, r = 1, g = 2, b = 3, quantiles = NULL)

Created on 2022-02-10 by the reprex package (v2.0.1)

lovalery
  • 4,524
  • 3
  • 14
  • 28
  • Great, that was easy. Unfortunately, it appears that unless you have squareish and perfectly crs-aligned raw data that you get a black or white rectangle around the raster. `terra::plotRGB` allows for an alpha setting, which should remove this effect, but that doesn't seem to carry over to `mapview::viewRGB`. Any chance that you know how to deal with this? Can post this another question, if necessary. – M.Teich Feb 10 '22 at 17:00
  • Sorry, meant the `bgalpha` setting, but that doesn't do what I expected. – M.Teich Feb 10 '22 at 17:30
  • @M.Teich Thank you very much for your feedback. Yes, you are right : it would be preferable to ask another question as this is another issue, specifically related to your data. I understand that your images do not appear to be royalty free. Perhaps you could just include a small excerpt in your new question or, at least, include the summary of the object to provide some information to increase the chances of figuring out how to fix the problem. Cheers. – lovalery Feb 10 '22 at 17:40
  • 1
    I'd be happy to upload my images, but they are rather large so that isn't really an option. I'll see if I can crop them to a manageable size and post a separate question. Cheers – M.Teich Feb 11 '22 at 14:10
  • @M.Teich, Yes, if you can, I guess that's the best solution: (i) having a piece of your image will make it possible to perfectly reproduce the problem you're facing, (ii) of course, I will look into your new question thoroughly on my side, but I am not sure I will find the solution; thus, asking a new question will also make it possible for other SO users to think about your problem, which will maximize your chances of getting a solution. Cheers. – lovalery Feb 11 '22 at 15:42
  • just posted a seperate question concerning the black rectangle around my image (https://stackoverflow.com/questions/73302949/mapview-transparent-na-color-when-displaying-raster-files) – M.Teich Aug 10 '22 at 08:18