Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to use viewRGB with stars object #322

Open
gilbertocamara opened this issue Aug 23, 2020 · 4 comments
Open

Error when trying to use viewRGB with stars object #322

gilbertocamara opened this issue Aug 23, 2020 · 4 comments

Comments

@gilbertocamara
Copy link

gilbertocamara commented Aug 23, 2020

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 functionsampleRegularfor signature"stars"
@tim-salabim
Copy link
Member

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.

@gilbertocamara
Copy link
Author

gilbertocamara commented Aug 23, 2020 via email

@tim-salabim
Copy link
Member

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

@tim-salabim
Copy link
Member

Making some progess at r-spatial/leafem#25 (comment)
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants