example.rst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. .. _sld-extensions_z_ordering_example:
  2. Z ordering single layer example
  3. -------------------------------
  4. The OpenStreetMap dataset uses extensively a ``z_order`` attribute to model the above/below relationships
  5. between elements in the real world.
  6. A :download:`small downloadable shapefile <files/z_order_roads.zip>` is provided that shows a small area with a rich set of different z-orders,
  7. where roads and rails go above and below each other.
  8. For reference, this is the dataset schema:
  9. .. list-table::
  10. :widths: 20 20 60
  11. :header-rows: 1
  12. * - Name
  13. - Type
  14. - Notes
  15. * - osm_id
  16. - numeric
  17. -
  18. * - type
  19. - string
  20. - The type of the segment, can be "mainroads", "minorroads", "railways", ...
  21. * - bridge
  22. - numeric
  23. - 0 or 1
  24. * - ref
  25. - numeric
  26. - 0 or 1
  27. * - tunnel
  28. - numeric
  29. -
  30. * - oneway
  31. - numeric
  32. - 0 or 1
  33. * - z_order
  34. - numeric
  35. -
  36. * - class
  37. - string
  38. -
  39. The dataset contains several different values for z_order, in particular:
  40. -10, -7, -5, -3, -1, 0, 3, 4, 5, 7, 9, 10, 13, 14, 15, 17, 19.
  41. Here is a sample CSS style using z-ordering, but not groups, to perform the display.
  42. Road casing is achieved by multiple FeatureTypeStyle, or ``z-index`` values in CSS:
  43. .. code-block:: css
  44. [class = 'railways' and bridge = 1] {
  45. stroke: #333333;
  46. stroke-width: 8;
  47. z-index: 0;
  48. }
  49. [class = 'minorroads'] {
  50. stroke: #a69269;
  51. stroke-width: 3;
  52. z-index: 0;
  53. }
  54. [class = 'mainroads'] {
  55. stroke: #ff0000;
  56. stroke-width: 5;
  57. z-index: 0;
  58. }
  59. [class = 'motorways'] {
  60. stroke: #990000;
  61. stroke-width: 8;
  62. z-index: 0;
  63. }
  64. [class = 'railways' and bridge = 1] {
  65. stroke: #ffffff;
  66. stroke-width: 6;
  67. z-index: 1;
  68. }
  69. [class = 'railways'] {
  70. stroke: #333333;
  71. stroke-width: 3;
  72. z-index: 2;
  73. }
  74. [class = 'railways'] {
  75. stroke: #ffffff;
  76. stroke-width: 1.5;
  77. stroke-dasharray: 5, 5;
  78. z-index: 3;
  79. }
  80. [class = 'motorways'] {
  81. stroke: #ff6666;
  82. stroke-width: 6;
  83. stroke-linecap: round;
  84. z-index: 3;
  85. }
  86. [class = 'minorroads'] {
  87. stroke: #ffffff;
  88. stroke-width: 2,5;
  89. stroke-linecap: round;
  90. z-index: 3;
  91. }
  92. [class = 'mainroads'] {
  93. stroke: #ff9999;
  94. stroke-width: 4;
  95. stroke-linecap: round;
  96. z-index: 3;
  97. }
  98. * {
  99. sort-by: "z_order";
  100. }
  101. The sorting is achieved by using the ``sort-by`` property, which translates into a ``sortBy`` VendorOption
  102. in SLD. A full equivalent SLD is :download:`available for download <files/roads_no_groups.sld>`.
  103. This is the resulting map:
  104. .. figure:: images/roads-no-group.png
  105. As one can see, there are evident issues:
  106. * Roads and rails are not showing any evident z-ordering, in fact, all rails are below roads,
  107. but their dashed white center shows a mix of below and above roads
  108. * The rails bridges (depicted with a third thicker line around the rail symbol) are consistently
  109. below some other road or rail, while they should be above.
  110. This is mostly happening because the various FeatureTypeStyle elements are not put doctor in a single
  111. group.
  112. A slight change in the CSS, grouping all levels in the same sortByGroup, solves the issues above:
  113. .. code-block:: css
  114. [class = 'railways' and bridge = 1] {
  115. stroke: #333333;
  116. stroke-width: 8;
  117. z-index: 0;
  118. }
  119. [class = 'minorroads'] {
  120. stroke: #a69269;
  121. stroke-width: 3;
  122. z-index: 0;
  123. }
  124. [class = 'mainroads'] {
  125. stroke: #ff0000;
  126. stroke-width: 5;
  127. z-index: 0;
  128. }
  129. [class = 'motorways'] {
  130. stroke: #990000;
  131. stroke-width: 8;
  132. z-index: 0;
  133. }
  134. [class = 'railways' and bridge = 1] {
  135. stroke: #ffffff;
  136. stroke-width: 6;
  137. z-index: 1;
  138. }
  139. [class = 'railways'] {
  140. stroke: #333333;
  141. stroke-width: 3;
  142. z-index: 2;
  143. }
  144. [class = 'railways'] {
  145. stroke: #ffffff;
  146. stroke-width: 1.5;
  147. stroke-dasharray: 5, 5;
  148. z-index: 3;
  149. }
  150. [class = 'motorways'] {
  151. stroke: #ff6666;
  152. stroke-width: 6;
  153. stroke-linecap: round;
  154. z-index: 3;
  155. }
  156. [class = 'minorroads'] {
  157. stroke: #ffffff;
  158. stroke-width: 2,5;
  159. stroke-linecap: round;
  160. z-index: 3;
  161. }
  162. [class = 'mainroads'] {
  163. stroke: #ff9999;
  164. stroke-width: 4;
  165. stroke-linecap: round;
  166. z-index: 3;
  167. }
  168. * {
  169. sort-by: "z_order";
  170. sort-by-group: "roadsGroup";
  171. }
  172. A full equivalent SLD is also :download:`available for download <files/roads_groups.sld>`.
  173. The result now shows proper z-ordering:
  174. .. figure:: images/roads-group.png