rules.rst 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. .. _sld_reference_rules:
  2. Rules
  3. =====
  4. Styling **rules** define the portrayal of features.
  5. A rule combines a :ref:`filter <sld_reference_filters>` with any number of symbolizers.
  6. Features for which the filter condition evaluates as true
  7. are rendered using the symbolizers in the rule.
  8. Syntax
  9. ------
  10. The ``<Rule>`` element contains the following elements:
  11. .. list-table::
  12. :widths: 25 15 60
  13. * - **Tag**
  14. - **Required?**
  15. - **Description**
  16. * - ``<Name>``
  17. - No
  18. - Specifies a name for the rule.
  19. * - ``<Title>``
  20. - No
  21. - Specifies a title for the rule.
  22. The title is used in display lists and legends.
  23. * - ``<Abstract>``
  24. - No
  25. - Specifies an abstract describing the rule.
  26. * - ``<Filter>``
  27. - No
  28. - Specifies a filter controlling when the rule is applied.
  29. See :ref:`sld_reference_filters`
  30. * - ``<MinScaleDenominator>``
  31. - No
  32. - Specifies the minimum scale denominator (inclusive) for the scale range
  33. in which this rule applies.
  34. If present, the rule applies at the given scale and all smaller scales.
  35. * - ``<MaxScaleDenominator>``
  36. - No
  37. - Specifies the maximum scale denominator (exclusive) for the scale range
  38. in which this rule applies.
  39. If present, the rule applies at scales larger than the given scale.
  40. * - ``<PointSymbolizer>``
  41. - 0..N
  42. - Specifies styling as points.
  43. See :ref:`sld_reference_pointsymbolizer`
  44. * - ``<LineSymbolizer>``
  45. - 0..N
  46. - Specifies styling as lines.
  47. See :ref:`sld_reference_linesymbolizer`
  48. * - ``<PolygonSymbolizer>``
  49. - 0..N
  50. - Specifies styling as polygons.
  51. See :ref:`sld_reference_polygonsymbolizer`
  52. * - ``<TextSymbolizer>``
  53. - 0..N
  54. - Specifies styling for text labels.
  55. See :ref:`sld_reference_textsymbolizer`
  56. * - ``<RasterSymbolizer>``
  57. - 0..N
  58. - Specifies styling for raster data.
  59. See :ref:`sld_reference_rastersymbolizer`
  60. Scale Selection
  61. ---------------
  62. Rules support **scale selection**
  63. to allow specifying the scale range in which a rule may be applied
  64. (assuming the filter condition is satisfied as well, if present).
  65. Scale selection allows for varying portrayal of features at different map scales.
  66. In particular, at smaller scales it is common to use simpler styling for features,
  67. or even prevent the display of some features altogether.
  68. Scale ranges are specified by using **scale denominators**.
  69. These values correspond directly to the ground distance covered by a map,
  70. but are inversely related to the common "large" and "small" terminology for map scale.
  71. In other words:
  72. * **large scale** maps cover *less* area and have a *smaller* scale denominator
  73. * **small scale** maps cover *more* area and have a *larger* scale denominator
  74. Two optional elements specify the scale range for a rule:
  75. .. list-table::
  76. :widths: 30 15 55
  77. * - **Tag**
  78. - **Required?**
  79. - **Description**
  80. * - ``<MinScaleDenominator>``
  81. - No
  82. - Specifies the minimum scale denominator (inclusive) for the scale range
  83. in which this rule applies.
  84. If present, the rule applies at the given scale and all smaller scales.
  85. * - ``<MaxScaleDenominator>``
  86. - No
  87. - Specifies the maximum scale denominator (exclusive) for the scale range
  88. in which this rule applies.
  89. If present, the rule applies at scales larger than the given scale.
  90. .. note::
  91. The current scale can also be obtained via the ``wms_scale_denominator``
  92. :ref:`SLD environment variable <sld_variable_substitution>`.
  93. This allows including scale dependency in :ref:`sld_filter_expression`.
  94. The following example shows the use of scale selection in a pair of rules.
  95. The rules specify that:
  96. * at scales **above** 1:20,000
  97. (*larger* scales, with scale denominators *smaller* than 20,000)
  98. features are symbolized with 10-pixel red squares,
  99. * at scales **at or below** 1:20,000
  100. (*smaller* scales, with scale denominators *larger* than 20,000)
  101. features are symbolized with 4-pixel blue triangles.
  102. .. code-block:: xml
  103. <Rule>
  104. <MaxScaleDenominator>20000</MaxScaleDenominator>
  105. <PointSymbolizer>
  106. <Graphic>
  107. <Mark>
  108. <WellKnownName>square</WellKnownName>
  109. <Fill><CssParameter name="fill">#FF0000</CssParameter>
  110. </Mark>
  111. <Size>10</Size>
  112. </Graphic>
  113. </PointSymbolizer>
  114. </Rule>
  115. <Rule>
  116. <MinScaleDenominator>20000</MinScaleDenominator>
  117. <PointSymbolizer>
  118. <Graphic>
  119. <Mark>
  120. <WellKnownName>triangle</WellKnownName>
  121. <Fill><CssParameter name="fill">#0000FF</CssParameter>
  122. </Mark>
  123. <Size>4</Size>
  124. </Graphic>
  125. </PointSymbolizer>
  126. </Rule>
  127. Evaluation Order
  128. ----------------
  129. Within an SLD document each ``<FeatureTypeStyle>`` can contain many rules.
  130. Multiple-rule SLDs are the basis for thematic styling.
  131. In GeoServer each ``<FeatureTypeStyle>``
  132. is evaluated once for each feature processed.
  133. The rules within it are evaluated in the order they occur.
  134. A rule is applied when its filter condition (if any) is true for a feature
  135. and the rule is enabled at the current map scale.
  136. The rule is applied by rendering the feature using each symbolizer
  137. within the rule, in the order in which they occur.
  138. The rendering is performed into the image buffer
  139. for the parent ``<FeatureTypeStyle>``.
  140. Thus symbolizers earlier in a ``FeatureTypeStyle`` and ``Rule`` are rendered
  141. *before* symbolizers occurring later in the document
  142. (this is the "Painter's Model" method of rendering).
  143. Examples
  144. --------
  145. The following rule applies only to features which have a ``POPULATION`` attribute greater than 100,000,
  146. and symbolizes the features as red points.
  147. .. code-block:: xml
  148. <Rule>
  149. <ogc:Filter>
  150. <ogc:PropertyIsGreaterThan>
  151. <ogc:PropertyName>POPULATION</ogc:PropertyName>
  152. <ogc:Literal>100000</ogc:Literal>
  153. </ogc:PropertyIsGreaterThan>
  154. </ogc:Filter>
  155. <PointSymbolizer>
  156. <Graphic>
  157. <Mark>
  158. <Fill><CssParameter name="fill">#FF0000</CssParameter>
  159. </Mark>
  160. </Graphic>
  161. </PointSymbolizer>
  162. </Rule>
  163. An additional rule can be added which applies to features whose ``POPULATION`` attribute is less than 100,000,
  164. and symbolizes them as green points.
  165. .. code-block:: xml
  166. <Rule>
  167. <ogc:Filter>
  168. <ogc:PropertyIsLessThan>
  169. <ogc:PropertyName>POPULATION</ogc:PropertyName>
  170. <ogc:Literal>100000</ogc:Literal>
  171. </ogc:PropertyIsLessThan>
  172. </ogc:Filter>
  173. <PointSymbolizer>
  174. <Graphic>
  175. <Mark>
  176. <Fill><CssParameter name="fill">#0000FF</CssParameter>
  177. </Mark>
  178. </Graphic>
  179. </PointSymbolizer>
  180. </Rule>