-
Notifications
You must be signed in to change notification settings - Fork 90
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
Mapview fails over "stars" proxy objects #305
Comments
I can't reproduce your first code snippet: > f <- system.file("external/test.grd", package="raster")
> r <- stars::read_stars(f, proxy = T)
trying to read file: /home/edzer/R/x86_64-pc-linux-gnu-library/4.0/raster/external/test.grd
Error in CPL_read_gdal(as.character(x), as.character(options), as.character(driver), :
file not found
In addition: Warning message:
In CPL_read_gdal(as.character(x), as.character(options), as.character(driver), :
GDAL Error 1: Unhandled datatype=FLT4S but can with the second, when |
@edzer thanks! @tim-salabim: I was thinking that mapview could maybe check if a "proxy" PS: Strange - this works for me:
Maybe a different |
r = st_as_stars(st_as_stars(raster(f))) # in case f is a huge file or directly st_as_stars(raster(f), proxy=FALSE) I don't like this, but see no simple alternative ATM. For |
AFAICT, this is what Seems reasonable to me. Downsampling could be governed by the already available |
https://github.com/GeoTIFF/georaster-layer-for-leaflet/tree/master seems to have capabilities that could make the whole raster experience with leaflet in R a lot nicer, though I'm not too convinced about using KNN for on-the-fly interpolation. I'll try to mash-up a test repo for this when I find the time. Currently trying to get mapview et. al. in good shape for a summer school :-) |
For raster we use |
I can see if i can manage a PR on this in the coming days, if you wish. |
Of course. That would be much appreciated |
@tim-salabim the georaster-layer-for-leaflet uses simple nearest neighbor interpolation, not KNN (well, K=1, yes); this is also what stars' downsample uses or default for RasterIO stuff. |
@edzer thanks for the clarification! And good to know that it's somewhat aligned. I guess it's a matter of getting used to that the raster constantly changes appearance when you zoom in... |
If you resample to a cell size that corresponds to screen pixels it should look "natural". |
Not sure if that can be set. I will investigate when I find the time |
@tim-salabim Having a look at the issue. "Dispatching" mapview also over proxy objects is straightforward, and then as a start even something simple like this at the beginning of the "stars" method could work:
Only inconvenient could be that the "downsample" argument in @edzer Am I missing something here ? Is there a simple way to easily downsample also a non-proxy stars raster? |
Yes, try tif = system.file("tif/L7_ETMs.tif", package = "stars")
plot(stars:::st_downsample(read_stars(tif), c(10,10,1)))
|
@lbusett just so you know, I am currently trying to add georaster-for-leaflet support to leafem. If that works nicely, the downsampling approach may not warrant the effort. Not sure what to advise as we will need to see how the performance is, but I don't want you to put work into something that may not be needed. |
Yes, please! Actually, I'm already using it as a hard copy. Also happy with exports of: |
So, I've had success to get it to work. See https://twitter.com/TimSalabim3/status/1280950560892518402 (gif too large for github). The code for the gif: library(leaflet)
library(leafem)
leaflet() %>%
addProviderTiles("Esri.WorldImagery") %>%
leafem:::addGeoRaster(
file = "/home/timpanse/software/data/srtm_39_03.tif"
, group = "test"
, layerId = "testid"
) Currently, only supports single layer file (tested) and url (not tested). stars/raster support will basically be either passing on the file path or write to tempfile and use that. This is only a POC, but it seems reasonably performant, so I have hopes. Much of the performance seems to depend on the resolution which is currently hardcoded to be 96 px. Feel free to try yourselves with your own files. I think they need to be in 4326 but I am not sure (haven't tested others). EDIT: Here's the commit r-spatial/leafem@7ae2b86 |
This seems very promising! Thanks! Concerning projection, 4326 does not seem mandatory. At least UTM projection works:
However, this doesn't:
, though it may be related to the projection of the original file (strereographic something) Concernig the issue about stars proxy objects / downsampling, I'll let you decide: I could come up with something quick to fill the void while you develop the "new" technique, or I can stay like this. Just let me know. |
Thanks! UTM seems to be nativley supported, see https://github.com/GeoTIFF/georaster-layer-for-leaflet/blob/master/utils/utm.js Re stars downsampling, I would be grateful for a quick solution as I don't know how long I will need to get |
Ok, I'll see what I can do ! |
I'll try to implement a more robust POC for One thing that may turn into a can of worms is the fact that we need/are able to handle coloring on the javascript side. This can be very powerful, as it is not as static as creating color vectors in R and passing them. On the other hand, we need to carefully think about what we need to pass from R and how flexible that can be (e.g. palettes created with The noce thing about being able to handle all sorts of things on the JS side is that we can also do band calculations on the fly. See https://github.com/GeoTIFF/georaster-layer-for-leaflet/blob/master/tests/ndvi.html#L37-L82 for an example. But again, this diverts far enough from what I've implemented in any method so far, that I cannot foresee how much work this will entail. But I am quite excited about all the possibilities :-) |
Is this going towards some kind of in-browser google earth engine? |
I honestly don't know where this will lead. Though I have no intentions to reinvent existing wheels. This is just an attempt to adress the long standing issue of lacking capabilities to interactively view large raster data from R. Given that without shiny we have no way of communicating anything back to the R session once things are rendered I think it's good that calculations like downsampling happen when they need to happen, i.e. on zoom/pan changes. And this is what However, given that with georaster-layer-for-leaflet we have a tool to do this, I guess it's only natural to try out other calculations too. But I would not overload any of these as my feeling is that this will degrade performance quickly if calculations become too involved. NDVI is easy and I think that's why it's included as an example, for more computationally heavy stuff, we'd need to resort to something like GPU.js (at which stage I guess one could argue that we're headed towards a google earth engine type thing). We'll see how this evolves. But now that you have me thinking about this, I guess it's not a bad thing to at least try and implement something along the way of reactable's ability to pass javascript functions for cell value rendering. If a user knows JS, why not give them the tools to make use of it. |
But if we wanna go this way, that's the next step I guess: https://github.com/GeoTIFF/geoblaze |
Concerning this:
@tim-salabim If you agree, I would make a PR to implement 1). Then I'd wait for @edzer to export |
Thanks @lbusett! I think approach 1) i.e. only implement for proxy for now would be best. I agree that there is no rush, so we should wait until On that note, I've just used dim(tst)
x y
32727 15474 to dim(tst_ds)
x y
21818 10316 to be able to render it. But the experience once rendered is great. I've exposed resolution and opacity for people to play with. Feed back very welcome! Next is color handling, but for that I need some proper programming time (not in the pub :-) ) |
Ok, PR submitted - sorry for some mess with indentation. Now we get for example on proxy objects:
On non proxy ones:
@mtennekes : I basically replicated your approach for computation of the downsamplig factor - hope you don't mind! |
Continuing the Closing this, as the solution proposed by @lbusett has now been merged into develop. |
I noticed that using mapview over a "proxy" stars object currently fails:
Therefore, also this fails:
Consider that I fear therefore that mapview will always fail over large stars objects unless "proxy = FALSE" is specified explicitly.
The text was updated successfully, but these errors were encountered: