geometry-transformations.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. .. _geometry_transformations:
  2. Geometry transformations in SLD
  3. ===============================
  4. SLD symbolizers may contain an optional ``<Geometry>`` element, which allows specifying which geometry attribute is to be rendered.
  5. In the common case of a featuretype with a single geometry attribute this element is usually omitted,
  6. but it is useful when a featuretype has multiple geometry-valued attributes.
  7. SLD 1.0 requires the ``<Geometry>`` content to be a ``<ogc:PropertyName>``.
  8. GeoServer extends this to allow a general SLD expression to be used.
  9. The expression can contain filter functions that manipulate geometries by transforming them into something different.
  10. This facility is called SLD *geometry transformations*.
  11. GeoServer provides a number of filter functions that can transform geometry.
  12. A full list is available in the :ref:`filter_function_reference`.
  13. They can be used to do things such as extracting line vertices or endpoints,
  14. offsetting polygons, or buffering geometries.
  15. Geometry transformations are computed in the geometry's original coordinate reference system, before any reprojection and rescaling to the output map is performed.
  16. For this reason, transformation parameters must be expressed in the units of the geometry CRS.
  17. This must be taken into account when using geometry transformations at different screen scales,
  18. since the parameters will not change with scale.
  19. Examples
  20. --------
  21. Let's look at some examples.
  22. Extracting vertices
  23. ^^^^^^^^^^^^^^^^^^^
  24. Here is an example that allows one to extract all the vertices of a geometry, and make them visible in a map, using the ``vertices`` function:
  25. .. code-block:: xml
  26. :linenos:
  27. <PointSymbolizer>
  28. <Geometry>
  29. <ogc:Function name="vertices">
  30. <ogc:PropertyName>the_geom</ogc:PropertyName>
  31. </ogc:Function>
  32. </Geometry>
  33. <Graphic>
  34. <Mark>
  35. <WellKnownName>square</WellKnownName>
  36. <Fill>
  37. <CssParameter name="fill">#FF0000</CssParameter>
  38. </Fill>
  39. </Mark>
  40. <Size>6</Size>
  41. </Graphic>
  42. </PointSymbolizer>
  43. :download:`View the full "Vertices" SLD <artifacts/vertices.sld>`
  44. Applied to the sample `tasmania_roads` layer this will result in:
  45. .. figure:: images/vertices.png
  46. :align: center
  47. *Extracting and showing the vertices out of a geometry*
  48. Start and end point
  49. ^^^^^^^^^^^^^^^^^^^
  50. The `startPoint` and `endPoint` functions can be used to extract the start and end point of a line.
  51. .. code-block:: xml
  52. :linenos:
  53. <PointSymbolizer>
  54. <Geometry>
  55. <ogc:Function name="startPoint">
  56. <ogc:PropertyName>the_geom</ogc:PropertyName>
  57. </ogc:Function>
  58. </Geometry>
  59. <Graphic>
  60. <Mark>
  61. <WellKnownName>square</WellKnownName>
  62. <Stroke>
  63. <CssParameter name="stroke">0x00FF00</CssParameter>
  64. <CssParameter name="stroke-width">1.5</CssParameter>
  65. </Stroke>
  66. </Mark>
  67. <Size>8</Size>
  68. </Graphic>
  69. </PointSymbolizer>
  70. <PointSymbolizer>
  71. <Geometry>
  72. <ogc:Function name="endPoint">
  73. <ogc:PropertyName>the_geom</ogc:PropertyName>
  74. </ogc:Function>
  75. </Geometry>
  76. <Graphic>
  77. <Mark>
  78. <WellKnownName>circle</WellKnownName>
  79. <Fill>
  80. <CssParameter name="fill">0xFF0000</CssParameter>
  81. </Fill>
  82. </Mark>
  83. <Size>4</Size>
  84. </Graphic>
  85. </PointSymbolizer>
  86. :download:`View the full "StartEnd" SLD <artifacts/startend.sld>`
  87. Applied to the sample `tasmania_roads` layer this will result in:
  88. .. figure:: images/startend.png
  89. :align: center
  90. *Extracting start and end point of a line*
  91. Drop shadow
  92. ^^^^^^^^^^^
  93. The `offset` function can be used to create drop shadow effects below polygons.
  94. Notice that the offset values reflect the fact that the data used in the example is in a geographic coordinate system.
  95. .. code-block:: xml
  96. :linenos:
  97. <PolygonSymbolizer>
  98. <Geometry>
  99. <ogc:Function name="offset">
  100. <ogc:PropertyName>the_geom</ogc:PropertyName>
  101. <ogc:Literal>0.00004</ogc:Literal>
  102. <ogc:Literal>-0.00004</ogc:Literal>
  103. </ogc:Function>
  104. </Geometry>
  105. <Fill>
  106. <CssParameter name="fill">#555555</CssParameter>
  107. </Fill>
  108. </PolygonSymbolizer>
  109. :download:`View the full "Shadow" SLD <artifacts/shadow.sld>`
  110. Applied to the sample `tasmania_roads` layer this will result in:
  111. .. figure:: images/shadow.png
  112. :align: center
  113. *Dropping building shadows*
  114. Performance tips
  115. ----------------
  116. GeoServer's filter functions contain a number of set-related or constructive geometric functions,
  117. such as ``buffer``, ``intersection``, ``difference`` and others.
  118. These can be used as geometry transformations, but they be can quite heavy in terms of CPU consumption so it is advisable to use them with care.
  119. One strategy is to activate them only at higher zoom levels, so that fewer features are processed.
  120. Buffering can often be visually approximated by using very large strokes together with round line joins and line caps.
  121. This avoids incurring the performance cost of a true geometric buffer transformation.
  122. Adding new transformations
  123. --------------------------
  124. Additional filter functions can be developed in Java and then deployed in a JAR file as a GeoServer plugin.
  125. A guide is not available at this time, but see the GeoTools ``main`` module for examples.