xpublish icon indicating copy to clipboard operation
xpublish copied to clipboard

Would it be feasible to provide a WMS route?

Open cwerner opened this issue 5 years ago • 15 comments

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... 🤷‍♂️

cwerner avatar Aug 28 '20 14:08 cwerner

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.

jhamman avatar Aug 28 '20 16:08 jhamman

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

cwerner avatar Aug 28 '20 18:08 cwerner

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.

benbovy avatar Sep 18 '20 07:09 benbovy

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 :).

iacopoff avatar Jun 14 '21 08:06 iacopoff

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

  • Titiler implements WMTS endpoints also using fastAPI, although using different data sources than xarray.Dataset.

  • Xarray-leaflet dynamically generates and serves images from xarray objects, although it targets another front-end / protocol.

benbovy avatar Jun 14 '21 09:06 benbovy

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 avatar Jun 15 '21 06:06 iacopoff

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

  • WMTS interface (GetCapabilities, GetTile, and possibly GetFeatureInfo), as new custom router in xpublish
  • Functionality to generate tiles from xarray.Dataset (either static or dynamically) stored as png images in a temporary folder, so that they can be requested by the web client

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

iacopoff avatar Jul 15 '21 09:07 iacopoff

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.

benbovy avatar Jul 20 '21 12:07 benbovy

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

iacopoff avatar Jul 20 '21 13:07 iacopoff

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.

benbovy avatar Jul 20 '21 15:07 benbovy

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!

iacopoff avatar Jul 24 '21 12:07 iacopoff

Yes please open a PR!

benbovy avatar Jul 26 '21 07:07 benbovy

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

abkfenris avatar Mar 30 '23 19:03 abkfenris

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 avatar Apr 07 '23 00:04 mpiannucci

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

mpiannucci avatar Apr 07 '23 21:04 mpiannucci