Rendering Transformations¶
Rendering Transformations allow processing to be carried out on datasets within the GeoServer rendering pipeline. A typical transformation computes a derived or aggregated result from the input data, allowing various useful visualization effects to be obtained. Transformations may transform data from one format into another (i.e vector to raster or vice-versa), to provide an appropriate format for display.
The following table lists examples of various kinds of rendering transformations available in GeoServer:
Type |
Examples |
Raster-to-Vector |
Contour extracts contours from a DEM raster. RasterAsPointCollections extracts a vector field from a multi-band raster |
Vector-to-Raster |
BarnesSurfaceInterpolation computes a surface from scattered data points. Heatmap computes a heatmap surface from weighted data points. |
Vector-to-Vector |
PointStacker aggregates dense point data into clusters. |
Rendering transformations are invoked within SLD styles. Parameters may be supplied to control the appearance of the output. The rendered output for the layer is produced by applying the styling rules and symbolizers in the SLD to the result of transformation.
Rendering transformations are implemented using the same mechanism as Process Cookbook. They can thus also be executed via the WPS protocol, if required. Conversely, any WPS process can be executed as a transformation, as long as the input and output are appropriate for use within an SLD.
This section is a general guide to rendering transformation usage in GeoServer. For details of input, parameters, and output for any particular rendering transformation, refer to its own documentation.
Installation¶
Using Rendering Transformations requires the WPS extension to be installed. See Installing the WPS extension.
Note
The WPS service does not need to be enabled to use Rendering Transformations. To avoid unwanted consumption of server resources it may be desirable to disable the WPS service if it is not being used directly.
Usage¶
Rendering Transformations are invoked by adding the <Transformation>
element
to a <FeatureTypeStyle>
element in an SLD document.
This element specifies the name of the transformation process,
and usually includes parameter values controlling the operation of the transformation.
The <Transformation>
element syntax leverages the OGC Filter function syntax.
The content of the element is a <ogc:Function>
with the name of the rendering transformation process.
Transformation processes may accept some number of parameters,
which may be either required (in which case they must be specified),
or optional (in which case they may be omitted if the default value is acceptable).
Parameters are supplied as name/value pairs.
Each parameter’s name and value are supplied via another function <ogc:Function name="parameter">
.
The first argument to this function is an <ogc:Literal>
containing the name of the parameter.
The optional following arguments provide the value for the parameter (if any).
Some parameters accept only a single value, while others may accept a list of values.
As with any filter function argument, values may be supplied in several ways:
As a literal value
As a computed expression
As an SLD environment variable, whose actual value is supplied in the WMS request (see Variable substitution in SLD).
As a predefined SLD environment variable (which allows obtaining values for the current request such as output image width and height).
The order of the supplied parameters is not significant.
Most rendering transformations take as input a dataset to be transformed. This is supplied via a special named parameter which does not have a value specified. The name of the parameter is determined by the particular transformation being used. When the transformation is executed, the input dataset is passed to it via this parameter.
The input dataset is determined by the same query mechanism as used for all WMS requests, and can thus be filtered in the request if required.
In rendering transformations which take as input a featuretype (vector dataset)
and convert it to a raster dataset, in order to pass validation
the SLD needs to mention the geometry attribute of the input dataset
(even though it is not used).
This is done by specifying the attribute name in the symbolizer <Geometry>
element.
The output of the rendering transformation is styled using symbolizers appropriate to its format: PointSymbolizer, LineSymbolizer, PolygonSymbolizer, and TextSymbolizer for vector data, and RasterSymbolizer for raster coverage data.
If it is desired to display the input dataset in its original form, or transformed in another way, there are two options:
Another
<FeatureTypeStyle>
can be used in the same SLDAnother SLD can be created, and the layer displayed twice using the different SLDs
Notes¶
Rendering transformations may not work correctly in tiled mode, unless they have been specifically written to accommodate it.
Examples¶
Contour extraction¶
ras:Contour
is a Raster-to-Vector rendering transformation
which extracts contour lines at specified levels from a raster DEM.
The following SLD invokes the transformation
and styles the contours as black lines.
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <StyledLayerDescriptor version="1.0.0"
3 xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
4 xmlns="http://www.opengis.net/sld"
5 xmlns:ogc="http://www.opengis.net/ogc"
6 xmlns:xlink="http://www.w3.org/1999/xlink"
7 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
8 <NamedLayer>
9 <Name>contour_dem</Name>
10 <UserStyle>
11 <Title>Contour DEM</Title>
12 <Abstract>Extracts contours from DEM</Abstract>
13 <FeatureTypeStyle>
14 <Transformation>
15 <ogc:Function name="ras:Contour">
16 <ogc:Function name="parameter">
17 <ogc:Literal>data</ogc:Literal>
18 </ogc:Function>
19 <ogc:Function name="parameter">
20 <ogc:Literal>levels</ogc:Literal>
21 <ogc:Literal>1100</ogc:Literal>
22 <ogc:Literal>1200</ogc:Literal>
23 <ogc:Literal>1300</ogc:Literal>
24 <ogc:Literal>1400</ogc:Literal>
25 <ogc:Literal>1500</ogc:Literal>
26 <ogc:Literal>1600</ogc:Literal>
27 <ogc:Literal>1700</ogc:Literal>
28 <ogc:Literal>1800</ogc:Literal>
29 </ogc:Function>
30 </ogc:Function>
31 </Transformation>
32 <Rule>
33 <Name>rule1</Name>
34 <Title>Contour Line</Title>
35 <LineSymbolizer>
36 <Stroke>
37 <CssParameter name="stroke">#000000</CssParameter>
38 <CssParameter name="stroke-width">1</CssParameter>
39 </Stroke>
40 </LineSymbolizer>
41 <TextSymbolizer>
42 <Label>
43 <ogc:PropertyName>value</ogc:PropertyName>
44 </Label>
45 <Font>
46 <CssParameter name="font-family">Arial</CssParameter>
47 <CssParameter name="font-style">Normal</CssParameter>
48 <CssParameter name="font-size">10</CssParameter>
49 </Font>
50 <LabelPlacement>
51 <LinePlacement/>
52 </LabelPlacement>
53 <Halo>
54 <Radius>
55 <ogc:Literal>2</ogc:Literal>
56 </Radius>
57 <Fill>
58 <CssParameter name="fill">#FFFFFF</CssParameter>
59 <CssParameter name="fill-opacity">0.6</CssParameter>
60 </Fill>
61 </Halo>
62 <Fill>
63 <CssParameter name="fill">#000000</CssParameter>
64 </Fill>
65 <Priority>2000</Priority>
66 <VendorOption name="followLine">true</VendorOption>
67 <VendorOption name="repeat">100</VendorOption>
68 <VendorOption name="maxDisplacement">50</VendorOption>
69 <VendorOption name="maxAngleDelta">30</VendorOption>
70 </TextSymbolizer>
71 </Rule>
72 </FeatureTypeStyle>
73 </UserStyle>
74 </NamedLayer>
75 </StyledLayerDescriptor>
Key aspects of the SLD are:
Lines 14-15 define the rendering transformation, using the process
ras:Contour
.Lines 16-18 supply the input data parameter, named
data
in this process.Lines 19-29 supply values for the process’s
levels
parameter, which specifies the elevation levels for the contours to extract.Lines 35-40 specify a
LineSymbolizer
to style the contour lines.Lines 41-70 specify a
TextSymbolizer
to show the contour levels along the lines.
The result of using this transformation is shown in the following map image (which also shows the underlying DEM raster):
Heatmap generation¶
vec:Heatmap
is a Vector-to-Raster rendering transformation
which generates a heatmap surface from weighted point data.
The following SLD invokes a Heatmap rendering transformation
on a featuretype with point geometries
and an attribute pop2000
supplying the weight for the points
(in this example, a dataset of world urban areas is used).
The output is styled using a color ramp across the output data value range [0 .. 1].
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <StyledLayerDescriptor version="1.0.0"
3 xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
4 xmlns="http://www.opengis.net/sld"
5 xmlns:ogc="http://www.opengis.net/ogc"
6 xmlns:xlink="http://www.w3.org/1999/xlink"
7 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
8 <NamedLayer>
9 <Name>Heatmap</Name>
10 <UserStyle>
11 <Title>Heatmap</Title>
12 <Abstract>A heatmap surface showing population density</Abstract>
13 <FeatureTypeStyle>
14 <Transformation>
15 <ogc:Function name="vec:Heatmap">
16 <ogc:Function name="parameter">
17 <ogc:Literal>data</ogc:Literal>
18 </ogc:Function>
19 <ogc:Function name="parameter">
20 <ogc:Literal>weightAttr</ogc:Literal>
21 <ogc:Literal>pop2000</ogc:Literal>
22 </ogc:Function>
23 <ogc:Function name="parameter">
24 <ogc:Literal>radiusPixels</ogc:Literal>
25 <ogc:Function name="env">
26 <ogc:Literal>radius</ogc:Literal>
27 <ogc:Literal>100</ogc:Literal>
28 </ogc:Function>
29 </ogc:Function>
30 <ogc:Function name="parameter">
31 <ogc:Literal>pixelsPerCell</ogc:Literal>
32 <ogc:Literal>10</ogc:Literal>
33 </ogc:Function>
34 <ogc:Function name="parameter">
35 <ogc:Literal>outputBBOX</ogc:Literal>
36 <ogc:Function name="env">
37 <ogc:Literal>wms_bbox</ogc:Literal>
38 </ogc:Function>
39 </ogc:Function>
40 <ogc:Function name="parameter">
41 <ogc:Literal>outputWidth</ogc:Literal>
42 <ogc:Function name="env">
43 <ogc:Literal>wms_width</ogc:Literal>
44 </ogc:Function>
45 </ogc:Function>
46 <ogc:Function name="parameter">
47 <ogc:Literal>outputHeight</ogc:Literal>
48 <ogc:Function name="env">
49 <ogc:Literal>wms_height</ogc:Literal>
50 </ogc:Function>
51 </ogc:Function>
52 </ogc:Function>
53 </Transformation>
54 <Rule>
55 <RasterSymbolizer>
56 <!-- specify geometry attribute to pass validation -->
57 <Geometry>
58 <ogc:PropertyName>the_geom</ogc:PropertyName></Geometry>
59 <Opacity>0.6</Opacity>
60 <ColorMap type="ramp" >
61 <ColorMapEntry color="#FFFFFF" quantity="0" label="nodata"
62 opacity="0"/>
63 <ColorMapEntry color="#FFFFFF" quantity="0.02" label="nodata"
64 opacity="0"/>
65 <ColorMapEntry color="#4444FF" quantity=".1" label="nodata"/>
66 <ColorMapEntry color="#FF0000" quantity=".5" label="values" />
67 <ColorMapEntry color="#FFFF00" quantity="1.0" label="values" />
68 </ColorMap>
69 </RasterSymbolizer>
70 </Rule>
71 </FeatureTypeStyle>
72 </UserStyle>
73 </NamedLayer>
74 </StyledLayerDescriptor>
Key aspects of the SLD are:
Lines 14-15 define the rendering transformation, using the process
vec:Heatmap
.Lines 16-18 supply the input data parameter, named
data
in this process.Lines 19-22 supply a value for the process’s
weightAttr
parameter, which specifies the input attribute providing a weight for each data point.Lines 23-29 supply the value for the
radiusPixels
parameter, which controls the “spread” of the heatmap around each point. In this SLD the value of this parameter may be supplied by a SLD substitution variable calledradius
, with a default value of100
pixels.Lines 30-33 supply the
pixelsPerCell
parameter, which controls the resolution at which the heatmap raster is computed.Lines 34-38 supply the
outputBBOX
parameter, which is given the value of the standard SLD environment variablewms_bbox
.Lines 40-45 supply the
outputWidth
parameter, which is given the value of the standard SLD environment variablewms_width
.Lines 46-52 supply the
outputHeight
parameter, which is given the value of the standard SLD environment variablewms_height
.Lines 55-70 specify a
RasterSymbolizer
to style the computed raster surface. The symbolizer contains a ramped color map for the data range [0..1].Line 58 specifies the geometry attribute of the input featuretype, which is necessary to pass SLD validation.
This transformation styles a layer to produce a heatmap surface for the data in the requested map extent, as shown in the image below. (The map image also shows the original input data points styled by another SLD, as well as a base map layer.)
Running map algebra on the fly using Jiffle¶
The Jiffle
rendering transformation allows to run map algebra on the bands of an input raster
layer using the Jiffle language.
For example, the following style computes the NDVI index from a 13 bands Sentinel 2 image, in which
the red and NIR bands are the forth and eight bands (Jiffle band indexes are zero based),
and then displays the resulting index with a color map:
1<?xml version="1.0" encoding="UTF-8"?>
2<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/sld
3http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd" version="1.0.0">
4 <NamedLayer>
5 <Name>Sentinel2 NDVI</Name>
6 <UserStyle>
7 <Title>NDVI</Title>
8 <FeatureTypeStyle>
9 <Transformation>
10 <ogc:Function name="ras:Jiffle">
11 <ogc:Function name="parameter">
12 <ogc:Literal>coverage</ogc:Literal>
13 </ogc:Function>
14 <ogc:Function name="parameter">
15 <ogc:Literal>script</ogc:Literal>
16 <ogc:Literal>
17 nir = src[7];
18 vir = src[3];
19 dest = (nir - vir) / (nir + vir);
20 </ogc:Literal>
21 </ogc:Function>
22 </ogc:Function>
23 </Transformation>
24 <Rule>
25 <RasterSymbolizer>
26 <Opacity>1.0</Opacity>
27 <ColorMap>
28 <ColorMapEntry color="#000000" quantity="-1"/>
29 <ColorMapEntry color="#0000ff" quantity="-0.75"/>
30 <ColorMapEntry color="#ff00ff" quantity="-0.25"/>
31 <ColorMapEntry color="#ff0000" quantity="0"/>
32 <ColorMapEntry color="#ffff00" quantity="0.5"/>
33 <ColorMapEntry color="#00ff00" quantity="1"/>
34 </ColorMap>
35 </RasterSymbolizer>
36 </Rule>
37 </FeatureTypeStyle>
38 </UserStyle>
39 </NamedLayer>
40</StyledLayerDescriptor>
Here are a view of the area, using the visible color bands:
and then the display of the NDVI index computed with the above style:
Group candidate selection¶
vec:GroupCandidateSelection
is a Vector-to-Vector rendering transformation
which filters a FeatureCollection according to the aggregate operation chosen (MIN or MAX) and the groups defined through attribute names. Given a feature collection, groups according to the defined grouping attributes, and returns the feature having the MIN or MAX value for the chosen attribute. One feature will be chosen for each group.
The following SLD invokes the transformation:
<?xml version="1.0" encoding="UTF-8"?>
<sld:StyledLayerDescriptor xmlns:sld="http://www.opengis.net/sld" xmlns="http://www.opengis.net/sld" xmlns:st="http://www.stations.org/1.0" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0.0">
<sld:UserLayer>
<sld:UserStyle>
<sld:Name>Default Styler</sld:Name>
<sld:Title>Default Styler</sld:Title>
<sld:FeatureTypeStyle>
<Transformation>
<ogc:Function name="vec:GroupCandidateSelection">
<ogc:Function name="parameter">
<ogc:Literal>data</ogc:Literal>
</ogc:Function>
<ogc:Function name="parameter">
<ogc:Literal>operationAttribute</ogc:Literal>
<ogc:Literal>st:numericAttribute</ogc:Literal>
</ogc:Function>
<ogc:Function name="parameter">
<ogc:Literal>aggregation</ogc:Literal>
<ogc:Literal>MIN</ogc:Literal>
</ogc:Function>
<ogc:Function name="parameter">
<ogc:Literal>groupingAttributes</ogc:Literal>
<ogc:Literal>st:inferredAttribute</ogc:Literal>
<ogc:Literal>st:inferredAttribute2</ogc:Literal>
</ogc:Function>
</ogc:Function>
</Transformation>
<sld:rule>
<sld:Title>Stations Selected Candidate</sld:Title>
<sld:PointSymbolizer>
<Stroke>
<CssParameter name="stroke">#000000</CssParameter>
</Stroke>
</sld:PointSymbolizer>
</sld:rule>
</sld:FeatureTypeStyle>
</sld:UserStyle>
</sld:UserLayer>
</sld:StyledLayerDescriptor>
Where st:numericAttribute
, st:inferredAttribute
and st:inferredAttribute2
are attributes of the current layer being rendered, in this case, a layer based complex features, having the attributes used for rendering in the http://www.stations.org/1.0
namespace.
This vector process accepts four parameters:
data
: the data on which perform the computation.aggregation
: the type of operation required to filter data (MIN or MAX).operationAttribute
: the xpath to the attribute whose value will be used to perform the MIN or MAX operation.groupingAttributes
: a lists of xpath pointing to the attributes defining the features’ groups for which perform the filtering process.
Disabling GetFeatureInfo requests results transformation¶
By default GetFeatureInfo results are determined from the output after evaluating rendering transformation on the layer data. This behavior can be changed only for raster sources (i.e., raster-to-raster and raster-to-vector transformations). See section Disabling GetFeatureInfo requests results transformation to disable this behavior on a global or per virtual service basis. The WMS setting can be overridden for individual FeatureTypeStyle elements using the transformFeatureInfo
SLD vendor option (either true
or false
).
<VendorOption name="transformFeatureInfo">true</VendorOption>