Developers Corner: have your SLD transform raster data into vectors on the fly

Hi all,

in this post we‘d like to share our most recent endeavor in dynamic data rendering within the GeoServer and GeoTools open source projects.
The problem
Suppose you have a set of scientific raster data sets, maybe they represent some sort of concentration, elevation, or maybe they represent wind, currents, or some other vector phenomena via two bands (one for magnitude, one for direction).
Now, you have lots of them and people want to display them in various ways. Raster with color scales are nice, but often you need to render them in other ways, such as contour lines, polygons catching all the pixels within certain ranges, or vector fields (think wind barbs).
Those are all raster to vector conversion processes that a WPS can take care of. However, suppose you also have a ton of those raster data, and that the raster classification parameters need to be dynamic, with a user providing, for example, the contour levels to extract.
Now you’re facing a somewhat hard problem, in theory you would have to:
  • call the WPS with the given data
  • store the results somewhere
  • register that new layer as a published WMS layer, along with the proper style
  • update the viewer to add that layer
  • purge that temporary layer once the user is done or wants a different set of parameters to be applied in the transformations
To add icing on the cake, suppose your datasets are massive, so doing the WPS extraction at full resolution can take its dear time…. does not really sound like a situation one would like your server and client infrastructure to deal with.

The solution

Instead of doing all of the above work, wouldn’t it be nice to just specify the transformation needed in the style sheet? That’s exactly the road we decided to follow.
We’ve created and SLD extension allowing to pipe a process (yes, a WPS one) inside the SLD so that it can be dinamically updated. It looks like the following:

The above would call on the fly the contouring process and then render its result: no need to create and manage a new vector layer, the data is generated on the fly only when needed.
Here is how the result looks (using a style sheet just a bit more complex than the above one):

Chaining transformations we can also extract and display the value of the single pixels and show it as a label, as in the following example:

Alternatively you may want to extract the polygons containing all the cells in a certain data range, like in the following transformation:

The result, coloring each range in a different way, is:

Finally, we may want to extract as set of wind arrows starting from a raster having the horizontal and vertical components of a vector (u and v):

We’re linking to the full SLD of this last one because it’s quite the testament of SLD flexibility: the magnitude and direction of the arrow are computed on the fly by using filter functions (functions that are part of GeoTools/GeoServer, you may not find them in just any implementation).

One important bit here is that the raster to vector conversion are happening at the visualization resolution: this means you can have the transformation work against large datasets without heavy slowdowns, because it is going to happen only in the area you’re looking at, and at the resolution that would have been used to draw the raster.
This makes it possible to get fast, on the fly operations that do not excessively slow down rendering.

This is yet another example of how processing capabilities can be integrated into GeoServer, and it’s by no means the last. Also, there is still plenty that can be done to improve this kind of transformations, as well as new transformations to support mapping tools such as heatmaps. Interested? Let us know!

The GeoSolutions team
 
  • That is brilliant!
    I am using GeoServer for publishing meteo data layers and this would save me a lot of work.
    Starting from which version is this supposed to be available? Shall I install any special extension?

  • At the moment it’s only available on trunk, which will eventually become GS 2.2 in … uh, at most one year.
    You can get nightly builds here, and you will need the WPS extension installed to have it working:
    http://gridlock.opengeo.org/geoserver/trunk/

    However we plan to back-port those changes to the 2.1.x stable series after the 2.1.0 release is out (2.1.0 is already in RC state, so we cannot do big backports like this one right now).

  • Will

    I could really use some help trying to implement this type of thing, I’m using the newest Geoserver 2.2 beta, and the geoserver blog says rendering transformations are now available, but when trying to copy the sld you provided to a style, it breaks trying to validate, as it thinks is not a possible tag or something, any help?

  • Ciao Will,
    adding m2 2 cents here. I believe these SLD extensions are not valid per se as the OGC original SLD schemas, therefore I would not try to validate them.

    Submit the style anyway and pla with it. If that still does not work then I would move the discussion to the ML of GeoServer.

  • Hi Andrea,

    I’m trying to concatenate a BarnesSurface transform with the RasterAsPointCollection but I can’t get the values as a result of the process.

    I’ve dropped here the minimal SLD to print points with labels of the interpolated values but I get nothing (no error, no label), only the points. This SLD should work on a geographic (4326) point layer with a numeric field called “valor”.

    I’ve tested with Band, Band1, value, etc without success. I’m wondering if I miss something on the RasterAsPointCollection transformation definition (looking at the source code it seems it only needs the data).

    The interpolation render works alone and concatenated with contours transform but I can’t get the RasterAsPointCollection style.

    Any advice? Thanks in advance!