style.lua 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. -- For documentation of Lua tag transformations see
  2. -- https://osm2pgsql.org/doc/manual.html#the-pgsql-output
  3. -- Objects with any of the following keys will be treated as polygon
  4. polygon_keys = {
  5. 'aeroway',
  6. 'amenity',
  7. 'building',
  8. 'harbour',
  9. 'historic',
  10. 'landuse',
  11. 'leisure',
  12. 'man_made',
  13. 'military',
  14. 'natural',
  15. 'office',
  16. 'place',
  17. 'power',
  18. 'public_transport',
  19. 'shop',
  20. 'sport',
  21. 'tourism',
  22. 'water',
  23. 'waterway',
  24. 'wetland'
  25. }
  26. -- Objects without any of the following keys will be deleted
  27. generic_keys = {
  28. 'access',
  29. 'addr:housename',
  30. 'addr:housenumber',
  31. 'addr:interpolation',
  32. 'admin_level',
  33. 'aerialway',
  34. 'aeroway',
  35. 'amenity',
  36. 'area',
  37. 'barrier',
  38. 'bicycle',
  39. 'boundary',
  40. 'brand',
  41. 'bridge',
  42. 'building',
  43. 'capital',
  44. 'construction',
  45. 'covered',
  46. 'culvert',
  47. 'cutting',
  48. 'denomination',
  49. 'disused',
  50. 'ele',
  51. 'embarkment',
  52. 'foot',
  53. 'generation:source',
  54. 'harbour',
  55. 'highway',
  56. 'historic',
  57. 'hours',
  58. 'intermittent',
  59. 'junction',
  60. 'landuse',
  61. 'layer',
  62. 'leisure',
  63. 'lock',
  64. 'man_made',
  65. 'military',
  66. 'motor_car',
  67. 'name',
  68. 'natural',
  69. 'office',
  70. 'oneway',
  71. 'operator',
  72. 'place',
  73. 'population',
  74. 'power',
  75. 'power_source',
  76. 'public_transport',
  77. 'railway',
  78. 'ref',
  79. 'religion',
  80. 'route',
  81. 'service',
  82. 'shop',
  83. 'sport',
  84. 'surface',
  85. 'toll',
  86. 'tourism',
  87. 'tower:type',
  88. 'tracktype',
  89. 'tunnel',
  90. 'type',
  91. 'water',
  92. 'waterway',
  93. 'wetland',
  94. 'width',
  95. 'wood'
  96. }
  97. -- The following keys will be deleted
  98. delete_tags = {
  99. 'FIXME',
  100. 'note',
  101. 'source'
  102. }
  103. -- Array used to specify z_order per key/value combination.
  104. -- Each element has the form {key, value, z_order, is_road}.
  105. -- If is_road=1, the object will be added to planet_osm_roads.
  106. zordering_tags = {{ 'railway', nil, 5, 1}, { 'boundary', 'administrative', 0, 1},
  107. { 'bridge', 'yes', 10, 0 }, { 'bridge', 'true', 10, 0 }, { 'bridge', 1, 10, 0 },
  108. { 'tunnel', 'yes', -10, 0}, { 'tunnel', 'true', -10, 0}, { 'tunnel', 1, -10, 0},
  109. { 'highway', 'minor', 3, 0}, { 'highway', 'road', 3, 0 }, { 'highway', 'unclassified', 3, 0 },
  110. { 'highway', 'residential', 3, 0 }, { 'highway', 'tertiary_link', 4, 0}, { 'highway', 'tertiary', 4, 0},
  111. { 'highway', 'secondary_link', 6, 1}, { 'highway', 'secondary', 6, 1},
  112. { 'highway', 'primary_link', 7, 1}, { 'highway', 'primary', 7, 1},
  113. { 'highway', 'trunk_link', 8, 1}, { 'highway', 'trunk', 8, 1},
  114. { 'highway', 'motorway_link', 9, 1}, { 'highway', 'motorway', 9, 1},
  115. }
  116. function add_z_order(keyvalues)
  117. -- The default z_order is 0
  118. z_order = 0
  119. -- Add the value of the layer key times 10 to z_order
  120. if (keyvalues["layer"] ~= nil and tonumber(keyvalues["layer"])) then
  121. z_order = 10*keyvalues["layer"]
  122. end
  123. -- Increase or decrease z_order based on the specific key/value combination as specified in zordering_tags
  124. for i,k in ipairs(zordering_tags) do
  125. -- If the value in zordering_tags is specified, match key and value. Otherwise, match key only.
  126. if ((k[2] and keyvalues[k[1]] == k[2]) or (k[2] == nil and keyvalues[k[1]] ~= nil)) then
  127. -- If the fourth component of the element of zordering_tags is 1, add the object to planet_osm_roads
  128. if (k[4] == 1) then
  129. roads = 1
  130. end
  131. z_order = z_order + k[3]
  132. end
  133. end
  134. -- Add z_order as key/value combination
  135. keyvalues["z_order"] = z_order
  136. return keyvalues, roads
  137. end
  138. -- Filtering on nodes, ways, and relations
  139. function filter_tags_generic(keyvalues, numberofkeys)
  140. filter = 0 -- Will object be filtered out?
  141. -- Filter out objects with 0 tags
  142. if numberofkeys == 0 then
  143. filter = 1
  144. return filter, keyvalues
  145. end
  146. -- Delete tags listed in delete_tags
  147. for i,k in ipairs(delete_tags) do
  148. keyvalues[k] = nil
  149. end
  150. -- Filter out objects that do not have any of the keys in generic_keys
  151. tagcount = 0
  152. for k,v in pairs(keyvalues) do
  153. for i, k2 in ipairs(generic_keys) do
  154. if k2 == k then
  155. tagcount = tagcount + 1
  156. end
  157. end
  158. end
  159. if tagcount == 0 then
  160. filter = 1
  161. end
  162. return filter, keyvalues
  163. end
  164. -- Filtering on nodes
  165. function filter_tags_node (keyvalues, numberofkeys)
  166. return filter_tags_generic(keyvalues, numberofkeys)
  167. end
  168. -- Filtering on relations
  169. function filter_basic_tags_rel (keyvalues, numberofkeys)
  170. -- Filter out objects that are filtered out by filter_tags_generic
  171. filter, keyvalues = filter_tags_generic(keyvalues, numberofkeys)
  172. if filter == 1 then
  173. return filter, keyvalues
  174. end
  175. -- Filter out all relations except route, multipolygon and boundary relations
  176. if ((keyvalues["type"] ~= "route") and (keyvalues["type"] ~= "multipolygon") and (keyvalues["type"] ~= "boundary")) then
  177. filter = 1
  178. return filter, keyvalues
  179. end
  180. return filter, keyvalues
  181. end
  182. -- Filtering on ways
  183. function filter_tags_way (keyvalues, numberofkeys)
  184. filter = 0 -- Will object be filtered out?
  185. polygon = 0 -- Will object be treated as polygon?
  186. roads = 0 -- Will object be added to planet_osm_roads?
  187. -- Filter out objects that are filtered out by filter_tags_generic
  188. filter, keyvalues = filter_tags_generic(keyvalues, numberofkeys)
  189. if filter == 1 then
  190. return filter, keyvalues, polygon, roads
  191. end
  192. -- Treat objects with a key in polygon_keys as polygon
  193. for i,k in ipairs(polygon_keys) do
  194. if keyvalues[k] then
  195. polygon=1
  196. break
  197. end
  198. end
  199. -- Treat objects tagged as area=yes, area=1, or area=true as polygon,
  200. -- and treat objects tagged as area=no, area=0, or area=false not as polygon
  201. if ((keyvalues["area"] == "yes") or (keyvalues["area"] == "1") or (keyvalues["area"] == "true")) then
  202. polygon = 1;
  203. elseif ((keyvalues["area"] == "no") or (keyvalues["area"] == "0") or (keyvalues["area"] == "false")) then
  204. polygon = 0;
  205. end
  206. -- Add z_order key/value combination and determine if the object should also be added to planet_osm_roads
  207. keyvalues, roads = add_z_order(keyvalues)
  208. return filter, keyvalues, polygon, roads
  209. end
  210. function filter_tags_relation_member (keyvalues, keyvaluemembers, roles, membercount)
  211. filter = 0 -- Will object be filtered out?
  212. linestring = 0 -- Will object be treated as linestring?
  213. polygon = 0 -- Will object be treated as polygon?
  214. roads = 0 -- Will object be added to planet_osm_roads?
  215. type = keyvalues["type"]
  216. -- Remove type key
  217. keyvalues["type"] = nil
  218. -- Relations with type=boundary are treated as linestring
  219. if (type == "boundary") then
  220. linestring = 1
  221. end
  222. -- Relations with type=multipolygon and boundary=* are treated as linestring
  223. if ((type == "multipolygon") and keyvalues["boundary"]) then
  224. linestring = 1
  225. -- For multipolygons...
  226. elseif (type == "multipolygon") then
  227. -- Treat as polygon
  228. polygon = 1
  229. end
  230. -- Add z_order key/value combination and determine if the object should also be added to planet_osm_roads
  231. keyvalues, roads = add_z_order(keyvalues)
  232. return filter, keyvalues, {}, linestring, polygon, roads
  233. end