-
Notifications
You must be signed in to change notification settings - Fork 506
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
support SpatRaster with color table or RGB #808
Conversation
Hi, sorry I haven't gotten to this yet, I've been on vacation and then busy with rstudio::conf preparations. It's on my todo list though, thanks for your patience. |
Hey all, I'm curious what the status of this PR is? I have a tutorial that has transitioned from the |
@amfriesz It's always taunting me from the top of my todo list 😞 I'll take a look at it now |
Looks good overall! How would you add a legend for these? (For both discrete and continuous) Currently, the "happy path" for doing so, is to pass a palette function to |
If a SpatRaster has colors, either via a "color table" or because it has RGB layers, but it does not have levels (it is not categorical), then it is a "photo", e.g. a satellite image or an air-photo. There should not be a legend for these. For example object If a SpatRaster has
The levels and colors can be matched by the first column (in this case they are both called "value" but that is not guaranteed). For continous rasters I use |
@rhijmans Thank you, that's extremely helpful. Give me a day or two to come up with a proposal for integrating the color table either with the color palette functions, or |
Hey @jcheng5, what's the status of this issue? |
@amfriesz Thanks for the nudge. @rhijmans How does this look? It's only intended for SpatRaster objects with a color table and categorical values; levels are optional. In particular, am I right in using numeric indexing into the
Example:
|
Two suggestions
Examples
|
"?terra:coltab" should be "?terra::coltab" |
Thank you for that feedback. Is it also worthwhile to remove unused levels in the case where |
Yes, that situation is not uncommon. The below is one way to handle that (with changed test data)
|
@rhijmans I've addressed that situation (but using a different method--sorry, I didn't see your response until I already had it working). If you could give it one more look, I'd appreciate it! |
@jcheng5 your approach is more elegant. In my two commits I suggest using "unique(x)" instead of "values(x)" to avoid memory issues. It looks like I have also added |
Pull Request
This PR extends #807 (support for SpatRaster objects from the terra package). With this one there is support for "RGB(A)" SpatRasters (in which layers represent color channels), and for rasters with a color table (that match cell values with colors).
PR task list:
tests/testthat/
devtools::document()