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

Disable resampling when plotting raster #273

Closed
fabeit opened this issue Mar 24, 2020 · 7 comments
Closed

Disable resampling when plotting raster #273

fabeit opened this issue Mar 24, 2020 · 7 comments

Comments

@fabeit
Copy link

fabeit commented Mar 24, 2020

Thank you for the very nice package!
I have seen a similar question/issue #123 in which it is explained that any raster object is resampled to be reprojected.

I am wondering if there is anyway to turn the resampling off because it really reduced the usefulness of such great package. My rasters are usually in latlong and world coverage WGS84. Is there any way to plot the raster with mapview() without resampling? I guess I could convert the raster in a polygon but it is very useful to plot the raster along with other simple_features.

Many thanks

@tim-salabim
Copy link
Member

You can use native.crs = TRUE but then you will not get backgraound maps. In order to put rasters on the background maps, we need to transform the data to webmercator, there is no way aound this (unless you find a tile provider that provides background maps in wgs84). Not sure if you are aware, but you can set method = 'ngb' to use neaighrest neighbor interpolation when transforming.

@fabeit
Copy link
Author

fabeit commented May 15, 2020

@tim-salabim thank you for the suggestion, I didn't know about the native.crs option, unfortunately it does not provide the cell on mouse hover, and the ngb method to doesn't provide the actual values. What I end up doing is a rasterToPolygon and then use mapview that way. I might just use a wrap around function. Is there a reason why it is difficult to find background maps in WGS 84?

@tim-salabim
Copy link
Member

Is there a reason why it is difficult to find background maps in WGS 84?

Because pretty much all tile providers provide tiles in webmercator as it is the de-facto default for webmapping.

I still don't quite get the issue you have... If you plot polygons with mapview, they are also transformed to web mercator... Do you maybe have a reprex that shows what the issue is and why it doesn't work as you'd expect?

@fabeit
Copy link
Author

fabeit commented May 19, 2020

The issue is that the raster values displayed by mapview(raster) are not the actual values in the raster, since they are interpolated. You can try this with any raster in lat/long, I can provide one if you'd like. The usefulness of mapview is also to explore data interactively, but if the displayed data is not the actual data it becomes less useful. When I convert a raster to polygon, when displayed the polygons contain the actual values.

@tim-salabim
Copy link
Member

Ok, so there's likely no quick fix here. Unfortunately leaflet does not support raster plotting on L.CRS.Simple. The only fix I could think of is to try and support addimageQuery for plainview (which is used when native.crs = TRUE).
This wouldn't change the fact that we won't have background maps, though. If you want background maps in any crs other than webmercator, you're pretty much on your own...

@fabeit
Copy link
Author

fabeit commented May 19, 2020

this confirms my initial thought that there is no easy solution, for me the conversion to polygons seems a reasonable compromise. Thank you for this discussion. Should we close the issue?

@tim-salabim
Copy link
Member

If you are fine your current workaround I guess we can close here. I've opened an issue here to keep the imageQuery for plainview objects open as I'd like to implement that at some stage.

Thanks

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