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

DataArrays that aren't in lat-lon co-ordinates: are they supported? #52

Open
robintw opened this issue Jan 14, 2022 · 3 comments
Open

Comments

@robintw
Copy link

robintw commented Jan 14, 2022

I'm trying to use xarray_leaflet to display an image that I've loaded via rioxarray. The image isn't in WGS84 projection (it's in a UK-based projection). It doesn't appear on the map, so I've been looking into the code.

In _get_tiles() the DataArray seems to be indexed by the lat/lon co-ordinates of a mercantile tile.

Does this mean that xarray_leaflet does not currently support working with DataArrays that are not indexed in lat/lon co-ordinates? I notice that the examples use large-scale global datasets that seem to be in WGS84.

@davidbrochart
Copy link
Collaborator

From this code:
https://github.com/davidbrochart/xarray_leaflet/blob/36adfa464c4ede34c3df019474a0f9d72d2877c6/xarray_leaflet/xarray_leaflet.py#L114-L129
I think that only WGS84 is supported if it's a dynamic map, but static maps should support projections supported by Leaflet.
Also, there is an example with a custom projection: https://github.com/davidbrochart/xarray_leaflet/blob/main/examples/custom_projection.ipynb

@robintw
Copy link
Author

robintw commented Jan 17, 2022

From what I can see from looking at that bit of code, and playing with the library, it seems that code only deals with a map that is in a different projection, not a DataArray that's in a different projection.

Looking at https://github.com/davidbrochart/xarray_leaflet/blob/main/xarray_leaflet/xarray_leaflet.py#L340, it seems that the raw lat-lon values of the tile boundaries are used to index the DataArray (and the same again at https://github.com/davidbrochart/xarray_leaflet/blob/main/xarray_leaflet/xarray_leaflet.py#L367) - and obviously this won't work if the xarray is indexed in lat-lon.

The reprojection that happens later (https://github.com/davidbrochart/xarray_leaflet/blob/main/xarray_leaflet/xarray_leaflet.py#L387) seems to be reprojecting to the projection of the map object.

I think this might be fixable relatively easily, if we can reproject to WGS84 before we do the subsetting - I'll do some experimenting and let you know how I get on.

@tsutterley
Copy link

hey @robintw, if you don't mind building off an unmerged PR in ipyleaflet, it's not too difficult to use imageservice layers with rioxarray. I found that it was easier when I was tinkering around on a project to just dynamically create images versus trying to do dynamically create projected tiles. Probably would be better in the long run to get the tiles working but this wasn't too bad 🤷

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

3 participants