randomized.rst 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. .. _randomized:
  2. Fills with randomized symbols
  3. =============================
  4. Starting with GeoServer 2.4.2 it is possible to generate fills by randomly repeating a symbol in the polygons to be filled.
  5. Or, to be more precise, generate the usual texture fill by repeating over and over a tile, whose contents is the random repetition of a fill.
  6. The random distribution is stable, so it will be the same across calls and tiles, and it's controlled by the seed used to generate the distribution.
  7. The random fill is generated by specifying a GraphicFill with a Mark or ExternalGraphic, and then adding vendor options to control how the
  8. symbol is randomly repeated. Here is a table with options, default values, and possible values:
  9. .. list-table::
  10. :widths: 20 10 70
  11. :header-rows: 1
  12. * - Option
  13. - Default value
  14. - Description
  15. * - random
  16. - none
  17. - Activates random distribution of symbol. Possible values are **none**, **free**, **grid**.
  18. **none** disables random distribution,
  19. **free** generates a completely random distribution, **grid** will generate a regular grid of positions, and only randomizes the
  20. position of the symbol around the cell centers, providing a more even distribution in space
  21. * - random-tile-size
  22. - 256
  23. - Size the texture fill tile that will contain the randomly distributed symbols
  24. * - random-rotation
  25. - none
  26. - Activates random symbol rotation. Possible values are **none** (no rotation) or **free**
  27. * - random-symbol-count
  28. - 16
  29. - The number of symbols in the tile. The number of symbols actually painted can be lower, as the distribution will ensure no
  30. two symbols overlap with each other.
  31. * - random-seed
  32. - 0
  33. - The "seed" used to generate the random distribution. Changing this value will result in a different symbol distribution
  34. Here is an example:
  35. .. code-block:: xml
  36. <sld:PolygonSymbolizer>
  37. <sld:Fill>
  38. <sld:GraphicFill>
  39. <sld:Graphic>
  40. <sld:Mark>
  41. <sld:WellKnownName>shape://slash</sld:WellKnownName>
  42. <sld:Stroke>
  43. <sld:CssParameter name="stroke">#0000ff</sld:CssParameter>
  44. <sld:CssParameter name="stroke-linecap">round</sld:CssParameter>
  45. <sld:CssParameter name="stroke-width">4</sld:CssParameter>
  46. </sld:Stroke>
  47. </sld:Mark>
  48. <sld:Size>8</sld:Size>
  49. </sld:Graphic>
  50. </sld:GraphicFill>
  51. </sld:Fill>
  52. <sld:VendorOption name="random-seed">5</sld:VendorOption>
  53. <sld:VendorOption name="random">grid</sld:VendorOption>
  54. <sld:VendorOption name="random-tile-size">100</sld:VendorOption>
  55. <sld:VendorOption name="random-rotation">free</sld:VendorOption>
  56. <sld:VendorOption name="random-symbol-count">50</sld:VendorOption>
  57. </sld:PolygonSymbolizer>
  58. .. figure:: images/random-slash.png
  59. :align: center
  60. *Random distribution of a diagonal line*
  61. Randomized distributions can also be used for thematic mapping, for example, here is the SLD for a version of topp:states that displays the number of inhabitantìs varying the density of a random point distribution:
  62. .. code-block:: xml
  63. <?xml version="1.0" encoding="UTF-8"?>
  64. <sld:UserStyle xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml">
  65. <sld:Name>Default Styler</sld:Name>
  66. <sld:FeatureTypeStyle>
  67. <sld:Name>name</sld:Name>
  68. <sld:Rule>
  69. <ogc:Filter>
  70. <ogc:And>
  71. <ogc:Not>
  72. <ogc:PropertyIsLessThan>
  73. <ogc:PropertyName>PERSONS</ogc:PropertyName>
  74. <ogc:Literal>2000000</ogc:Literal>
  75. </ogc:PropertyIsLessThan>
  76. </ogc:Not>
  77. <ogc:Not>
  78. <ogc:PropertyIsGreaterThanOrEqualTo>
  79. <ogc:PropertyName>PERSONS</ogc:PropertyName>
  80. <ogc:Literal>4000000</ogc:Literal>
  81. </ogc:PropertyIsGreaterThanOrEqualTo>
  82. </ogc:Not>
  83. </ogc:And>
  84. </ogc:Filter>
  85. <sld:PolygonSymbolizer>
  86. <sld:Fill>
  87. <sld:GraphicFill>
  88. <sld:Graphic>
  89. <sld:Mark>
  90. <sld:WellKnownName>circle</sld:WellKnownName>
  91. <sld:Fill>
  92. <sld:CssParameter name="fill">#a9a9a9</sld:CssParameter>
  93. </sld:Fill>
  94. </sld:Mark>
  95. <sld:Size>2</sld:Size>
  96. </sld:Graphic>
  97. </sld:GraphicFill>
  98. </sld:Fill>
  99. <sld:VendorOption name="random">grid</sld:VendorOption>
  100. <sld:VendorOption name="random-tile-size">100</sld:VendorOption>
  101. <sld:VendorOption name="random-symbol-count">150</sld:VendorOption>
  102. </sld:PolygonSymbolizer>
  103. <sld:LineSymbolizer>
  104. <sld:Stroke/>
  105. </sld:LineSymbolizer>
  106. </sld:Rule>
  107. <sld:Rule>
  108. <ogc:Filter>
  109. <ogc:PropertyIsLessThan>
  110. <ogc:PropertyName>PERSONS</ogc:PropertyName>
  111. <ogc:Literal>2000000</ogc:Literal>
  112. </ogc:PropertyIsLessThan>
  113. </ogc:Filter>
  114. <sld:PolygonSymbolizer>
  115. <sld:Fill>
  116. <sld:GraphicFill>
  117. <sld:Graphic>
  118. <sld:Mark>
  119. <sld:WellKnownName>circle</sld:WellKnownName>
  120. <sld:Fill>
  121. <sld:CssParameter name="fill">#a9a9a9</sld:CssParameter>
  122. </sld:Fill>
  123. </sld:Mark>
  124. <sld:Size>2</sld:Size>
  125. </sld:Graphic>
  126. </sld:GraphicFill>
  127. </sld:Fill>
  128. <sld:VendorOption name="random">grid</sld:VendorOption>
  129. <sld:VendorOption name="random-tile-size">100</sld:VendorOption>
  130. <sld:VendorOption name="random-symbol-count">50</sld:VendorOption>
  131. </sld:PolygonSymbolizer>
  132. <sld:LineSymbolizer>
  133. <sld:Stroke/>
  134. </sld:LineSymbolizer>
  135. </sld:Rule>
  136. <sld:Rule>
  137. <ogc:Filter>
  138. <ogc:PropertyIsGreaterThanOrEqualTo>
  139. <ogc:PropertyName>PERSONS</ogc:PropertyName>
  140. <ogc:Literal>4000000</ogc:Literal>
  141. </ogc:PropertyIsGreaterThanOrEqualTo>
  142. </ogc:Filter>
  143. <sld:PolygonSymbolizer>
  144. <sld:Fill>
  145. <sld:GraphicFill>
  146. <sld:Graphic>
  147. <sld:Mark>
  148. <sld:WellKnownName>circle</sld:WellKnownName>
  149. <sld:Fill>
  150. <sld:CssParameter name="fill">#a9a9a9</sld:CssParameter>
  151. </sld:Fill>
  152. </sld:Mark>
  153. <sld:Size>2</sld:Size>
  154. </sld:Graphic>
  155. </sld:GraphicFill>
  156. </sld:Fill>
  157. <sld:VendorOption name="random">grid</sld:VendorOption>
  158. <sld:VendorOption name="random-tile-size">100</sld:VendorOption>
  159. <sld:VendorOption name="random-symbol-count">500</sld:VendorOption>
  160. </sld:PolygonSymbolizer>
  161. <sld:LineSymbolizer>
  162. <sld:Stroke/>
  163. </sld:LineSymbolizer>
  164. </sld:Rule>
  165. </sld:FeatureTypeStyle>
  166. </sld:UserStyle>
  167. .. figure:: images/states-random.png
  168. :align: center
  169. *Thematic map via point density approach*