syntax.rst 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. .. _sld-extensions_z_order_syntax:
  2. Enabling z-ordering in a single FeatureTypeStyle
  3. ================================================
  4. The z-ordering is implemented as a new FeatureTypeStyle vendor option, ``sortBy``, which controls
  5. in which order the features are extracted from the data source, and thus painted.
  6. The ``sortBy`` syntax is the same as the WFS one, that is, a list of comma separated field names,
  7. with an optional direction modifier (ascending being the default)::
  8. field1 [A|D], field2 [A|D], ... , fieldN [A|D]
  9. Some examples:
  10. * "z": sorts the features based on the ``z`` field, ascending (lower z values are painted first, higher later)
  11. * "cat,z D": sorts the features on the ``cat`` attribute, with ascending order, and for those that have the same ``cat`` value, the sorting is on descending ``z``
  12. * "cat D,z D": sorts the features on the ``cat`` attribute, with descending order, and for those that have the same ``cat`` value, the sorting is on descending ``z``
  13. So, if we wanted to order features based on a single "elevation" attribute we'd be using the
  14. following SLD snippet:
  15. .. code-block:: xml
  16. ...
  17. <sld:FeatureTypeStyle>
  18. <sld:Rule>
  19. ...
  20. <!-- filters and symbolizers here -->
  21. ...
  22. </sld:Rule>
  23. <sld:VendorOption name="sortBy">elevation</sld:VendorOption>
  24. </sld:FeatureTypeStyle>
  25. ...
  26. z-ordering across FeatureTypeStyle
  27. ----------------------------------
  28. It is a common need to perform road casing against a complex road network, which can have its own
  29. z-ordering needs (e.g., over and under passes).
  30. Casing is normally achieved by using two separate two ``FeatureTypeStyle``, one drawing a thick
  31. line, one drawing a thin one.
  32. Let's consider a simple data set, made of just three roads::
  33. _=geom:LineString:404000,z:int
  34. Line.1=LINESTRING(0 4, 10 4)|1
  35. Line.2=LINESTRING(0 6, 10 6)|3
  36. Line.3=LINESTRING(7 0, 7 10)|1
  37. Adding a "sortBy" rule to both ``FeatureTypeStyle`` objects will achieve no visible result:
  38. .. code-block:: xml
  39. <?xml version="1.0" encoding="ISO-8859-1"?>
  40. <StyledLayerDescriptor version="1.0.0"
  41. xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
  42. xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
  43. xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  44. <!-- a named layer is the basic building block of an sld document -->
  45. <NamedLayer>
  46. <UserStyle>
  47. <FeatureTypeStyle>
  48. <Rule>
  49. <LineSymbolizer>
  50. <Stroke>
  51. <CssParameter name="stroke">#FF0000</CssParameter>
  52. <CssParameter name="stroke-width">8</CssParameter>
  53. </Stroke>
  54. </LineSymbolizer>
  55. </Rule>
  56. <sld:VendorOption name="sortBy">z</sld:VendorOption>
  57. </FeatureTypeStyle>
  58. <FeatureTypeStyle>
  59. <Rule>
  60. <LineSymbolizer>
  61. <Stroke>
  62. <CssParameter name="stroke">#FFFFFF</CssParameter>
  63. <CssParameter name="stroke-width">6</CssParameter>
  64. </Stroke>
  65. </LineSymbolizer>
  66. </Rule>
  67. <sld:VendorOption name="sortBy">z</sld:VendorOption>
  68. </FeatureTypeStyle>
  69. </UserStyle>
  70. </NamedLayer>
  71. </StyledLayerDescriptor>
  72. The result will be the following:
  73. .. figure:: images/roads-no-group.png
  74. This is happening because while the roads are loaded in the right order, ``Line.1,Line.3,Line.2``,
  75. they are all painted with the tick link first, and then the code will start over, and paint
  76. them all with the thin line.
  77. In order to get both casing and z-ordering to work a new vendor option, ``sortByGroup``, needs to
  78. be added to both ``FeatureTypeStyle``, grouping them in a single z-ordering paint.
  79. .. code-block:: xml
  80. <?xml version="1.0" encoding="ISO-8859-1"?>
  81. <StyledLayerDescriptor version="1.0.0"
  82. xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
  83. xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
  84. xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  85. <!-- a named layer is the basic building block of an sld document -->
  86. <NamedLayer>
  87. <UserStyle>
  88. <FeatureTypeStyle>
  89. <Rule>
  90. <LineSymbolizer>
  91. <Stroke>
  92. <CssParameter name="stroke">#FF0000</CssParameter>
  93. <CssParameter name="stroke-width">8</CssParameter>
  94. </Stroke>
  95. </LineSymbolizer>
  96. </Rule>
  97. <sld:VendorOption name="sortBy">z</sld:VendorOption>
  98. <sld:VendorOption name="sortByGroup">roads</sld:VendorOption>
  99. </FeatureTypeStyle>
  100. <FeatureTypeStyle>
  101. <Rule>
  102. <LineSymbolizer>
  103. <Stroke>
  104. <CssParameter name="stroke">#FFFFFF</CssParameter>
  105. <CssParameter name="stroke-width">6</CssParameter>
  106. </Stroke>
  107. </LineSymbolizer>
  108. </Rule>
  109. <sld:VendorOption name="sortBy">z</sld:VendorOption>
  110. <sld:VendorOption name="sortByGroup">roads</sld:VendorOption>
  111. </FeatureTypeStyle>
  112. </UserStyle>
  113. </NamedLayer>
  114. </StyledLayerDescriptor>
  115. The result will be the following:
  116. .. figure:: images/roads-group.png
  117. When grouping is used, the code will first paint ``Line.1,Line3`` with the thick line, then track back
  118. and paint them with the thin line, then move to paint ``Line.2`` with the thick line, and finally
  119. ``Line.2`` with the thin line, achieving the desired result.
  120. z-ordering across layers
  121. ------------------------
  122. Different layers, such for example roads and rails, can have their features z-ordered together
  123. by putting all the ``FeatureTypeStyle`` in their styles in the same ``sortByGroup``, provided
  124. the following conditions are met:
  125. * The layers are side by side in the WMS request/layer group. In other words, the z-ordering
  126. allows to break the WMS specified order only if the layers are directly subsequent in the
  127. request. This can be extended to any number of layers, provided the progression of ``FeatureTypeStyle``
  128. in the same group is not broken
  129. * There is no FeatureTypeStyle in the layer style that's breaking the sequence
  130. Let's consider an example, with a rails layer having two ``FeatureTypeStyle``, one with a group,
  131. the other not:
  132. .. list-table::
  133. :widths: 50 50
  134. :header-rows: 1
  135. * - FeatureTypeStyle id
  136. - SortByGroup id
  137. * - rails1
  138. - linework
  139. * - rails2
  140. - ``none``
  141. We then have a roads layer with two ``FeatureTypeStyle``, both in the same group:
  142. .. list-table::
  143. :widths: 50 50
  144. :header-rows: 1
  145. * - FeatureTypeStyle id
  146. - SortByGroup id
  147. * - road1
  148. - linework
  149. * - road2
  150. - linework
  151. If the WMS request asks for ``&layers=roads,rails``, then the expanded ``FeatureTypeStyle`` list will be:
  152. .. list-table::
  153. :widths: 50 50
  154. :header-rows: 1
  155. * - FeatureTypeStyle id
  156. - SortByGroup id
  157. * - road1
  158. - linework
  159. * - road2
  160. - linework
  161. * - rails1
  162. - linework
  163. * - rails2
  164. - ``none``
  165. As a result, the ``road1,road2,rails1`` will form a single group, and this will result in the rails
  166. be merged with the roads when z-ordering.
  167. If instead the WMS request asks for `&layers=rails,roads``, then the expanded ``FeatureTypeStyle`` list will be:
  168. .. list-table::
  169. :widths: 50 50
  170. :header-rows: 1
  171. * - FeatureTypeStyle id
  172. - SortByGroup id
  173. * - rails1
  174. - linework
  175. * - rails2
  176. - ``none``
  177. * - road1
  178. - linework
  179. * - road2
  180. - linework
  181. The ``rails2`` feature type style breaks the sequence, as a result, the rails will not be z-ordered
  182. in the same group as the roads.