rendering-transform.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. .. _rendering_transform:
  2. Rendering Transformations
  3. =========================
  4. **Rendering Transformations** allow processing to be carried out
  5. on datasets within the GeoServer rendering pipeline.
  6. A typical transformation computes a derived or aggregated result from the input data,
  7. allowing various useful visualization effects to be obtained.
  8. Transformations may transform data from one format into another
  9. (i.e vector to raster or vice-versa),
  10. to provide an appropriate format for display.
  11. The following table lists examples of various kinds of rendering transformations
  12. available in GeoServer:
  13. .. list-table::
  14. :widths: 25 75
  15. * - **Type**
  16. - **Examples**
  17. * - Raster-to-Vector
  18. - **Contour** extracts contours from a DEM raster.
  19. **RasterAsPointCollections** extracts a vector field from a multi-band raster
  20. * - Vector-to-Raster
  21. - **BarnesSurfaceInterpolation** computes a surface from scattered data points.
  22. **Heatmap** computes a heatmap surface from weighted data points.
  23. * - Vector-to-Vector
  24. - **PointStacker** aggregates dense point data into clusters.
  25. Rendering transformations are invoked within SLD styles.
  26. Parameters may be supplied to control the appearance of the output.
  27. The rendered output for the layer is produced
  28. by applying the styling rules and symbolizers in the SLD to the result of transformation.
  29. Rendering transformations are implemented using the same mechanism as :ref:`wps_processes`.
  30. They can thus also be executed via the WPS protocol, if required.
  31. Conversely, any WPS process can be executed as a transformation, as long
  32. as the input and output are appropriate for use within an SLD.
  33. This section is a general guide to rendering transformation usage in GeoServer.
  34. For details of input, parameters, and output for any particular
  35. rendering transformation, refer to its own documentation.
  36. Installation
  37. ------------
  38. Using Rendering Transformations requires the WPS extension to be installed. See :ref:`wps_install`.
  39. .. note::
  40. The WPS service does not need to be **enabled** to use Rendering Transformations.
  41. To avoid unwanted consumption of server resources
  42. it may be desirable to disable the WPS service if it is not being used directly.
  43. Usage
  44. -----
  45. Rendering Transformations are invoked by adding the ``<Transformation>`` element
  46. to a ``<FeatureTypeStyle>`` element in an SLD document.
  47. This element specifies the name of the transformation process,
  48. and usually includes parameter values controlling the operation of the transformation.
  49. The ``<Transformation>`` element syntax leverages the OGC Filter function syntax.
  50. The content of the element is a ``<ogc:Function>`` with the name of the rendering transformation process.
  51. Transformation processes may accept some number of parameters,
  52. which may be either required (in which case they must be specified),
  53. or optional (in which case they may be omitted if the default value is acceptable).
  54. Parameters are supplied as name/value pairs.
  55. Each parameter's name and value are supplied via another function ``<ogc:Function name="parameter">``.
  56. The first argument to this function is an ``<ogc:Literal>`` containing the name of the parameter.
  57. The optional following arguments provide the value for the parameter (if any).
  58. Some parameters accept only a single value, while others may accept a list of values.
  59. As with any filter function argument, values may be supplied in several ways:
  60. * As a literal value
  61. * As a computed expression
  62. * As an SLD environment variable, whose actual value is supplied in the WMS request
  63. (see :ref:`sld_variable_substitution`).
  64. * As a predefined SLD environment variable (which allows obtaining values
  65. for the current request such as output image width and height).
  66. The order of the supplied parameters is not significant.
  67. Most rendering transformations take as input a dataset to be transformed.
  68. This is supplied via a special named parameter which does not have a value specified.
  69. The name of the parameter is determined by the particular transformation being used.
  70. When the transformation is executed, the input dataset
  71. is passed to it via this parameter.
  72. The input dataset is determined by the same query mechanism as used for all WMS requests,
  73. and can thus be filtered in the request if required.
  74. In rendering transformations which take as input a featuretype (vector dataset)
  75. and convert it to a raster dataset, in order to pass validation
  76. the SLD needs to mention the geometry attribute of the input dataset
  77. (even though it is not used).
  78. This is done by specifying the attribute name in the symbolizer ``<Geometry>`` element.
  79. The output of the rendering transformation is styled using symbolizers
  80. appropriate to its format:
  81. :ref:`sld_reference_pointsymbolizer`, :ref:`sld_reference_linesymbolizer`, :ref:`sld_reference_polygonsymbolizer`,
  82. and :ref:`sld_reference_textsymbolizer` for vector data,
  83. and :ref:`sld_reference_rastersymbolizer` for raster coverage data.
  84. If it is desired to display the input dataset in its original form,
  85. or transformed in another way, there are two options:
  86. * Another ``<FeatureTypeStyle>`` can be used in the same SLD
  87. * Another SLD can be created, and the layer displayed twice using the different SLDs
  88. Notes
  89. ^^^^^
  90. * Rendering transformations may not work correctly in tiled mode,
  91. unless they have been specifically written to accommodate it.
  92. Examples
  93. --------
  94. Contour extraction
  95. ^^^^^^^^^^^^^^^^^^
  96. ``ras:Contour`` is a **Raster-to-Vector** rendering transformation
  97. which extracts contour lines at specified levels from a raster DEM.
  98. The following SLD invokes the transformation
  99. and styles the contours as black lines.
  100. .. code-block:: xml
  101. :linenos:
  102. <?xml version="1.0" encoding="ISO-8859-1"?>
  103. <StyledLayerDescriptor version="1.0.0"
  104. xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
  105. xmlns="http://www.opengis.net/sld"
  106. xmlns:ogc="http://www.opengis.net/ogc"
  107. xmlns:xlink="http://www.w3.org/1999/xlink"
  108. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  109. <NamedLayer>
  110. <Name>contour_dem</Name>
  111. <UserStyle>
  112. <Title>Contour DEM</Title>
  113. <Abstract>Extracts contours from DEM</Abstract>
  114. <FeatureTypeStyle>
  115. <Transformation>
  116. <ogc:Function name="ras:Contour">
  117. <ogc:Function name="parameter">
  118. <ogc:Literal>data</ogc:Literal>
  119. </ogc:Function>
  120. <ogc:Function name="parameter">
  121. <ogc:Literal>levels</ogc:Literal>
  122. <ogc:Literal>1100</ogc:Literal>
  123. <ogc:Literal>1200</ogc:Literal>
  124. <ogc:Literal>1300</ogc:Literal>
  125. <ogc:Literal>1400</ogc:Literal>
  126. <ogc:Literal>1500</ogc:Literal>
  127. <ogc:Literal>1600</ogc:Literal>
  128. <ogc:Literal>1700</ogc:Literal>
  129. <ogc:Literal>1800</ogc:Literal>
  130. </ogc:Function>
  131. </ogc:Function>
  132. </Transformation>
  133. <Rule>
  134. <Name>rule1</Name>
  135. <Title>Contour Line</Title>
  136. <LineSymbolizer>
  137. <Stroke>
  138. <CssParameter name="stroke">#000000</CssParameter>
  139. <CssParameter name="stroke-width">1</CssParameter>
  140. </Stroke>
  141. </LineSymbolizer>
  142. <TextSymbolizer>
  143. <Label>
  144. <ogc:PropertyName>value</ogc:PropertyName>
  145. </Label>
  146. <Font>
  147. <CssParameter name="font-family">Arial</CssParameter>
  148. <CssParameter name="font-style">Normal</CssParameter>
  149. <CssParameter name="font-size">10</CssParameter>
  150. </Font>
  151. <LabelPlacement>
  152. <LinePlacement/>
  153. </LabelPlacement>
  154. <Halo>
  155. <Radius>
  156. <ogc:Literal>2</ogc:Literal>
  157. </Radius>
  158. <Fill>
  159. <CssParameter name="fill">#FFFFFF</CssParameter>
  160. <CssParameter name="fill-opacity">0.6</CssParameter>
  161. </Fill>
  162. </Halo>
  163. <Fill>
  164. <CssParameter name="fill">#000000</CssParameter>
  165. </Fill>
  166. <Priority>2000</Priority>
  167. <VendorOption name="followLine">true</VendorOption>
  168. <VendorOption name="repeat">100</VendorOption>
  169. <VendorOption name="maxDisplacement">50</VendorOption>
  170. <VendorOption name="maxAngleDelta">30</VendorOption>
  171. </TextSymbolizer>
  172. </Rule>
  173. </FeatureTypeStyle>
  174. </UserStyle>
  175. </NamedLayer>
  176. </StyledLayerDescriptor>
  177. Key aspects of the SLD are:
  178. * **Lines 14-15** define the rendering transformation, using the process ``ras:Contour``.
  179. * **Lines 16-18** supply the input data parameter, named ``data`` in this process.
  180. * **Lines 19-29** supply values for the process's ``levels`` parameter,
  181. which specifies the elevation levels for the contours to extract.
  182. * **Lines 35-40** specify a ``LineSymbolizer`` to style the contour lines.
  183. * **Lines 41-70** specify a ``TextSymbolizer`` to show the contour levels along the lines.
  184. The result of using this transformation is shown in the following map image
  185. (which also shows the underlying DEM raster):
  186. .. figure:: images/transform_contour_sf_dem.png
  187. :align: center
  188. Heatmap generation
  189. ^^^^^^^^^^^^^^^^^^
  190. ``vec:Heatmap`` is a **Vector-to-Raster** rendering transformation
  191. which generates a heatmap surface from weighted point data.
  192. The following SLD invokes a Heatmap rendering transformation
  193. on a featuretype with point geometries
  194. and an attribute ``pop2000`` supplying the weight for the points
  195. (in this example, a dataset of world urban areas is used).
  196. The output is styled using a color ramp across the output data value range [0 .. 1].
  197. .. code-block:: xml
  198. :linenos:
  199. <?xml version="1.0" encoding="ISO-8859-1"?>
  200. <StyledLayerDescriptor version="1.0.0"
  201. xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
  202. xmlns="http://www.opengis.net/sld"
  203. xmlns:ogc="http://www.opengis.net/ogc"
  204. xmlns:xlink="http://www.w3.org/1999/xlink"
  205. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  206. <NamedLayer>
  207. <Name>Heatmap</Name>
  208. <UserStyle>
  209. <Title>Heatmap</Title>
  210. <Abstract>A heatmap surface showing population density</Abstract>
  211. <FeatureTypeStyle>
  212. <Transformation>
  213. <ogc:Function name="vec:Heatmap">
  214. <ogc:Function name="parameter">
  215. <ogc:Literal>data</ogc:Literal>
  216. </ogc:Function>
  217. <ogc:Function name="parameter">
  218. <ogc:Literal>weightAttr</ogc:Literal>
  219. <ogc:Literal>pop2000</ogc:Literal>
  220. </ogc:Function>
  221. <ogc:Function name="parameter">
  222. <ogc:Literal>radiusPixels</ogc:Literal>
  223. <ogc:Function name="env">
  224. <ogc:Literal>radius</ogc:Literal>
  225. <ogc:Literal>100</ogc:Literal>
  226. </ogc:Function>
  227. </ogc:Function>
  228. <ogc:Function name="parameter">
  229. <ogc:Literal>pixelsPerCell</ogc:Literal>
  230. <ogc:Literal>10</ogc:Literal>
  231. </ogc:Function>
  232. <ogc:Function name="parameter">
  233. <ogc:Literal>outputBBOX</ogc:Literal>
  234. <ogc:Function name="env">
  235. <ogc:Literal>wms_bbox</ogc:Literal>
  236. </ogc:Function>
  237. </ogc:Function>
  238. <ogc:Function name="parameter">
  239. <ogc:Literal>outputWidth</ogc:Literal>
  240. <ogc:Function name="env">
  241. <ogc:Literal>wms_width</ogc:Literal>
  242. </ogc:Function>
  243. </ogc:Function>
  244. <ogc:Function name="parameter">
  245. <ogc:Literal>outputHeight</ogc:Literal>
  246. <ogc:Function name="env">
  247. <ogc:Literal>wms_height</ogc:Literal>
  248. </ogc:Function>
  249. </ogc:Function>
  250. </ogc:Function>
  251. </Transformation>
  252. <Rule>
  253. <RasterSymbolizer>
  254. <!-- specify geometry attribute to pass validation -->
  255. <Geometry>
  256. <ogc:PropertyName>the_geom</ogc:PropertyName></Geometry>
  257. <Opacity>0.6</Opacity>
  258. <ColorMap type="ramp" >
  259. <ColorMapEntry color="#FFFFFF" quantity="0" label="nodata"
  260. opacity="0"/>
  261. <ColorMapEntry color="#FFFFFF" quantity="0.02" label="nodata"
  262. opacity="0"/>
  263. <ColorMapEntry color="#4444FF" quantity=".1" label="nodata"/>
  264. <ColorMapEntry color="#FF0000" quantity=".5" label="values" />
  265. <ColorMapEntry color="#FFFF00" quantity="1.0" label="values" />
  266. </ColorMap>
  267. </RasterSymbolizer>
  268. </Rule>
  269. </FeatureTypeStyle>
  270. </UserStyle>
  271. </NamedLayer>
  272. </StyledLayerDescriptor>
  273. Key aspects of the SLD are:
  274. * **Lines 14-15** define the rendering transformation, using the process ``vec:Heatmap``.
  275. * **Lines 16-18** supply the input data parameter, named ``data`` in this process.
  276. * **Lines 19-22** supply a value for the process's ``weightAttr`` parameter,
  277. which specifies the input attribute providing a weight for each data point.
  278. * **Lines 23-29** supply the value for the ``radiusPixels`` parameter,
  279. which controls the "spread" of the heatmap around each point.
  280. In this SLD the value of this parameter may be supplied by a SLD substitution variable
  281. called ``radius``, with a default value of ``100`` pixels.
  282. * **Lines 30-33** supply the ``pixelsPerCell`` parameter,
  283. which controls the resolution at which the heatmap raster is computed.
  284. * **Lines 34-38** supply the ``outputBBOX`` parameter,
  285. which is given the value of the standard SLD environment variable ``wms_bbox``.
  286. * **Lines 40-45** supply the ``outputWidth`` parameter,
  287. which is given the value of the standard SLD environment variable ``wms_width``.
  288. * **Lines 46-52** supply the ``outputHeight`` parameter,
  289. which is given the value of the standard SLD environment variable ``wms_height``.
  290. * **Lines 55-70** specify a ``RasterSymbolizer`` to style the computed raster surface.
  291. The symbolizer contains a ramped color map for the data range [0..1].
  292. * **Line 58** specifies the geometry attribute of the input featuretype,
  293. which is necessary to pass SLD validation.
  294. This transformation styles a layer to produce a heatmap surface
  295. for the data in the requested map extent, as shown in the image below.
  296. (The map image also shows the original input data points
  297. styled by another SLD, as well as a base map layer.)
  298. .. figure:: images/heatmap_urban_us_east.png
  299. :align: center
  300. Running map algebra on the fly using Jiffle
  301. -------------------------------------------
  302. The ``Jiffle`` rendering transformation allows to run map algebra on the bands of an input raster
  303. layer using the `Jiffle language <https://github.com/geosolutions-it/jai-ext/wiki/Jiffle---language-summary>`_.
  304. For example, the following style computes the NDVI index from a 13 bands Sentinel 2 image, in which
  305. the red and NIR bands are the forth and eight bands (Jiffle band indexes are zero based),
  306. and then displays the resulting index with a color map:
  307. .. code-block:: xml
  308. :linenos:
  309. <?xml version="1.0" encoding="UTF-8"?>
  310. <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
  311. http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd" version="1.0.0">
  312. <NamedLayer>
  313. <Name>Sentinel2 NDVI</Name>
  314. <UserStyle>
  315. <Title>NDVI</Title>
  316. <FeatureTypeStyle>
  317. <Transformation>
  318. <ogc:Function name="ras:Jiffle">
  319. <ogc:Function name="parameter">
  320. <ogc:Literal>coverage</ogc:Literal>
  321. </ogc:Function>
  322. <ogc:Function name="parameter">
  323. <ogc:Literal>script</ogc:Literal>
  324. <ogc:Literal>
  325. nir = src[7];
  326. vir = src[3];
  327. dest = (nir - vir) / (nir + vir);
  328. </ogc:Literal>
  329. </ogc:Function>
  330. </ogc:Function>
  331. </Transformation>
  332. <Rule>
  333. <RasterSymbolizer>
  334. <Opacity>1.0</Opacity>
  335. <ColorMap>
  336. <ColorMapEntry color="#000000" quantity="-1"/>
  337. <ColorMapEntry color="#0000ff" quantity="-0.75"/>
  338. <ColorMapEntry color="#ff00ff" quantity="-0.25"/>
  339. <ColorMapEntry color="#ff0000" quantity="0"/>
  340. <ColorMapEntry color="#ffff00" quantity="0.5"/>
  341. <ColorMapEntry color="#00ff00" quantity="1"/>
  342. </ColorMap>
  343. </RasterSymbolizer>
  344. </Rule>
  345. </FeatureTypeStyle>
  346. </UserStyle>
  347. </NamedLayer>
  348. </StyledLayerDescriptor>
  349. Here are a view of the area, using the visible color bands:
  350. .. figure:: images/s2-visible.png
  351. :align: center
  352. and then the display of the NDVI index computed with the above style:
  353. .. figure:: images/s2-ndvi.png
  354. :align: center
  355. Group candidate selection
  356. ^^^^^^^^^^^^^^^^^^^^^^^^^
  357. ``vec:GroupCandidateSelection`` is a **Vector-to-Vector** rendering transformation
  358. 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.
  359. The following SLD invokes the transformation:
  360. .. code-block:: xml
  361. <?xml version="1.0" encoding="UTF-8"?>
  362. <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">
  363. <sld:UserLayer>
  364. <sld:UserStyle>
  365. <sld:Name>Default Styler</sld:Name>
  366. <sld:Title>Default Styler</sld:Title>
  367. <sld:FeatureTypeStyle>
  368. <Transformation>
  369. <ogc:Function name="vec:GroupCandidateSelection">
  370. <ogc:Function name="parameter">
  371. <ogc:Literal>data</ogc:Literal>
  372. </ogc:Function>
  373. <ogc:Function name="parameter">
  374. <ogc:Literal>operationAttribute</ogc:Literal>
  375. <ogc:Literal>st:numericAttribute</ogc:Literal>
  376. </ogc:Function>
  377. <ogc:Function name="parameter">
  378. <ogc:Literal>aggregation</ogc:Literal>
  379. <ogc:Literal>MIN</ogc:Literal>
  380. </ogc:Function>
  381. <ogc:Function name="parameter">
  382. <ogc:Literal>groupingAttributes</ogc:Literal>
  383. <ogc:Literal>st:inferredAttribute</ogc:Literal>
  384. <ogc:Literal>st:inferredAttribute2</ogc:Literal>
  385. </ogc:Function>
  386. </ogc:Function>
  387. </Transformation>
  388. <sld:rule>
  389. <sld:Title>Stations Selected Candidate</sld:Title>
  390. <sld:PointSymbolizer>
  391. <Stroke>
  392. <CssParameter name="stroke">#000000</CssParameter>
  393. </Stroke>
  394. </sld:PointSymbolizer>
  395. </sld:rule>
  396. </sld:FeatureTypeStyle>
  397. </sld:UserStyle>
  398. </sld:UserLayer>
  399. </sld:StyledLayerDescriptor>
  400. 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.
  401. This vector process accepts four parameters:
  402. * ``data``: the data on which perform the computation.
  403. * ``aggregation``: the type of operation required to filter data (MIN or MAX).
  404. * ``operationAttribute``: the xpath to the attribute whose value will be used to perform the MIN or MAX operation.
  405. * ``groupingAttributes``: a lists of xpath pointing to the attributes defining the features' groups for which perform the filtering process.
  406. Disabling GetFeatureInfo requests results transformation
  407. --------------------------------------------------------
  408. 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 :ref:`services_webadmin_wms_featureinfo_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``).
  409. .. code-block:: xml
  410. <VendorOption name="transformFeatureInfo">true</VendorOption>