xpublish-community / xpublish

Publish Xarray Datasets via a REST API.
https://xpublish.readthedocs.io
Apache License 2.0
168 stars 23 forks source link

Would it be feasible to provide a WMS route? #53

Closed cwerner closed 2 months ago

cwerner commented 4 years ago

Hi

Recently stumbled upon this neat little library. I currently have the problem that I'm building a dashboard using streamlit and folium. On the folium map, I'd like to overlay a raster which can be achieved rather easy if this is hosted via WMS somewhere. Now, I'd like to avoid hosting this single file via something expensive as geoserver or a threads instance just for this single map.

Would it be feasible to implement a WMS access option in Xpublish? not sure about the boilerplate required for doing this... 🤷‍♂️

jhamman commented 4 years ago

Yes! This should be perfectly feasible. You'll need to create a new custom router that exposes an WMS endpoint. I think for a simple WMS endpoint, it will probably be easiest to just write the GET/POST routes from scratch but you should certainly take a look at the existing implementations in OWSLib before getting started. Between @benbovy and I, we can help point you in the right direction for getting the xpublish router stuff working.

cwerner commented 4 years ago

Great

Unfortunately with regard to the WMS protocol and internals I‘m merely a user and implementing this myself might be well over my head (but I’ll try to read up on it). Would integrating something like skinnywms into Xpublish work? https://github.com/ecmwf/skinnywms

benbovy commented 4 years ago

Would integrating something like skinnywms into Xpublish work?

I think it would be be better if xpublish doesn't rely on 3rd party servers like skinnywms in order to keep the deployment easy. Thanks to FastAPI, It should be pretty straightforward to implement the WMS API endpoints in xpublish from scratch.

A good part of the work to support WMS is to properly handle plotting of the data and exporting it to a PNG/JPG image. This is something that we could delegate to a 3rd party library like Holoviews/Datashader as suggested in https://github.com/xarray-contrib/xpublish/issues/50#issuecomment-673510401.

iacopoff commented 3 years ago

Hi @benbovy and @jhamman, I would like this feature available in xpublish so I thought I would start working on it. Actually, I am not an expert in WMS but I think I can manage! Surely a little bit of guidance is definitely welcome :).

benbovy commented 3 years ago

Hi @iacopoff, I'm not an expert in WMS either, but it might be worth looking at those projects:

iacopoff commented 3 years ago

Hi @benbovy, great, thanks for the suggestions. I have just forked the repo. I am going to start working on it from mid July, after holidays!

iacopoff commented 3 years ago

Hi @benbovy, my understanding is that the key ingredients are:

Does it sound correct? Are you suggesting to use Titiler for both somehow?

benbovy commented 3 years ago

Hi @iacopoff, it sounds good to me. I had a look at Titiler a while ago, I'm not sure how easy / hard would it be to reuse it instead of re-implementing the same functionality here.

I guess we would need a custom subclass of rio_tiler.BaseReader subclass, which is used by Titiler router factory classes. However, rio_tiler.BaseReader is specific to rasterio and expects a dataset url as parameter, whereas in Xpublish we use a get_dataset fastapi dependency to directly access the xarray Dataset object being served. I'm not sure how this could be integrated together.

iacopoff commented 3 years ago

Hi @benbovy, I have started with something simpler: an XYZ service. To create the tiles, I am using Datashader but I guess that I could alternatively use Pillow/PIL if needed. The tricky bit is to get the dataset's coordinates into the correct WGS 84/Pseudo-Mercator projection, which seems to be the standard projection required by web map services.
thanks

benbovy commented 3 years ago

An XYZ service would be a very nice addition too and I guess it could share many things with a WMTS regarding their implementation.

For the (re)projection, you may want to look at how Xarray-leaflet handles it. It think it's based on morecantile and rioxarray.

iacopoff commented 3 years ago

Hi @benbovy, I think I have now something working. What is the best way for you to review/comment? Shall I open a PR or you could just try the xyz_router from my forked xpublish repo? I have added server/client notebooks that show how to use the xyz service. thanks!

benbovy commented 3 years ago

Yes please open a PR!

abkfenris commented 1 year ago

If folks are looking for WMS in Xpublish, @mpiannucci has created a plugin that will give you WMS routes without creating your own router.

mpiannucci commented 1 year ago

If folks are looking for WMS in Xpublish, @mpiannucci has created a plugin that will give you WMS routes without creating your own router.

Very much a work in progress, but it shows how easy the flow is with plugins

mpiannucci commented 1 year ago

I moved xpublish-wms to the xpublish-community org here!