mapview icon indicating copy to clipboard operation
mapview copied to clipboard

Error when trying to use viewRGB with stars object

Open gilbertocamara opened this issue 5 years ago • 4 comments

Dear Tim: I am having problems when trying to use the "viewRGB" function with a "stars" object. Please see the script below (MWE):

# install the inSitu library which has examples of large remote sensing images
devtools::install_github("e-sensing/inSitu")
# load the inSitu, raster and stars packages
library(inSitu)
library(raster)
library(stars)

# define the local directory to load the images
local_dir <- system.file("extdata/CBERS/", package = "inSitu")
files <- list.files(system.file("extdata/CBERS/", package = "inSitu"), recursive = TRUE)
# list the images
# images are 23 instances of NDVI and 23 instances of EVI for an area in Brazil
image_files <- paste0(local_dir, files)
# load the files as raster stacks
rast <- raster::stack(image_files)
# show an RGB with mapview based on raster stack - works!
mapview::viewRGB(rast, r = 46, g = 23, b = 46)
# load the files as a stars object
st_obj <- stars::read_stars(image_files)
# try to view them with mapview - Error!
mapview::viewRGB(st_obj, r = 46, g = 23, b = 46)

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘sampleRegular’ for signature ‘"stars"’

gilbertocamara avatar Aug 23 '20 08:08 gilbertocamara

Thanks @gilbertocamara, viewRGB currently only supports Raster* objects (even if the help says otherwise). My plan is to revamp mapview internally to only use stars functionality, so it will be supported in the future. I am not sure how long this will take me, as I am trying to leverage a new raster display js lib (which is currently already used for displaying single layer stars objects). This will require careful design of the API to allow passing of js functions which will then be used to do the calculations on the fly in the browser. The rgb functionality is a prime candidate for developing this as it is a clearly defined functionality. So bare with me, I'll try to get to it soon.

tim-salabim avatar Aug 23 '20 09:08 tim-salabim

Dear Tim

Many thanks for your quick response.

Best Gilberto

=========================== Prof Dr Gilberto Camara Secretariat Director GEO - Group on Earth Observations 7 bis, Avenue de La Paix CH-1211 Geneva - Switzerland Tel: +41227308480 Web: www.earthobservations.org

On 23 Aug 2020, at 11:22, tim-salabim [email protected] wrote:

Thanks @gilbertocamara https://github.com/gilbertocamara, viewRGB currently only supports Raster* objects (even if the help says otherwise). My plan is to revamp mapview internally to only use stars functionality, so it will be supported in the future. I am not sure how long this will take me, as I am trying to leverage a new raster display js lib (which is currently already used for displaying single layer stars objects). This will require careful design of the API to allow passing of js functions which will then be used to do the calculations on the fly in the browser. The rgb functionality is a prime candidate for developing this as it is a clearly defined functionality. So bare with me, I'll try to get to it soon.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/r-spatial/mapview/issues/322#issuecomment-678750683, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOHEDNRLSLEPA2FKHL6CKLSCDNUZANCNFSM4QIRTNMQ.

gilbertocamara avatar Aug 23 '20 09:08 gilbertocamara

I've just updated the documentation for viewRGB to reflect that it only works for Raster* objects.

tim-salabim avatar Aug 23 '20 09:08 tim-salabim

Making some progess at https://github.com/r-spatial/leafem/issues/25#issuecomment-678760949 We need to address this first in leafem before wrapping it here in mapview. So testing the leafem:: functions would be a great way to help and provide feedback

tim-salabim avatar Aug 23 '20 11:08 tim-salabim