pointsymbols.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. .. _pointsymbols:
  2. Graphic symbology in GeoServer
  3. ==============================
  4. Graphic symbology is supported via the SLD ``<Graphic>`` element.
  5. This element can appear in several contexts in SLD:
  6. * in a :ref:`sld_reference_pointsymbolizer`, to display symbols at points
  7. * in the ``<Stroke>/<GraphicStroke>`` element of a :ref:`sld_reference_linesymbolizer` and :ref:`sld_reference_polygonsymbolizer`, to display repeated symbols along lines and polygon boundaries.
  8. * in the ``<Stroke>/<GraphicFill>`` element of a :ref:`sld_reference_linesymbolizer` and :ref:`sld_reference_polygonsymbolizer`, to fill lines and polygon boundaries with tiled symbols.
  9. * in the ``<Fill>/<GraphicFill>`` element of a :ref:`sld_reference_polygonsymbolizer`, to fill polygons with tiled symbols (stippling).
  10. * in a :ref:`sld_reference_textsymbolizer` to display a graphic behind or instead of text labels (this is a GeoServer extension).
  11. ``<Graphic>`` contains either a ``<Mark>`` or an ``<ExternalGraphic>`` element.
  12. **Marks** are pure vector symbols whose geometry is predefined but with stroke and fill defined in the SLD itself.
  13. **External Graphics** are external files (such as PNG images or SVG graphics)
  14. that contain the shape and color information defining how to render a symbol.
  15. In standard SLD the ``<Mark>`` and ``<ExternalGraphic>`` names are fixed strings.
  16. GeoServer extends this by providing `dynamic symbolizers`,
  17. which allow computing symbol names on a per-feature basis by embedding CQL expressions in them.
  18. Marks
  19. -----
  20. GeoServer supports the standard SLD ``<Mark>`` symbols,
  21. a user-expandable set of extended symbols,
  22. and also TrueType Font glyphs.
  23. The symbol names are specified in the ``<WellKnownName>`` element.
  24. See also the :ref:`sld_reference_pointsymbolizer` reference for further details, as well as the examples in the :ref:`sld_cookbook_points` Cookbook section.
  25. Standard symbols
  26. ~~~~~~~~~~~~~~~~
  27. The SLD specification mandates the support of the following symbols:
  28. .. list-table::
  29. :widths: 20 80
  30. * - **Name**
  31. - **Description**
  32. * - ``square``
  33. - A square
  34. * - ``circle``
  35. - A circle
  36. * - ``triangle``
  37. - A triangle pointing up
  38. * - ``star``
  39. - five-pointed star
  40. * - ``cross``
  41. - A square cross with space around (not suitable for hatch fills)
  42. * - ``x``
  43. - A square X with space around (not suitable for hatch fills)
  44. Shape symbols
  45. ~~~~~~~~~~~~~
  46. The shape symbols set adds extra symbols that are not part of the basic set.
  47. 1. To enable ensure that the WMS Settings :guilabel:``Mark Factory Precedence`` has ``ShapeMarkFactory`` selected.
  48. 2. The shape symbols are prefixed by ``shape://``
  49. .. list-table::
  50. :widths: 20 80
  51. * - **Name**
  52. - **Description**
  53. * - ``shape://vertline``
  54. - A vertical line (suitable for hatch fills or to make railroad symbols)
  55. * - ``shape://horline``
  56. - A horizontal line (suitable for hatch fills)
  57. * - ``shape://slash``
  58. - A diagonal line leaning forwards like the "slash" keyboard symbol (suitable for diagonal hatches)
  59. * - ``shape://backslash``
  60. - Same as ``shape://slash``, but oriented in the opposite direction
  61. * - ``shape://dot``
  62. - A very small circle with space around
  63. * - ``shape://plus``
  64. - A + symbol, without space around (suitable for cross-hatch fills)
  65. * - ``shape://times``
  66. - A "X" symbol, without space around (suitable for cross-hatch fills)
  67. * - ``shape://oarrow``
  68. - An open arrow symbol (triangle without one side, suitable for placing arrows at the end of lines)
  69. * - ``shape://carrow``
  70. - A closed arrow symbol (closed triangle, suitable for placing arrows at the end of lines)
  71. Weather Symbols
  72. ~~~~~~~~~~~~~~~
  73. The weather symbols are prefixed by the ``extshape://`` protocol in the SLD:
  74. 1. To enable ensure that the WMS Settings :guilabel:``Mark Factory Precedence`` has ``MeteoMarkFactory`` selected.
  75. 2. These symbols are:
  76. .. list-table::
  77. :widths: 20 20 60
  78. * - **Name**
  79. - **Description**
  80. - **Produces**
  81. * - ``extshape://triangle``
  82. - cold front
  83. - |triangle|
  84. * - ``extshape://emicircle``
  85. - warm front
  86. - |emicircle|
  87. * - ``extshape://triangleemicircle``
  88. - stationary front
  89. - |triangleemicircle|
  90. 3. You can use ``extshape://`` for a few additional built-in shapes:
  91. .. list-table::
  92. :widths: 20 80
  93. * - ``extshape://narrow``
  94. - North Arrow
  95. * - ``extshape://sarrow``
  96. - South Arrow
  97. .. |triangle| image:: images/triangle.png
  98. .. |emicircle| image:: images/emicircle.png
  99. .. |triangleemicircle| image:: images/triangleemicircle.png
  100. More complex symbols like Wind Barbs can be created with the ``windbarbs://`` prefix.
  101. 1. To enable ensure that the WMS Settings :guilabel:``Mark Factory Precedence`` has ``WindBarbsmFactory`` selected.
  102. 2. There are some examples:
  103. .. list-table::
  104. :widths: 50 50
  105. * - **Name**
  106. - **Description**
  107. * - ``windbarbs://default(15)[kts]``
  108. - *15* wind intensity with *[kts]* unit of measure
  109. * - ``windbarbs://default(9)[m/s]?hemisphere=s``
  110. - *9* wind intensity with *[m/s]* unit of measure, in the south hemisphere
  111. Custom WKT Shapes
  112. ~~~~~~~~~~~~~~~~~
  113. Custom shapes can be defined using your own Geometry, to enable use WMS Settings :guilabel:``Mark Factory Precedence`` to select ``WKTMarkFactory``.
  114. Geometry is defined using the same well-known-text format used for CQL_FILTER.
  115. .. code-block:: xml
  116. <LineSymbolizer>
  117. <Stroke>
  118. <GraphicStroke>
  119. <Graphic>
  120. <Mark>
  121. <WellKnownName>wkt://MULTILINESTRING((-0.25 -0.25, -0.125 -0.25), (0.125 -0.25, 0.25 -0.25), (-0.25 0.25, -0.125 0.25), (0.125 0.25, 0.25 0.25))</WellKnownName>
  122. <Fill>
  123. <CssParameter name="fill">#0000ff</CssParameter>
  124. </Fill>
  125. <Stroke>
  126. <CssParameter name="stroke">#0000ff</CssParameter>
  127. <CssParameter name="stroke-width">1</CssParameter>
  128. </Stroke>
  129. </Mark>
  130. <Size>6</Size>
  131. </Graphic>
  132. </GraphicStroke>
  133. </Stroke>
  134. </LineSymbolizer>
  135. Which produces double dashed line:
  136. .. image:: images/double-dashed-line.png
  137. You can also make use of curves when defining WKT:
  138. .. code-block:: xml
  139. <LineSymbolizer>
  140. <Stroke>
  141. <GraphicStroke>
  142. <Graphic>
  143. <Mark>
  144. <WellKnownName>wkt://COMPOUNDCURVE((0 0, 0.25 0), CIRCULARSTRING(0.25 0, 0.5 0.5, 0.75 0), (0.75 0, 1 0))</WellKnownName>
  145. <Fill>
  146. <CssParameter name="fill">#0000ff</CssParameter>
  147. </Fill>
  148. <Stroke>
  149. <CssParameter name="stroke">#0000ff</CssParameter>
  150. <CssParameter name="stroke-width">1</CssParameter>
  151. </Stroke>
  152. </Mark>
  153. <Size>10</Size>
  154. </Graphic>
  155. </GraphicStroke>
  156. </Stroke>
  157. </LineSymbolizer>
  158. Producing an "emi circle" line:
  159. .. image:: images/emicircle-line.png
  160. Bulk TTF marks
  161. ~~~~~~~~~~~~~~
  162. It is possible to create a mark using glyphs from any decorative or symbolic True Type Font, such as Wingdings, WebDings, or the many symbol fonts available on the internet. To enable use WMS Settings :guilabel:``Mark Factory Precedence`` to select ``TTFMarkFactory``.
  163. The syntax for specifying this is::
  164. ttf://<fontname>#<hexcode>
  165. where ``fontname`` is the full name of a TTF font available to GeoServer, and ``hexcode`` is the hexadecimal code of the symbol.
  166. To get the hex code of a symbol, use the "Char Map" utility available in most operating systems (Windows and Linux Gnome both have one).
  167. For example, to use the "shield" symbol contained in the WebDings font, the Gnome ``charmap`` reports the symbol hex code as shown:
  168. .. figure:: images/charmap.png
  169. :align: center
  170. *Selecting a symbol hex code in the Gnome char map*
  171. The SLD to use the shield glyph as a symbol is:
  172. .. code-block:: xml
  173. :linenos:
  174. <PointSymbolizer>
  175. <Graphic>
  176. <Mark>
  177. <WellKnownName>ttf://Webdings#0x0064</WellKnownName>
  178. <Fill>
  179. <CssParameter name="fill">#AAAAAA</CssParameter>
  180. </Fill>
  181. <Stroke/>
  182. </Mark>
  183. <Size>16</Size>
  184. </Graphic>
  185. </PointSymbolizer>
  186. This results in the following map display:
  187. .. figure:: images/shields.png
  188. :align: center
  189. *Shield symbols rendered on the map*
  190. Extending the Mark subsystem using Java
  191. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  192. The Mark subsystem is user-extensible.
  193. To do this using Java code, implement the ``MarkFactory`` interface and declare the implementation in the ``META-INF/services/org.geotools.renderer.style.MarkFactory`` file.
  194. For further information see the Javadoc of the GeoTools `MarkFactory <https://github.com/geotools/geotools/blob/main/modules/library/render/src/main/java/org/geotools/renderer/style/MarkFactory.java>`_,
  195. along with the following example code:
  196. * The `factory SPI registration file <https://github.com/geotools/geotools/blob/main/modules/library/render/src/main/resources/META-INF/services/org.geotools.renderer.style.MarkFactory>`_
  197. * The `TTFMarkFactory <https://github.com/geotools/geotools/blob/main/modules/library/render/src/main/java/org/geotools/renderer/style/TTFMarkFactory.java>`_ implementation
  198. * The `ShapeMarkFactory <https://github.com/geotools/geotools/blob/main/modules/library/render/src/main/java/org/geotools/renderer/style/ShapeMarkFactory.java>`_ implementation
  199. External Graphics
  200. -----------------
  201. ``<ExternalGraphic>`` is the other way to define point symbology.
  202. Unlike marks, external graphics are used as-is, so the specification is somewhat simpler.
  203. The element content specifies a graphic ``<OnlineResource>`` using a URL or file path, and the graphic ``<Format>`` using a MIME type:
  204. .. code-block:: xml
  205. :linenos:
  206. <PointSymbolizer>
  207. <Graphic>
  208. <ExternalGraphic>
  209. <OnlineResource xlink:type="simple" xlink:href="http://mywebsite.com/pointsymbol.png" />
  210. <Format>image/png</Format>
  211. </ExternalGraphic>
  212. </Graphic>
  213. </PointSymbolizer>
  214. As with ``<Mark>``, a ``<Size>`` element can be optionally specified.
  215. When using images as graphic symbols it is better to avoid resizing, as that may blur their appearance.
  216. Use images at their native resolution by omitting the ``<Size>`` element.
  217. In contrast, for SVG graphics specifying a ``<Size>`` is recommended.
  218. SVG files are a vector-based format describing both shape and color,
  219. so they scale cleanly to any size.
  220. If the path of the symbol file is relative,
  221. the file is looked for under ``$GEOSERVER_DATA_DIR/styles``.
  222. For example:
  223. .. code-block:: xml
  224. :linenos:
  225. <PointSymbolizer>
  226. <Graphic>
  227. <ExternalGraphic>
  228. <OnlineResource xlink:type="simple" xlink:href="burg02.svg" />
  229. <Format>image/svg+xml</Format>
  230. </ExternalGraphic>
  231. <Size>20</Size>
  232. </Graphic>
  233. </PointSymbolizer>
  234. In this example an SVG graphic is being used, so the size is specified explicitly.
  235. SVG Parameters
  236. ~~~~~~~~~~~~~~
  237. GeoServer can handle SVG images in which parts of the SVG-attributes are
  238. named parameters, as outlined the `SVG Parameters 1.0 specification <https://www.w3.org/TR/SVGParamPrimer/>`__. This capability is also supported by `QGIS <http://qgis.org>`__.
  239. SVG Parameters are represented in a file like: `poi_peak.svg <https://github.com/qgis/QGIS/blob/master/images/svg/symbol/poi_peak.svg>`__ as:
  240. .. code-block:: xml
  241. <svg enable-background="new 0 0 580 580" height="580" viewBox="0 0 580 580" width="580" xmlns="http://www.w3.org/2000/svg">
  242. <path d="m290.565 67.281l-255.498 442.534-1.087 1.885 511.229.393 2.18.002z" fill="param(fill)"
  243. fill-opacity="param(fill-opacity)" stroke="param(outline)" stroke-opacity="param(outline-opacity)" stroke-width="param(outline-width)"/>
  244. </svg>
  245. The 'param'-constructs mean that you can define the parameters: `fill`, `fill-opacity`, `outline`, `outline-opacity` and `outline-width` as part of an SVG URL reference, where a reference to this image with red fill would be: ``poi_peak.svg?fill=#FF0000``.
  246. Note: When editng :file:`SVG` files (e.g. in Inkscape) save using 'simple svg' format.
  247. Default behaviour:
  248. * OnlineResource `href` URI without any parameters.
  249. .. code-block:: xml
  250. <se:OnlineResource xlink:href="poi_peak.svg" xlink:type="simple"/>
  251. * Displays :file:`poi_peak.svg` with the default black `fill`.
  252. .. figure:: images/peak_black.png
  253. SVG image with default black fill
  254. Using `#ff000` red parameter:
  255. * OnlineResource `href` URI with parameter:
  256. .. code-block:: xml
  257. <se:OnlineResource xlink:href="poi_peak.svg?fill=#ff0000" xlink:type="simple"/>
  258. * Displays :file:`poi_peak.svg` with supplied red `fill`.
  259. .. figure:: images/peak_redfill.png
  260. SVG image with fill provided by parameter
  261. To define several parameters, the query-parameters should be url-encoded.
  262. * A green peak with 25% opacity: `?fill=#00ff00&opacity=0.25`, requires encoding both the '#' ( ``%23`` ) and the '&' ( ``&amp;`` ) signs:
  263. .. code-block:: xml
  264. <se:OnlineResource xlink:href="poi_peak.svg?fill=%2300ff00&amp;opacity=0.25" xlink:type="simple"/>
  265. * Displayed with white fill, red outlined peaks:
  266. .. figure:: images/peak_green25opacity.png
  267. SVG image with fill and outline provided by parameters
  268. Parameters names are defined by the SVG file:
  269. * The parameter 'stroke' above is called 'outline' in the original :file:`svg` file:
  270. .. code-block:: xml
  271. stroke="param(outline)"
  272. * OnlineResource `href` URI referencing parameters `fill`, `outline` and `outline-width`:
  273. .. code-block:: xml
  274. <se:OnlineResource xlink:href="poi_peak.svg?fill=%23ffffff&amp;outline=%23ff0000&amp;outline-width=5" xlink:type="simple"/>
  275. * Displayed as:
  276. .. figure:: images/peak_whitered.png
  277. SVG image with fill
  278. The use of SVG parameters can be combinded with dynamic symbolizers (covered below) to supply SVG parameter values based on feature attribute data and expressions.
  279. * OnlineResource `href` URI referencing SVG Parameter with dynamic CQL expression:
  280. .. code-block:: xml
  281. <se:OnlineResource xlink:href="poi_peak.svg?fill=${COLOR}" xlink:type="simple"/>
  282. * Display depends on the feature attribute `COLOR`.
  283. Bulk WKT Shapes
  284. ~~~~~~~~~~~~~~~
  285. It is possible to create a symbol set of your own custom marks using a property file.
  286. Here is an :file:`example.properties`:
  287. .. code-block:: text
  288. zig=LINESTRING(0.0 0.25, 0.25 0.25, 0.5 0.75, 0.75 0.25, 1.00 0.25)
  289. block=POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))
  290. The SLD to use the symbols defined in :file:`example.properties` is:
  291. .. code-block:: xml
  292. :linenos:
  293. <PointSymbolizer>
  294. <Graphic>
  295. <ExternalGraphic>
  296. <OnlineResource
  297. xlink:type="simple"
  298. xlink:href="example.properties#zig" />
  299. <Format>wkt</Format>
  300. </ExternalGraphic>
  301. <Size>20</Size>
  302. </Graphic>
  303. </PointSymbolizer>
  304. Symbol Positioning
  305. ~~~~~~~~~~~~~~~~~~
  306. Graphic symbols are rendered so that the center of the graphic extent
  307. lies on the placement point (or points, in the case of repeated or tiled graphics).
  308. If it is desired to have a graphic offset from a point
  309. (such as a symbol which acts
  310. as a pointer) it is necessary to offset
  311. the visible portion of the graphic within the overall extent.
  312. For images this can be accomplished by extending the image with transparent pixels.
  313. For SVG graphics this can be done by surrounding the shape with
  314. an invisible rectangle with the desired relative position.
  315. Dynamic symbolizers
  316. -------------------
  317. In standard SLD, the ``Mark/WellKnowName`` element and the ``ExternalGraphic/OnlineResource/@xlink:href`` attribute are fixed strings.
  318. This means they have the same value for all rendered features.
  319. When the symbols to be displayed vary depending on feature attributes this restriction leads to very verbose styling, as a separate ``Rule`` and ``Symbolizer`` must be used for each different symbol.
  320. GeoServer improves this by allowing :ref:`CQL expressions<filter_ecql_reference>` to be embedded inside the content of both ``WellKnownName`` and ``OnlineResource/@xlink:href``.
  321. When the names of the symbols can be derived from the feature attribute values, this provides much more compact styling.
  322. CQL expressions can be embedded in a ``<WellKnownName>`` content string or an ``<OnlineResource>`` ``xlink:href`` attribute by using the syntax::
  323. ${<cql expression>}
  324. .. note::
  325. Currently ``xlink:href`` strings must be valid URLs *before* expression expansion is performed.
  326. This means that the URL cannot be completely provided by an expression.
  327. The ``xlink:href`` string must explicitly include at least the prefix ``http://``
  328. The simplest form of expression is a single attribute name, such as ``${STATE_ABBR}``.
  329. For example, suppose we want to display the flags of the US states using symbols whose file names match the state name.
  330. The following style specifies the flag symbols using a single rule:
  331. .. code-block:: xml
  332. :linenos:
  333. <ExternalGraphic>
  334. <OnlineResource xlink:type="simple"
  335. xlink:href="http://mysite.com/tn_${STATE_ABBR}.jpg"/>
  336. <Format>image/jpeg</Format>
  337. </ExternalGraphic>
  338. If manipulation of the attribute values is required a full CQL expression can be specified.
  339. For example, if the values in the ``STATE_ABBR`` attribute are uppercase but the URL requires a lowercase name, the CQL ``strToLowerCase`` function can be used:
  340. .. code-block:: xml
  341. :linenos:
  342. <ExternalGraphic>
  343. <OnlineResource xlink:type="simple"
  344. xlink:href="http://mysite.com/tn_${strToLowerCase(STATE_ABBR)}.jpg" />
  345. <Format>image/jpeg</Format>
  346. </ExternalGraphic>