linesymbolizer.rst 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. .. _sld_reference_linesymbolizer:
  2. LineSymbolizer
  3. ==============
  4. A **LineSymbolizer** styles features as **lines**.
  5. Lines are one-dimensional geometries that have both position and length.
  6. Each line is comprised of one or more **line segments**,
  7. and has either two **ends** or none (if it is closed).
  8. Syntax
  9. ------
  10. A ``<LineSymbolizer>`` contains an optional ``<Geometry>`` element,
  11. and a required ``<Stroke>`` element specifying the line symbology.
  12. .. list-table::
  13. :widths: 20 20 60
  14. * - **Tag**
  15. - **Required?**
  16. - **Description**
  17. * - ``<Geometry>``
  18. - No
  19. - Specifies the geometry to be rendered.
  20. * - ``<Stroke>``
  21. - Yes
  22. - Specifies the styling for the line.
  23. * - ``<PerpendicularOffset>``
  24. - No
  25. - Specifies the perpendicular offset for the current line
  26. Geometry
  27. ^^^^^^^^
  28. The ``<Geometry>`` element is optional.
  29. If present, it specifies the featuretype property from which to obtain the geometry to style
  30. using the ``PropertyName`` element.
  31. See also :ref:`geometry_transformations` for GeoServer extensions for specifying geometry.
  32. Any kind of geometry may be styled with a ``<LineSymbolizer>``.
  33. Point geometries are treated as lines of zero length, with a horizontal orientation.
  34. For polygonal geometries the boundary (or boundaries) are used as the lines,
  35. each line being a closed ring with no ends.
  36. .. _sld_reference_stroke:
  37. Stroke
  38. ^^^^^^
  39. The ``<Stroke>`` element specifies the styling of a line.
  40. There are three elements that can be included inside the ``<Stroke>`` element.
  41. .. list-table::
  42. :widths: 20 20 60
  43. * - **Tag**
  44. - **Required?**
  45. - **Description**
  46. * - ``<GraphicFill>``
  47. - No
  48. - Renders the pixels of the line with a repeated pattern.
  49. * - ``<GraphicStroke>``
  50. - No
  51. - Renders the line with a repeated linear graphic.
  52. * - ``<CssParameter>``
  53. - 0..N
  54. - Determines the stroke styling parameters.
  55. GraphicFill
  56. ^^^^^^^^^^^
  57. The ``<GraphicFill>`` element specifies that the pixels of the line are to be filled
  58. with a repeating graphic image or symbol.
  59. The graphic is specified by a ``<Graphic>`` sub-element,
  60. which is described in the ``PointSymbolizer`` :ref:`sld_reference_graphic` section.
  61. .. _sld_reference_linesymbolizer_graphicstroke:
  62. GraphicStroke
  63. ^^^^^^^^^^^^^
  64. The ``<GraphicStroke>`` element specifies the line is to be drawn
  65. using a repeated graphic image or symbol following the line.
  66. The graphic is specified by a ``<Graphic>`` sub-element,
  67. which is described in the ``PointSymbolizer`` :ref:`sld_reference_graphic` section.
  68. The spacing of the graphic symbol can be specified using the ``<Size>`` element in the ``<Graphic>`` element,
  69. or the ``<CSSParameter name="stroke-dasharray">`` in the ``Stroke`` element.
  70. .. _sld_reference_linesymbolizer_css:
  71. CssParameter
  72. ^^^^^^^^^^^^
  73. The ``<CssParameter>`` elements describe the basic styling of the line.
  74. Any number of ``<CssParameter>`` elements can be specified.
  75. The ``name`` **attribute** indicates what aspect of styling an element specifies,
  76. using the standard CSS/SVG styling model.
  77. The **content** of the element supplies the
  78. value of the styling parameter.
  79. The value may contain :ref:`expressions <sld_reference_parameter_expressions>`.
  80. The following parameters are supported:
  81. .. list-table::
  82. :widths: 30 15 55
  83. * - **Parameter**
  84. - **Required?**
  85. - **Description**
  86. * - ``name="stroke"``
  87. - No
  88. - Specifies the solid color given to the line, in the form ``#RRGGBB``. Default is black (``#000000``).
  89. * - ``name="stroke-width"``
  90. - No
  91. - Specifies the width of the line in pixels. Default is ``1``.
  92. * - ``name="stroke-opacity"``
  93. - No
  94. - Specifies the opacity (transparency) of the line. The value is a number are between ``0`` (completely transparent) and ``1`` (completely opaque). Default is ``1``.
  95. * - ``name="stroke-linejoin"``
  96. - No
  97. - Determines how lines are rendered at intersections of line segments. Possible values are ``mitre`` (sharp corner), ``round`` (rounded corner), and ``bevel`` (diagonal corner). Default is ``mitre``.
  98. * - ``name="stroke-linecap"``
  99. - No
  100. - Determines how lines are rendered at their ends. Possible values are ``butt`` (sharp square edge), ``round`` (rounded edge), and ``square`` (slightly elongated square edge). Default is ``butt``.
  101. * - ``name="stroke-dasharray"``
  102. - No
  103. - Encodes a dash pattern as a series of numbers separated by spaces. Odd-indexed numbers (first, third, etc) determine the length in pxiels to draw the line, and even-indexed numbers (second, fourth, etc) determine the length in pixels to blank out the line. Default is an unbroken line. `Starting from version 2.1` dash arrays can be combined with graphic strokes to generate complex line styles with alternating symbols or a mix of lines and symbols.
  104. * - ``name="stroke-dashoffset"``
  105. - No
  106. - Specifies the distance in pixels into the ``dasharray`` pattern at which to start drawing. Default is ``0``.
  107. PerpendicularOffset
  108. ^^^^^^^^^^^^^^^^^^^
  109. The ``<PerpendicularOffset>`` element is optional. It is native to the SE 1.1 specification, but supported also
  110. in SLD 1.0 as a vendor extension.
  111. If present, it makes the renderer draw a line parallel to the original one, at the given distance.
  112. When applied on lines, positive values generate a parallel line on the left hand side, negative values
  113. on the right hand side.
  114. When applied on polygons instead, positive is interpreted as outwards, negative as inwards.
  115. As most properties, ``<PerpendicularOffset>`` accepts expressions.
  116. Care should be taken when using it, as it might become a performance bottleneck. When offsetting lines
  117. a fast offset algorithm is used, which works well at small distances, but can generate visible artifacts
  118. at higher values. When working against polygons the fast offset line algorithm is used up to 3 pixels
  119. away from the original geometry, after that a full buffer algorithm is used instead, which always provides
  120. correct results, but is significantly more expensive.
  121. Basic Example
  122. -------------
  123. The following symbolizer is taken from the :ref:`sld_cookbook_lines` section in the :ref:`sld_cookbook`.
  124. .. code-block:: xml
  125. :linenos:
  126. <LineSymbolizer>
  127. <Stroke>
  128. <CssParameter name="stroke">#0000FF</CssParameter>
  129. <CssParameter name="stroke-width">3</CssParameter>
  130. <CssParameter name="stroke-dasharray">5 2</CssParameter>
  131. </Stroke>
  132. </LineSymbolizer>
  133. The symbolizer styles a feature as a dashed blue line of width 3 pixels.
  134. .. figure:: img/line_dashedline.png
  135. :align: center
  136. *Dashed blue line*
  137. Offsetting lines
  138. ----------------
  139. The following style excerpt generates a solid line, and then a dashed blue line 3 pixels
  140. on the left of it.
  141. .. code-block:: xml
  142. :linenos:
  143. <LineSymbolizer>
  144. <Stroke>
  145. <CssParameter name="stroke">#000000</CssParameter>
  146. <CssParameter name="stroke-width">2</CssParameter>
  147. </Stroke>
  148. </LineSymbolizer>
  149. <LineSymbolizer>
  150. <Stroke>
  151. <CssParameter name="stroke">#0000FF</CssParameter>
  152. <CssParameter name="stroke-width">3</CssParameter>
  153. <CssParameter name="stroke-dasharray">5 2</CssParameter>
  154. </Stroke>
  155. <PerpendicularOffset>3</PerpendicularOffset>
  156. </LineSymbolizer>
  157. .. figure:: img/line_dashoffset.png
  158. :align: center
  159. *Left offset dashed line*
  160. Offsetting polygons
  161. -------------------
  162. The following style excerpt builds a inward offset line for polygons.
  163. .. code-block:: xml
  164. :linenos:
  165. <PolygonSymbolizer>
  166. <Stroke>
  167. <CssParameter name="stroke">#000000</CssParameter>
  168. <CssParameter name="stroke-width">2</CssParameter>
  169. </Stroke>
  170. </PolygonSymbolizer>
  171. <LineSymbolizer>
  172. <Stroke>
  173. <CssParameter name="stroke">#AAAAAA</CssParameter>
  174. <CssParameter name="stroke-width">3</CssParameter>
  175. </Stroke>
  176. <PerpendicularOffset>-2</PerpendicularOffset>
  177. </LineSymbolizer>
  178. .. figure:: img/polygon_offset.png
  179. :align: center
  180. *Inwards offset line*