Fin barney
Fin barney

Reputation: 1

In R when I create a Sentinel 2 True Color Basemap with vector Border overlay it turns Black when trying to save and convert to a Grob

I am trying to do three things: create a basemap of true color image by compositing RGB, add an overlay of a boundary shape file, and then save these two items as a Grob that is plotted with the vector on top of the raster. Here is a snippet of the code. Sorry if not enough detail this is my first stack overflow question.

` bbox <- sf::st_bbox(Boundary[1,])

raster_bands <-  list.files(path = "Data/Scenes/2018_2019/All_Scenes/Test/2019-07-04", full.names = TRUE)

R1 <- raster::raster(raster_bands[5])
G1 <- raster::raster(raster_bands[4])
B1 <- raster::raster(raster_bands[3])


 r_crop <- raster::crop(R1, bbox)
 g_crop <- raster::crop(G1, bbox)
 b_crop <- raster::crop(B1, bbox)
 

rgb_stack <- raster::stack(r_crop,g_crop,b_crop)

Basemap  <- recordPlot({(raster::plotRGB(rgb_stack, r = 1, g = 2, b = 3,
                 scale = 800,
                 stretch = "lin"))})

Basemap <- grob(Basemap)

Basemap <- 
  tm_shape(rgb_stack) +
   tm_rgb( r = 1,
            g = 2 ,
            b = 3,
            alpha = NA,
            saturation = 1,
            interpolate = TRUE,
            max.value = 65535) +
    tm_shape(Boundary) +
    tm_borders(lwd = 2, col = "red")

Basemap <- tmap::tmap_grob(Basemap)
`

I know the raster is working properly when I run the "recordPlot" line as I see the true color raster image.

After I convert this to a grob on the next line it does not plot using the "grid.draw" function.

I appreciate any help or other ways to make this custom basemap plot as a grob. I would like it in that format as I am plotting 3 different maps and a histogram all together. Thanks!

Upvotes: 0

Views: 44

Answers (0)

Related Questions