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