rules.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. .. _ysld_reference_rules:
  2. Rules
  3. =====
  4. A rule is a **collection of styling directives**, primarily consisting of :ref:`symbolizers <ysld_reference_symbolizers>` combined with optional conditional statements.
  5. * **If a conditional statement exists** in a rule, then the styling directives will only be carried out **if the conditional returns true**. Otherwise, the rule will be skipped.
  6. * **If no conditional statement exists** in a rule, then the styling directive will **always be carried out**.
  7. .. todo:: FIGURE NEEDED
  8. The types of conditional statements available to rules are:
  9. * :ref:`Filters <ysld_reference_filters>` for attribute-based rendering
  10. * :ref:`Scale <ysld_reference_scalezoom>` for scale-based rendering
  11. Rules are contained within :ref:`feature styles <ysld_reference_featurestyles>`. There is no limit on the number of rules that can be created, and there is no restriction that all rules must be mutually exclusive (as in, some rules may apply to the same features).
  12. Syntax
  13. ------
  14. The following is the basic syntax of a rule. Note that the contents of the block are not all expanded; see the other sections for the relevant syntax.
  15. ::
  16. rules:
  17. - name: <text>
  18. title: <text>
  19. filter: <filter>
  20. else: <boolean>
  21. scale: [<min>,<max>]
  22. symbolizers:
  23. - ...
  24. x-inclusion: <text>
  25. where:
  26. .. list-table::
  27. :class: non-responsive
  28. :header-rows: 1
  29. :stub-columns: 1
  30. :widths: 20 10 50 20
  31. * - Property
  32. - Required?
  33. - Description
  34. - Default value
  35. * - ``name``
  36. - No
  37. - Internal reference to the feature style. It is recommended that the value be **lower case** and contain **no spaces**.
  38. - Blank
  39. * - ``title``
  40. - No
  41. - Human-readable description of what the rule accomplishes.
  42. - Blank
  43. * - ``filter``
  44. - No
  45. - :ref:`Filter <ysld_reference_filters>` expression which will need to evaluate to be true for the symbolizer(s) to be applied. Cannot be used with ``else``.
  46. - Blank (meaning that the rule will apply to all features)
  47. * - ``else``
  48. - No
  49. - Specifies whether the rule will be an "else" rule. An else rule applies when, after scale and filters are applied, no other rule applies. To make an else rule, set this option to ``true``. Cannot be used with ``filter``.
  50. - ``false``
  51. * - ``scale``
  52. - No
  53. - :ref:`Scale <ysld_reference_scalezoom>` boundaries showing at what scales (related to zoom levels) the rule will be applied.
  54. - Visible at all scales
  55. * - ``symbolizers``
  56. - Yes
  57. - Block containing one or more :ref:`symbolizers <ysld_reference_symbolizers>`. These contain the actual visualization directives. If the filter returns true and the view is within the scale boundaries, these symbolizers will be drawn.
  58. - N/A
  59. * - ``x-inclusion``
  60. - No
  61. - Define if rule should be included in style for ``legendOnly`` or ``mapOnly`` (see :ref:`rendering_selection`)
  62. - ``normal``
  63. Short syntax
  64. ------------
  65. When a style has a single rule inside a single feature style, it is possible to omit the syntax for both and start at the first parameter inside.
  66. So the following complete styles are equivalent::
  67. feature-styles:
  68. - rules:
  69. - symbolizers:
  70. - line:
  71. stroke-color: '#000000'
  72. stroke-width: 2
  73. ::
  74. line:
  75. stroke-color: '#000000'
  76. stroke-width: 2
  77. Examples
  78. --------
  79. Else filter
  80. ~~~~~~~~~~~
  81. Using ``filter`` and ``else`` together::
  82. rules:
  83. - name: small
  84. title: Small features
  85. filter: ${type = 'small'}
  86. symbolizers:
  87. - ...
  88. - name: large
  89. title: Large features
  90. filter: ${type = 'large'}
  91. symbolizers:
  92. - ...
  93. - name: else
  94. title: All other features
  95. else: true
  96. symbolizers:
  97. - ...
  98. In the above situation:
  99. * If a feature has a value of "small" in its ``type`` attribute, it will be styled with the "small" rule.
  100. * If a feature has a value of "large" in its ``type`` attribute, it will be styled with the "large" rule.
  101. * If a feature has a value of "medium" (or anything else) in its ``type`` attribute, it will be styled with the "else" rule.
  102. Else with scale
  103. ~~~~~~~~~~~~~~~
  104. Using ``filter``, ``else``, and ``scale`` together::
  105. rules:
  106. - name: small_zoomin
  107. scale: [min,10000]
  108. title: Small features when zoomed in
  109. filter: ${type = 'small'}
  110. symbolizers:
  111. - ...
  112. - name: small_zoomout
  113. scale: [10000,max]
  114. title: Small features when zoomed out
  115. filter: ${type = 'small'}
  116. symbolizers:
  117. - ...
  118. - name: else_zoomin
  119. scale: [min,10000]
  120. title: All other features when zoomed in
  121. else: true
  122. symbolizers:
  123. - ...
  124. - name: else_zoomout
  125. scale: [10000,max]
  126. title: All other features when zoomed out
  127. else: true
  128. symbolizers:
  129. - ...
  130. In the above situation:
  131. * If a feature has a value of "small" in its ``type`` attribute, and the map is a scale level less than 10,000, it will be styled with the "small_zoomin" rule.
  132. * If a feature has a value of anything else other than "small" in its ``type`` attribute, and the map is a scale level less than 10,000, it will be styled with the "else_zoomin" rule.
  133. * If a feature has a value of "small" in its ``type`` attribute, and the map is a scale level greater than 10,000, it will be styled with the "small_zoomout" rule.
  134. * If a feature has a value of anything else other than "small" in its ``type`` attribute, and the map is a scale level greater than 10,000, it will be styled with the "else_zoomout" rule.