I like the look of xarray-leaflet!
Bear in mind I’m a data scientist and something of a geospatial (vis) numpty. I’m after the best (pronounced “easiest”) route to achieve an interactive (base)map and xarray based raster data. I get the basics of CRS and projections, but I’m sure not many of the deeper details, especially when it comes to the various formats for specifying projections and which function of which package accepts, or does, what!
I see ipyleaflet has a few built-in projections in dicts in the projections attribute. I’m surprised it has so few built in? I have data in xarray in CRS EPSG:32643 (N. India). If I try to specify that CRS when creating an ipyleaflet basemap, I just get a grey image. I think I understand this is because the projection isn’t supported. I tried creating a basemap (m
) using the default ipyleaflet CRS and then add my raster image with da.leaflet.plot(m)
. I get the basemap show up, but no raster image. I think I understand this is because the xarray_leaflet extension doesn’t do reprojections and just assumes the coordinates already match? So my raster could be appearing on the Moon or somewhere.
So I conclude I either need to tell ipyleafet about EPSG:32643, or reproject my xarray data to one of the CRS included in ipyleaflet’s projections? Getting a basemap in my target CRS sounds like the most computationally efficient approach.
I tried defining a custom projection using information from the epsg page and some copypaste:
proj43 = {
'name': 'EPSG:32643',
'custom': True,
'proj4def': '+proj=utm +zone=43 +datum=WGS84 +units=m +no_defs',
'bounds': [
[166021.44, 0.00],
[534994.66, 9329005.18]
],
'resolutions': [
8192.0,
4096.0,
2048.0,
1024.0,
512.0,
256.0
]
}
but that resulted in a grey image as well.
I was previously using contextily, but that’s not interactive. So this worked:
predicted.where(predicted.label == id).label.plot(ax=ax)
ctx.add_basemap(ax, crs='EPSG:32643', source=ctx.providers.OpenStreetMap.France)
where predicted
is my xarray to plot.
I just want to create a basemap in the right CRS and have my dask-backed xarray rasters magically overplotted. It’s not much to ask! I don’t mind defining a projection, but I don’t really know what I’m doing (which is likely clear from the above) so not sure whether I defined something wrong in proj43
or simply the specified basemap isn’t available in that CRS. Naively, it’s the same (?) basemap (at least provider) as works for EPSG:32643 in contextily.
Although I may be slightly hijacking/resurrecting your post about xarray-leaflet, @davidbrochart (which does look very cool and useful, BTW!) this does seem appropriate given the title of “xarray extensions for map plotting”.
If someone could give me a pointer, I’d be immensely grateful.