points.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. .. _ysld_cookbook.points:
  2. Points
  3. ======
  4. While points are seemingly the simplest type of shape, possessing only position and no other dimensions, there are many different ways that a point can be styled in YSLD.
  5. .. _ysld_cookbook_points_attributes:
  6. Example points layer
  7. --------------------
  8. The :download:`points layer <artifacts/ysld_cookbook_point.zip>` used for the examples below contains name and population information for the major cities of a fictional country. For reference, the attribute table for the points in this layer is included below.
  9. .. list-table::
  10. :widths: 30 40 30
  11. :header-rows: 1
  12. * - ``fid`` (Feature ID)
  13. - ``name`` (City name)
  14. - ``pop`` (Population)
  15. * - point.1
  16. - Borfin
  17. - 157860
  18. * - point.2
  19. - Supox City
  20. - 578231
  21. * - point.3
  22. - Ruckis
  23. - 98159
  24. * - point.4
  25. - Thisland
  26. - 34879
  27. * - point.5
  28. - Synopolis
  29. - 24567
  30. * - point.6
  31. - San Glissando
  32. - 76024
  33. * - point.7
  34. - Detrania
  35. - 205609
  36. :download:`Download the points shapefile <artifacts/ysld_cookbook_point.zip>`
  37. .. _ysld_cookbook_points_simplepoint:
  38. Simple point
  39. ------------
  40. This example specifies points be styled as red circles with a diameter of 6 pixels.
  41. .. figure:: ../../sld/cookbook/images/point_simplepoint.png
  42. Simple point
  43. Code
  44. ~~~~
  45. :download:`Download the "Simple point" YSLD <artifacts/point_simplepoint.ysld>`
  46. .. code-block:: yaml
  47. title: 'YSLD Cook Book: Simple Point'
  48. feature-styles:
  49. - name: name
  50. rules:
  51. - symbolizers:
  52. - point:
  53. size: 6
  54. symbols:
  55. - mark:
  56. shape: circle
  57. fill-color: '#FF0000'
  58. Details
  59. ~~~~~~~
  60. There is one rule in one feature style for this YSLD, which is the simplest possible situation. (All subsequent examples will contain one rule and one feature style unless otherwise specified.) Styling points is accomplished via the point symbolizer (**lines 6-11**). **Line 10** specifies the shape of the symbol to be a circle, with **line 11** determining the fill color to be red (``'#FF0000'``). **Line 7** sets the size (diameter) of the graphic to be 6 pixels.
  61. .. _ysld_cookbook_points_simplepointwithstroke:
  62. Simple point with stroke
  63. ------------------------
  64. This example adds a stroke (or border) around the :ref:`ysld_cookbook_points_simplepoint`, with the stroke colored black and given a thickness of 2 pixels.
  65. .. figure:: ../../sld/cookbook/images/point_simplepointwithstroke.png
  66. Simple point with stroke
  67. Code
  68. ~~~~
  69. :download:`Download the "Simple point with stroke" YSLD <artifacts/point_simplepointwithstroke.ysld>`
  70. .. code-block:: yaml
  71. title: 'YSLD Cook Book: Simple point with stroke'
  72. feature-styles:
  73. - name: name
  74. rules:
  75. - symbolizers:
  76. - point:
  77. size: 6
  78. symbols:
  79. - mark:
  80. shape: circle
  81. stroke-color: '#000000'
  82. stroke-width: 2
  83. fill-color: '#FF0000'
  84. Details
  85. ~~~~~~~
  86. This example is similar to the :ref:`ysld_cookbook_points_simplepoint` example. **Lines 11-12** specify the stroke, with **line 11** setting the color to black (``'#000000'``) and **line 12** setting the width to 2 pixels.
  87. Rotated square
  88. --------------
  89. This example creates a square instead of a circle, colors it green, sizes it to 12 pixels, and rotates it by 45 degrees.
  90. .. figure:: ../../sld/cookbook/images/point_rotatedsquare.png
  91. Rotated square
  92. Code
  93. ~~~~
  94. :download:`Download the "Rotated square" YSLD <artifacts/point_rotatedsquare.ysld>`
  95. .. code-block:: yaml
  96. title: 'YSLD Cook Book: Rotated square'
  97. feature-styles:
  98. - name: name
  99. rules:
  100. - symbolizers:
  101. - point:
  102. size: 12
  103. rotation: 45
  104. symbols:
  105. - mark:
  106. shape: square
  107. fill-color: '#009900'
  108. Details
  109. ~~~~~~~
  110. In this example, **line 11** sets the shape to be a square, with **line 12** setting the color to a dark green (``009900``). **Line 7** sets the size of the square to be 12 pixels, and **line 8** sets the rotation to 45 degrees.
  111. Transparent triangle
  112. --------------------
  113. This example draws a triangle, creates a black stroke identical to the :ref:`ysld_cookbook_points_simplepointwithstroke` example, and sets the fill of the triangle to 20% opacity (mostly transparent).
  114. .. figure:: ../../sld/cookbook/images/point_transparenttriangle.png
  115. Transparent triangle
  116. Code
  117. ~~~~
  118. :download:`Download the "Transparent triangle" YSLD <artifacts/point_transparenttriangle.ysld>`
  119. .. code-block:: yaml
  120. title: 'YSLD Cook Book: Transparent triangle'
  121. feature-styles:
  122. - name: name
  123. rules:
  124. - symbolizers:
  125. - point:
  126. size: 12
  127. symbols:
  128. - mark:
  129. shape: triangle
  130. stroke-color: '#000000'
  131. stroke-width: 2
  132. fill-color: '#009900'
  133. fill-opacity: 0.2
  134. Details
  135. ~~~~~~~
  136. In this example, **line 10** once again sets the shape, in this case to a triangle. **Line 13** sets the fill color to a dark green (``'#009900'``) and **line 14** sets the opacity to 0.2 (20% opaque). An opacity value of 1 means that the shape is drawn 100% opaque, while an opacity value of 0 means that the shape is drawn 0% opaque, or completely transparent. The value of 0.2 (20% opaque) means that the fill of the points partially takes on the color and style of whatever is drawn beneath it. In this example, since the background is white, the dark green looks lighter. Were the points imposed on a dark background, the resulting color would be darker. **Lines 11-12** set the stroke color to black (``'#000000'``) and width to 2 pixels. Finally, **line 7** sets the size of the point to be 12 pixels in diameter.
  137. Point as graphic
  138. ----------------
  139. This example styles each point as a graphic instead of as a simple shape.
  140. .. figure:: ../../sld/cookbook/images/point_pointasgraphic.png
  141. Point as graphic
  142. Code
  143. ~~~~
  144. :download:`Download the "Point as graphic" YSLD <artifacts/point_pointasgraphic.ysld>`
  145. .. code-block:: yaml
  146. title: 'YSLD Cook Book: Point as graphic'
  147. feature-styles:
  148. - name: name
  149. rules:
  150. - symbolizers:
  151. - point:
  152. size: 32
  153. symbols:
  154. - external:
  155. url: smileyface.png
  156. format: image/png
  157. Details
  158. ~~~~~~~
  159. This style uses a graphic instead of a simple shape to render the points. In YSLD, this is known as an ``external``, to distinguish it from the commonly-used shapes such as squares and circles that are "internal" to the renderer. **Lines 9-11** specify the details of this graphic. **Line 10** sets the path and file name of the graphic, while **line 11** indicates the format (MIME type) of the graphic (image/png). In this example, the graphic is contained in the same directory as the YSLD, so no path information is necessary in **line 10**, although a full URL could be used if desired. **Line 7** determines the size of the displayed graphic; this can be set independently of the dimensions of the graphic itself, although in this case they are the same (32 pixels). Should a graphic be rectangular, the ``size`` value will apply to the *height* of the graphic only, with the width scaled proportionally.
  160. .. figure:: ../../sld/cookbook/images/smileyface.png
  161. Graphic used for points
  162. .. _ysld_cookbook_points_pointwithdefaultlabel:
  163. Point with default label
  164. ------------------------
  165. This example shows a text label on the :ref:`ysld_cookbook_points_simplepoint` that displays the "name" attribute of the point. This is how a label will be displayed in the absence of any other customization.
  166. .. figure:: ../../sld/cookbook/images/point_pointwithdefaultlabel.png
  167. Point with default label
  168. Code
  169. ~~~~
  170. :download:`Download the "Point with default label" YSLD <artifacts/point_pointwithdefaultlabel.ysld>`
  171. .. code-block:: yaml
  172. title: 'YSLD Cook Book: Point with default label'
  173. feature-styles:
  174. - name: name
  175. rules:
  176. - symbolizers:
  177. - point:
  178. size: 6
  179. symbols:
  180. - mark:
  181. shape: circle
  182. fill-color: '#FF0000'
  183. - text:
  184. label: ${name}
  185. fill-color: '#000000'
  186. font-family: Serif
  187. font-size: 10
  188. font-style: normal
  189. font-weight: normal
  190. placement: point
  191. Details
  192. ~~~~~~~
  193. **Lines 2-11**, which contain the point symbolizer, are identical to the :ref:`ysld_cookbook_points_simplepoint` example above. The label is set in the text symbolizer on **lines 12-19**. **Line 13** determines what text to display in the label, which in this case is the value of the "name" attribute. (Refer to the attribute table in the :ref:`ysld_cookbook_points_attributes` section if necessary.) **Line 15** sets the text color. All other details about the label are set to the renderer default, which here is Times New Roman font, font color black, and font size of 10 pixels. The bottom left of the label is aligned with the center of the point.
  194. .. _ysld_cookbook_points_pointwithstyledlabel:
  195. Point with styled label
  196. -----------------------
  197. This example improves the label style from the :ref:`ysld_cookbook_points_pointwithdefaultlabel` example by centering the label above the point and providing a different font name and size.
  198. .. figure:: ../../sld/cookbook/images/point_pointwithstyledlabel.png
  199. Point with styled label
  200. Code
  201. ~~~~
  202. :download:`Download the "Point with styled label" YSLD <artifacts/point_pointwithstyledlabel.ysld>`
  203. .. code-block:: yaml
  204. title: 'YSLD Cook Book: Point with styled label'
  205. feature-styles:
  206. - name: name
  207. rules:
  208. - symbolizers:
  209. - point:
  210. size: 6
  211. symbols:
  212. - mark:
  213. shape: circle
  214. fill-color: '#FF0000'
  215. - text:
  216. label: ${name}
  217. fill-color: '#000000'
  218. font-family: Arial
  219. font-size: 12
  220. font-style: normal
  221. font-weight: bold
  222. placement: point
  223. anchor: [0.5,0.0]
  224. displacement: [0,5]
  225. Details
  226. ~~~~~~~
  227. In this example, **lines 2-11** are identical to the :ref:`ysld_cookbook_points_simplepoint` example above. The ``<TextSymbolizer>`` on **lines 12-21** contains many more details about the label styling than the previous example, :ref:`ysld_cookbook_points_pointwithdefaultlabel`. **Line 13** once again specifies the "name" attribute as text to display. **Lines 15-18** set the font information: **line 15** sets the font family to be "Arial", **line 16** sets the font size to 12, **line 17** sets the font style to "normal" (as opposed to "italic" or "oblique"), and **line 18** sets the font weight to "bold" (as opposed to "normal"). **Lines 19-21** determine the placement of the label relative to the point. The ``anchor`` (**line 20**) sets the point of intersection between the label and point, which here sets the point to be centered (0.5) horizontally axis and bottom aligned (0.0) vertically with the label. There is also ``displacement`` (**line 21**), which sets the offset of the label relative to the line, which in this case is 0 pixels horizontally and 5 pixels vertically . Finally, **line 14** sets the font color of the label to black (``'#000000'``).
  228. The result is a centered bold label placed slightly above each point.
  229. Point with rotated label
  230. ------------------------
  231. This example builds on the previous example, :ref:`ysld_cookbook_points_pointwithstyledlabel`, by rotating the label by 45 degrees, positioning the labels farther away from the points, and changing the color of the label to purple.
  232. .. figure:: ../../sld/cookbook/images/point_pointwithrotatedlabel.png
  233. Point with rotated label
  234. Code
  235. ~~~~
  236. :download:`Download the "Point with rotated label" YSLD <artifacts/point_pointwithrotatedlabel.ysld>`
  237. .. code-block:: yaml
  238. title: 'YSLD Cook Book: Point with rotated label'
  239. feature-styles:
  240. - name: name
  241. rules:
  242. - symbolizers:
  243. - point:
  244. size: 6
  245. symbols:
  246. - mark:
  247. shape: circle
  248. fill-color: '#FF0000'
  249. - text:
  250. label: ${name}
  251. fill-color: '#990099'
  252. font-family: Arial
  253. font-size: 12
  254. font-style: normal
  255. font-weight: bold
  256. placement: point
  257. anchor: [0.5,0.0]
  258. displacement: [0,25]
  259. rotation: -45
  260. Details
  261. ~~~~~~~
  262. This example is similar to the :ref:`ysld_cookbook_points_pointwithstyledlabel`, but there are three important differences. **Line 21** specifies 25 pixels of vertical displacement. **Line 22** specifies a rotation of "-45" or 45 degrees counter-clockwise. (Rotation values increase clockwise, which is why the value is negative.) Finally, **line 14** sets the font color to be a shade of purple (``'#99099'``).
  263. Note that the displacement takes effect before the rotation during rendering, so in this example, the 25 pixel vertical displacement is itself rotated 45 degrees.
  264. Attribute-based point
  265. ---------------------
  266. This example alters the size of the symbol based on the value of the population ("pop") attribute.
  267. .. figure:: ../../sld/cookbook/images/point_attributebasedpoint.png
  268. Attribute-based point
  269. Code
  270. ~~~~
  271. :download:`Download the "Attribute-based point" YSLD <artifacts/point_attribute.ysld>`
  272. .. code-block:: yaml
  273. title: 'YSLD Cook Book: Attribute-based point'
  274. feature-styles:
  275. - name: name
  276. rules:
  277. - name: SmallPop
  278. title: 1 to 50000
  279. filter: ${pop < '50000'}
  280. symbolizers:
  281. - point:
  282. size: 8
  283. symbols:
  284. - mark:
  285. shape: circle
  286. fill-color: '#0033CC'
  287. - name: MediumPop
  288. title: 50000 to 100000
  289. filter: ${pop >= '50000' AND pop < '100000'}
  290. symbolizers:
  291. - point:
  292. size: 12
  293. symbols:
  294. - mark:
  295. shape: circle
  296. fill-color: '#0033CC'
  297. - name: LargePop
  298. title: Greater than 100000
  299. filter: ${pop >= '100000'}
  300. symbolizers:
  301. - point:
  302. size: 16
  303. symbols:
  304. - mark:
  305. shape: circle
  306. fill-color: '#0033CC'
  307. Details
  308. ~~~~~~~
  309. .. note:: Refer to the :ref:`ysld_cookbook_points_attributes` to see the attributes for this data. This example has eschewed labels in order to simplify the style, but you can refer to the example :ref:`ysld_cookbook_points_pointwithstyledlabel` to see which attributes correspond to which points.
  310. This style contains three rules. Each rule varies the style based on the value of the population ("pop") attribute for each point, with smaller values yielding a smaller circle, and larger values yielding a larger circle.
  311. The three rules are designed as follows:
  312. .. list-table::
  313. :widths: 20 30 30 20
  314. :header-rows: 1
  315. * - Rule order
  316. - Rule name
  317. - Population (``pop``)
  318. - Size
  319. * - 1
  320. - SmallPop
  321. - Less than 50,000
  322. - 8
  323. * - 2
  324. - MediumPop
  325. - 50,000 to 100,000
  326. - 12
  327. * - 3
  328. - LargePop
  329. - Greater than 100,000
  330. - 16
  331. The order of the rules does not matter in this case, since each shape is only rendered by a single rule.
  332. The first rule, on **lines 5-14**, specifies the styling of those points whose population attribute is less than 50,000. **Line 7** sets this filter, denoting the attribute ("pop") to be "less than" the value of 50,000. The symbol is a circle (**line 13**), the color is dark blue (``'#0033CC'``, on **line 15**), and the size is 8 pixels in diameter (**line 18**).
  333. The second rule, on **lines 15-24**, specifies a style for points whose population attribute is greater than or equal to 50,000 and less than 100,000. The population filter is set on **line 17**. This filter specifies two criteria instead of one: a "greater than or equal to" and a "less than" filter. These criteria are joined by ``AND``, which mandates that both filters need to be true for the rule to be applicable. The size of the graphic is set to 12 pixels on **line 20**. All other styling directives are identical to the first rule.
  334. The third rule, on **lines 25-34**, specifies a style for points whose population attribute is greater than or equal to 100,000. The population filter is set on **line 27**, and the only other difference is the size of the circle, which in this rule (**line 30**) is 16 pixels.
  335. The result of this style is that cities with larger populations have larger points.
  336. Zoom-based point
  337. ----------------
  338. This example alters the style of the points at different zoom levels.
  339. .. figure:: ../../sld/cookbook/images/point_zoombasedpointlarge.png
  340. Zoom-based point: Zoomed in
  341. .. figure:: ../../sld/cookbook/images/point_zoombasedpointmedium.png
  342. Zoom-based point: Partially zoomed
  343. .. figure:: ../../sld/cookbook/images/point_zoombasedpointsmall.png
  344. Zoom-based point: Zoomed out
  345. Code
  346. ~~~~
  347. :download:`Download the "Zoom-based point" YSLD <artifacts/point_zoom.ysld>`
  348. .. code-block:: yaml
  349. title: 'YSLD Cook Book: Zoom-based point'
  350. feature-styles:
  351. - name: name
  352. rules:
  353. - name: Large
  354. scale: [min,1.6e8]
  355. symbolizers:
  356. - point:
  357. size: 12
  358. symbols:
  359. - mark:
  360. shape: circle
  361. fill-color: '#CC3300'
  362. - name: Medium
  363. scale: [1.6e8,3.2e8]
  364. symbolizers:
  365. - point:
  366. size: 8
  367. symbols:
  368. - mark:
  369. shape: circle
  370. fill-color: '#CC3300'
  371. - name: Small
  372. scale: [3.2e8,max]
  373. symbolizers:
  374. - point:
  375. size: 4
  376. symbols:
  377. - mark:
  378. shape: circle
  379. fill-color: '#CC3300'
  380. Details
  381. ~~~~~~~
  382. It is often desirable to make shapes larger at higher zoom levels when creating a natural-looking map. This example styles the points to vary in size based on the zoom level (or more accurately, scale denominator). Scale denominators refer to the scale of the map. A scale denominator of 10,000 means the map has a scale of 1:10,000 in the units of the map projection.
  383. .. note:: Determining the appropriate scale denominators (zoom levels) to use is beyond the scope of this example.
  384. This style contains three rules. The three rules are designed as follows:
  385. .. list-table::
  386. :widths: 25 25 25 25
  387. :header-rows: 1
  388. * - Rule order
  389. - Rule name
  390. - Scale denominator
  391. - Point size
  392. * - 1
  393. - Large
  394. - 1:160,000,000 or less
  395. - 12
  396. * - 2
  397. - Medium
  398. - 1:160,000,000 to 1:320,000,000
  399. - 8
  400. * - 3
  401. - Small
  402. - Greater than 1:320,000,000
  403. - 4
  404. The order of these rules does not matter since the scales denominated in each rule do not overlap.
  405. The first rule (**lines 5-13**) is for the smallest scale denominator, corresponding to when the view is "zoomed in". The scale rule is set on **line 6**, so that the rule will apply to any map with a scale denominator of 160,000,000 or less. The rule draws a circle (**line 12**), colored red (``#CC3300`` on **line 13**) with a size of 12 pixels (**line 9**).
  406. The second rule (**lines 14-22**) is the intermediate scale denominator, corresponding to when the view is "partially zoomed". The scale rules is set on **line 15**, so that the rule will apply to any map with a scale denominator between 160,000,000 and 320,000,000. (The lower bound is inclusive and the upper bound is exclusive, so a zoom level of exactly 320,000,000 would *not* apply here.) Aside from the scale, the only difference between this rule and the first is the size of the symbol, which is set to 8 pixels on **line 18**.
  407. The third rule (**lines 23-31**) is the largest scale denominator, corresponding to when the map is "zoomed out". The scale rule is set on **line 24**, so that the rule will apply to any map with a scale denominator of 320,000,000 or more. Again, the only other difference between this rule and the others is the size of the symbol, which is set to 4 pixels on **line 27**.
  408. The result of this style is that points are drawn larger as one zooms in and smaller as one zooms out.