line.rst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. .. _ysld_reference_symbolizers_line:
  2. Line symbolizer
  3. ===============
  4. The line symbolizer is used to style linear (1-dimensional) features. It is in some ways the simplest of the symbolizers because it only contains facilities for the stroke (outline) of a feature.
  5. Syntax
  6. ------
  7. The full syntax of a line symbolizer is:
  8. ::
  9. symbolizers:
  10. - line:
  11. stroke-color: <color>
  12. stroke-width: <expression>
  13. stroke-opacity: <expression>
  14. stroke-linejoin: <expression>
  15. stroke-linecap: <expression>
  16. stroke-dasharray: <float list>
  17. stroke-dashoffset: <expression>
  18. stroke-graphic:
  19. <graphic_options>
  20. stroke-graphic-fill:
  21. <graphic_options>
  22. offset: <expression>
  23. geometry: <expression>
  24. uom: <text>
  25. x-labelObstacle: <boolean>
  26. x-composite-base: <boolean>
  27. x-composite: <text>
  28. x-inclusion: <text>
  29. where:
  30. .. include:: include/stroke.rst
  31. .. list-table::
  32. :class: non-responsive
  33. :header-rows: 1
  34. :stub-columns: 1
  35. :widths: 20 10 50 20
  36. * - Property
  37. - Required?
  38. - Description
  39. - Default value
  40. * - ``offset``
  41. - No
  42. - Value in pixels for moving the drawn line relative to the location of the feature.
  43. - ``0``
  44. .. include:: include/symbol.rst
  45. .. include:: include/misc.rst
  46. .. include:: include/composite.rst
  47. .. include:: include/inclusion.rst
  48. Examples
  49. --------
  50. Basic line with styled ends
  51. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  52. The ``linejoin`` and ``linecap`` properties can be used to style the joins and ends of any stroke.
  53. This example draws lines with partially transparent black lines with rounded ends and sharp (mitred) corners::
  54. feature-styles:
  55. - rules:
  56. - symbolizers:
  57. - line:
  58. stroke-color: '#000000'
  59. stroke-width: 8
  60. stroke-opacity: 0.5
  61. stroke-linejoin: mitre
  62. stroke-linecap: round
  63. .. figure:: img/line_basic.png
  64. Basic line with styled ends
  65. Railroad pattern
  66. ~~~~~~~~~~~~~~~~
  67. .. todo:: Fix this example
  68. Many maps use a hatched pattern to represent railroads. This can be accomplished by using two line symbolizers, one solid and one dashed. Specifically, the ``stroke-dasharray`` property is used to create a dashed line of length 1 every 24 pixels::
  69. name: railroad
  70. feature-styles:
  71. - name: name
  72. rules:
  73. - symbolizers:
  74. - line:
  75. stroke-color: '#000000'
  76. stroke-width: 1
  77. - line:
  78. stroke-color: '#000000'
  79. stroke-width: 12
  80. stroke-dasharray: '1 24'
  81. .. figure:: img/line_railroad.png
  82. Railroad pattern
  83. Specifying sizes in units
  84. ~~~~~~~~~~~~~~~~~~~~~~~~~
  85. The units for ``stroke-width``, ``size``, and other similar attributes default to pixels, meaning that graphics remain a constant size at different zoom levels. Alternately, units (feet or meters) can be specified for values, so graphics will scale as you zoom in or out. This example draws roads with a fixed width of 8 meters:
  86. .. code-block:: yaml
  87. feature-styles:
  88. - rules:
  89. - symbolizers:
  90. - line:
  91. stroke-color: '#000000'
  92. stroke-width: '8 m'
  93. .. figure:: img/line_uomsmall.png
  94. Line width measured in meters (zoomed out)
  95. .. figure:: img/line_uombig.png
  96. Line width measured in meters (zoomed in)
  97. The default unit of measure for the symbolizer is defined using ``uom``. This example uses a default of meters to supply distances for ``stroke-width`` and ``stroke-dasharray`` using meters.
  98. .. code-block:: yaml
  99. line:
  100. uom: metre
  101. stroke-color: '#000000'
  102. stroke-width: '8'
  103. stroke-dasharray: '20 3'
  104. .. figure:: img/line-uom.png
  105. Line width and spacing in meters