Search code examples
javascriptpythonscriptingopenlayersgeoserver

Contouring function with OpenLayers3/GeoServer


We're stocking rasters in our database, and we want to implement a function inside our web app that will allow the user to add contour lines to the map based on a raster. We want the user to be able to customize the contour levels and colors.

Do anyone have an idea which tools I should be using? I think that I should be using the Python scripting extension of GeoServer, but I don't know if this is possible to implement such a function.

Thanks for your comments !


Solution

  • The easiest way to create contours on the fly from a raster data source in GeoServer is to use the rendering transform gs:Contour. There is a full example in the documentation. This shows how to use an SLD file to specify the contour values, which are then extracted on render and drawn using the remainder of the SLD file. The example assumes a fixed set of contours using a static file, this is easiest.

    But the WMS standard allows a client (OpenLayers) to upload a new SLD file with a map request - this is exactly what you want to do here. I suggest that you generate a working SLD file and then use a templating engine of your choice to insert the user's chosen values into the file before sending it to GeoServer for processing. The downside of this is that you will need to send the SLD file with each request and tiling will probably not work well (at all?). You may be able to speed things up a bit by using library mode for the styles, but at the risk of complicating the client.