rendering-selection.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. .. _rendering_selection:
  2. Rendering Selection
  3. ====================
  4. GeoServer provides a ``VendorOption`` to define whether a particular element ``Rule``, ``FeatureTypeStyle`` or ``Symbolizer`` should be applied to a ``getLegendGraphic`` output or to a ``getMap`` output.
  5. This allows to generate legends from the SLD that can be better looking and more expressive, without the underlying complexity of the actual rendered style. Other systems have a dedicated language to build legends instead. The advantage of using the same language is that dynamic behaviors, like rule removal based on the area being rendered, can be easily retained.
  6. The vendor option is named ``inclusion``, e.g.:
  7. * <VendorOption name="inclusion">legendOnly</VendorOption>
  8. * <VendorOption name="inclusion">mapOnly</VendorOption>
  9. Valid values are:
  10. * ``legendOnly`` the element will be skipped when applying the style to the data to render map.
  11. * ``mapOnly`` the element will be skipped when applying the style to the data to render legend.
  12. * ``normal`` will have the same effect then omitting the VendorOption: the SLD element will be used for both map and legend (same effect as not specifying the vendor option).
  13. Take as an example the following style: for each Rule two symbolizers are defined one that will be skipped when rendering the legend and one that will be skipped when rendering the map and loads the legend icon from an external svg file.
  14. .. code-block:: xml
  15. <?xml version="1.0" encoding="UTF-8"?>
  16. <StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
  17. <NamedLayer>
  18. <Name>Style example</Name>
  19. <UserStyle>
  20. <FeatureTypeStyle>
  21. <Rule>
  22. <ogc:Filter>
  23. <ogc:PropertyIsLessThan>
  24. <ogc:PropertyName>numericValue</ogc:PropertyName>
  25. <ogc:Literal>90</ogc:Literal>
  26. </ogc:PropertyIsLessThan>
  27. </ogc:Filter>
  28. <PointSymbolizer>
  29. <Graphic>
  30. <Mark>
  31. <WellKnownName>circle</WellKnownName>
  32. <Fill>
  33. <CssParameter name="fill">0xFF0000</CssParameter>
  34. </Fill>
  35. </Mark>
  36. <Size>32</Size>
  37. </Graphic>
  38. <VendorOption name="inclusion">mapOnly</VendorOption>
  39. </PointSymbolizer>
  40. <PointSymbolizer>
  41. <Graphic>
  42. <ExternalGraphic>
  43. <OnlineResource xlink:type="simple" xlink:href="my-custom-legend-icon1.svg" />
  44. <Format>image/svg+xml</Format>
  45. </ExternalGraphic>
  46. <Size>20</Size>
  47. </Graphic>
  48. <VendorOption name="inclusion">legendOnly</VendorOption>
  49. </PointSymbolizer>
  50. </Rule>
  51. <Rule>
  52. <ogc:Filter>
  53. <ogc:And>
  54. <ogc:PropertyIsGreaterThanOrEqualTo>
  55. <ogc:PropertyName>numericValue</ogc:PropertyName>
  56. <ogc:Literal>90</ogc:Literal>
  57. </ogc:PropertyIsGreaterThanOrEqualTo>
  58. <ogc:PropertyIsLessThan>
  59. <ogc:PropertyName>numericValue</ogc:PropertyName>
  60. <ogc:Literal>180</ogc:Literal>
  61. </ogc:PropertyIsLessThan>
  62. </ogc:And>
  63. </ogc:Filter>
  64. <PointSymbolizer>
  65. <Graphic>
  66. <Mark>
  67. <WellKnownName>circle</WellKnownName>
  68. <Fill>
  69. <CssParameter name="fill">#6495ED</CssParameter>
  70. </Fill>
  71. </Mark>
  72. <Size>32</Size>
  73. </Graphic>
  74. <VendorOption name="inclusion">mapOnly</VendorOption>
  75. </PointSymbolizer>
  76. <PointSymbolizer>
  77. <Graphic>
  78. <ExternalGraphic>
  79. <OnlineResource xlink:type="simple" xlink:href="my-custom-legend-icon2.svg" />
  80. <Format>image/svg+xml</Format>
  81. </ExternalGraphic>
  82. <Size>20</Size>
  83. </Graphic>
  84. <VendorOption name="inclusion">legendOnly</VendorOption>
  85. </PointSymbolizer>
  86. </Rule>
  87. </FeatureTypeStyle>
  88. </UserStyle>
  89. </NamedLayer>
  90. </StyledLayerDescriptor>
  91. The same result could have been obtained by defining each rule two time each one with a single symbolizer, and defining the vendor options at the rule level.
  92. .. code-block:: xml
  93. <?xml version="1.0" encoding="UTF-8"?>
  94. <StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
  95. <NamedLayer>
  96. <Name>Style example</Name>
  97. <UserStyle>
  98. <FeatureTypeStyle>
  99. <Rule>
  100. <ogc:Filter>
  101. <ogc:PropertyIsLessThan>
  102. <ogc:PropertyName>numericValue</ogc:PropertyName>
  103. <ogc:Literal>90</ogc:Literal>
  104. </ogc:PropertyIsLessThan>
  105. </ogc:Filter>
  106. <PointSymbolizer>
  107. <Graphic>
  108. <Mark>
  109. <WellKnownName>circle</WellKnownName>
  110. <Fill>
  111. <CssParameter name="fill">0xFF0000</CssParameter>
  112. </Fill>
  113. </Mark>
  114. <Size>32</Size>
  115. </Graphic>
  116. </PointSymbolizer>
  117. <VendorOption name="inclusion">mapOnly</VendorOption>
  118. </Rule>
  119. <Rule>
  120. <ogc:Filter>
  121. <ogc:And>
  122. <ogc:PropertyIsGreaterThanOrEqualTo>
  123. <ogc:PropertyName>numericValue</ogc:PropertyName>
  124. <ogc:Literal>90</ogc:Literal>
  125. </ogc:PropertyIsGreaterThanOrEqualTo>
  126. <ogc:PropertyIsLessThan>
  127. <ogc:PropertyName>numericValue</ogc:PropertyName>
  128. <ogc:Literal>180</ogc:Literal>
  129. </ogc:PropertyIsLessThan>
  130. </ogc:And>
  131. </ogc:Filter>
  132. <PointSymbolizer>
  133. <Graphic>
  134. <Mark>
  135. <WellKnownName>circle</WellKnownName>
  136. <Fill>
  137. <CssParameter name="fill">#6495ED</CssParameter>
  138. </Fill>
  139. </Mark>
  140. <Size>32</Size>
  141. </Graphic>
  142. <VendorOption name="inclusion">mapOnly</VendorOption>
  143. </PointSymbolizer>
  144. </Rule>
  145. <Rule>
  146. <ogc:Filter>
  147. <ogc:PropertyIsLessThan>
  148. <ogc:PropertyName>numericValue</ogc:PropertyName>
  149. <ogc:Literal>90</ogc:Literal>
  150. </ogc:PropertyIsLessThan>
  151. </ogc:Filter>
  152. <PointSymbolizer>
  153. <Graphic>
  154. <ExternalGraphic>
  155. <OnlineResource xlink:type="simple" xlink:href="my-custom-legend-icon1.svg" />
  156. <Format>image/svg+xml</Format>
  157. </ExternalGraphic>
  158. <Size>20</Size>
  159. </Graphic>
  160. <VendorOption name="inclusion">legendOnly</VendorOption>
  161. </PointSymbolizer>
  162. </Rule>
  163. <Rule>
  164. <ogc:Filter>
  165. <ogc:And>
  166. <ogc:PropertyIsGreaterThanOrEqualTo>
  167. <ogc:PropertyName>numericValue</ogc:PropertyName>
  168. <ogc:Literal>90</ogc:Literal>
  169. </ogc:PropertyIsGreaterThanOrEqualTo>
  170. <ogc:PropertyIsLessThan>
  171. <ogc:PropertyName>numericValue</ogc:PropertyName>
  172. <ogc:Literal>180</ogc:Literal>
  173. </ogc:PropertyIsLessThan>
  174. </ogc:And>
  175. </ogc:Filter>
  176. <PointSymbolizer>
  177. <Graphic>
  178. <ExternalGraphic>
  179. <OnlineResource xlink:type="simple" xlink:href="my-custom-legend-icon2.svg" />
  180. <Format>image/svg+xml</Format>
  181. </ExternalGraphic>
  182. <Size>20</Size>
  183. </Graphic>
  184. <VendorOption name="inclusion">legendOnly</VendorOption>
  185. </PointSymbolizer>
  186. </Rule>
  187. </FeatureTypeStyle>
  188. </UserStyle>
  189. </NamedLayer>
  190. </StyledLayerDescriptor>
  191. A third way to obtain the same result could be to define vendor options at the FeatureTypeStyle level.
  192. .. code-block:: xml
  193. <?xml version="1.0" encoding="UTF-8"?>
  194. <StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
  195. <NamedLayer>
  196. <Name>Style example</Name>
  197. <UserStyle>
  198. <FeatureTypeStyle>
  199. <Rule>
  200. <ogc:Filter>
  201. <ogc:PropertyIsLessThan>
  202. <ogc:PropertyName>numericValue</ogc:PropertyName>
  203. <ogc:Literal>90</ogc:Literal>
  204. </ogc:PropertyIsLessThan>
  205. </ogc:Filter>
  206. <PointSymbolizer>
  207. <Graphic>
  208. <Mark>
  209. <WellKnownName>circle</WellKnownName>
  210. <Fill>
  211. <CssParameter name="fill">0xFF0000</CssParameter>
  212. </Fill>
  213. </Mark>
  214. <Size>32</Size>
  215. </Graphic>
  216. </PointSymbolizer>
  217. </Rule>
  218. <Rule>
  219. <ogc:Filter>
  220. <ogc:And>
  221. <ogc:PropertyIsGreaterThanOrEqualTo>
  222. <ogc:PropertyName>numericValue</ogc:PropertyName>
  223. <ogc:Literal>90</ogc:Literal>
  224. </ogc:PropertyIsGreaterThanOrEqualTo>
  225. <ogc:PropertyIsLessThan>
  226. <ogc:PropertyName>numericValue</ogc:PropertyName>
  227. <ogc:Literal>180</ogc:Literal>
  228. </ogc:PropertyIsLessThan>
  229. </ogc:And>
  230. </ogc:Filter>
  231. <PointSymbolizer>
  232. <Graphic>
  233. <Mark>
  234. <WellKnownName>circle</WellKnownName>
  235. <Fill>
  236. <CssParameter name="fill">#6495ED</CssParameter>
  237. </Fill>
  238. </Mark>
  239. <Size>32</Size>
  240. </Graphic>
  241. </PointSymbolizer>
  242. </Rule>
  243. <VendorOption name="inclusion">mapOnly</VendorOption>
  244. </FeatureTypeStyle>
  245. <FeatureTypeStyle>
  246. <Rule>
  247. <ogc:Filter>
  248. <ogc:PropertyIsLessThan>
  249. <ogc:PropertyName>numericValue</ogc:PropertyName>
  250. <ogc:Literal>90</ogc:Literal>
  251. </ogc:PropertyIsLessThan>
  252. </ogc:Filter>
  253. <PointSymbolizer>
  254. <Graphic>
  255. <ExternalGraphic>
  256. <OnlineResource xlink:type="simple" xlink:href="my-custom-legend-icon1.svg" />
  257. <Format>image/svg+xml</Format>
  258. </ExternalGraphic>
  259. <Size>20</Size>
  260. </Graphic>
  261. </PointSymbolizer>
  262. </Rule>
  263. <Rule>
  264. <ogc:Filter>
  265. <ogc:And>
  266. <ogc:PropertyIsGreaterThanOrEqualTo>
  267. <ogc:PropertyName>numericValue</ogc:PropertyName>
  268. <ogc:Literal>90</ogc:Literal>
  269. </ogc:PropertyIsGreaterThanOrEqualTo>
  270. <ogc:PropertyIsLessThan>
  271. <ogc:PropertyName>numericValue</ogc:PropertyName>
  272. <ogc:Literal>180</ogc:Literal>
  273. </ogc:PropertyIsLessThan>
  274. </ogc:And>
  275. </ogc:Filter>
  276. <PointSymbolizer>
  277. <Graphic>
  278. <ExternalGraphic>
  279. <OnlineResource xlink:type="simple" xlink:href="my-custom-legend-icon2.svg" />
  280. <Format>image/svg+xml</Format>
  281. </ExternalGraphic>
  282. <Size>20</Size>
  283. </Graphic>
  284. </PointSymbolizer>
  285. </Rule>
  286. <VendorOption name="inclusion">legendOnly</VendorOption>
  287. </FeatureTypeStyle>
  288. </UserStyle>
  289. </NamedLayer>
  290. </StyledLayerDescriptor>