expire.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. -- Määrame skeemi keskkonnamuutujast või vaikimisi 'public'
  2. local schema = os.getenv("PGSCHEMA") or "public"
  3. -- This config example file is released into the Public Domain.
  4. --
  5. -- This examples shows how to use tile expiry.
  6. local expire_outputs = {}
  7. expire_outputs.pois = osm2pgsql.define_expire_output({
  8. -- The zoom level at which we calculate the tiles. This must always be set.
  9. maxzoom = 14,
  10. -- The filename where tile list should be written to.
  11. filename = 'pois.tiles'
  12. })
  13. expire_outputs.lines = osm2pgsql.define_expire_output({
  14. maxzoom = 14,
  15. -- Instead of writing the tile list to a file, it can be written to a table.
  16. -- The table will be created if it isn't there already.
  17. table = 'lines_tiles',
  18. schema = schema, -- You can also set a database schema.
  19. })
  20. expire_outputs.polygons = osm2pgsql.define_expire_output({
  21. -- You can also set a minimum zoom level in addition to the maximum zoom
  22. -- level. Tiles in all zoom levels between those two will be written out.
  23. minzoom = 10,
  24. maxzoom = 14,
  25. table = 'polygons_tiles',
  26. schema = schema
  27. })
  28. print("Expire outputs:(")
  29. for name, eo in pairs(expire_outputs) do
  30. print(" " .. name
  31. .. ": minzoom=" .. eo:minzoom()
  32. .. " maxzoom=" .. eo:maxzoom()
  33. .. " filename=" .. eo:filename()
  34. .. " schema=" .. eo:schema()
  35. .. " table=" .. eo:table())
  36. end
  37. print(")")
  38. local tables = {}
  39. tables.pois = osm2pgsql.define_node_table('expire_pois', {
  40. { column = 'tags', type = 'jsonb' },
  41. -- Zero, one or more expire outputs are referenced in an `expire` field in
  42. -- the definition of any geometry column using the Web Mercator (3857)
  43. -- projection.
  44. { column = 'geom', type = 'point', not_null = true, expire = {
  45. { output = expire_outputs.pois }
  46. }},
  47. }, {
  48. schema = schema,
  49. proj = 3301
  50. })
  51. tables.lines = osm2pgsql.define_way_table('expire_lines', {
  52. { column = 'tags', type = 'jsonb' },
  53. -- If you only have a single expire output and with the default
  54. -- parameters, you can specify it directly.
  55. { column = 'geom', type = 'linestring', not_null = true, expire = expire_outputs.lines },
  56. }, {
  57. schema = schema,
  58. proj = 3301
  59. })
  60. tables.polygons = osm2pgsql.define_area_table('expire_polygons', {
  61. { column = 'tags', type = 'jsonb' },
  62. -- In this configuration the `mode` of the expiry is set to `boundary-only`.
  63. -- Other modes are `full-area` (default) and `hybrid`. If set to `hybrid`
  64. -- you can set `full_area_limit` to a value in Web Mercator units. For
  65. -- polygons where the width and height of the bounding box is below this
  66. -- limit the full area is expired, for larger polygons only the boundary.
  67. -- This setting doesn't have any effect on point or linestring geometries.
  68. { column = 'geom', type = 'geometry', not_null = true, expire = {
  69. { output = expire_outputs.polygons, mode = 'boundary-only' }
  70. }}
  71. }, {
  72. schema = schema,
  73. proj = 3301
  74. })
  75. tables.boundaries = osm2pgsql.define_relation_table('expire_boundaries', {
  76. { column = 'type', type = 'text' },
  77. { column = 'tags', type = 'jsonb' },
  78. -- This geometry column doesn't have an `expire` field, so no expiry is
  79. -- done.
  80. { column = 'geom', type = 'multilinestring', not_null = true },
  81. }, {
  82. schema = schema,
  83. proj = 3301
  84. })
  85. print("Tables:(")
  86. for name, ts in pairs(tables) do
  87. print(" " .. name .. ": name=" .. ts:name() .. " (" .. tostring(ts) .. ")")
  88. end
  89. print(")")
  90. -- Helper function that looks at the tags and decides if this is possibly
  91. -- an area.
  92. local function has_area_tags(tags)
  93. if tags.area == 'yes' then
  94. return true
  95. end
  96. if tags.area == 'no' then
  97. return false
  98. end
  99. return tags.aeroway
  100. or tags.amenity
  101. or tags.building
  102. or tags.harbour
  103. or tags.historic
  104. or tags.landuse
  105. or tags.leisure
  106. or tags.man_made
  107. or tags.military
  108. or tags.natural
  109. or tags.office
  110. or tags.place
  111. or tags.power
  112. or tags.public_transport
  113. or tags.shop
  114. or tags.sport
  115. or tags.tourism
  116. or tags.water
  117. or tags.waterway
  118. or tags.wetland
  119. or tags['abandoned:aeroway']
  120. or tags['abandoned:amenity']
  121. or tags['abandoned:building']
  122. or tags['abandoned:landuse']
  123. or tags['abandoned:power']
  124. or tags['area:highway']
  125. end
  126. function osm2pgsql.process_node(object)
  127. tables.pois:insert({
  128. tags = object.tags,
  129. geom = object:as_point()
  130. })
  131. end
  132. function osm2pgsql.process_way(object)
  133. if object.is_closed and has_area_tags(object.tags) then
  134. tables.polygons:insert({
  135. tags = object.tags,
  136. geom = object:as_polygon()
  137. })
  138. else
  139. tables.lines:insert({
  140. tags = object.tags,
  141. geom = object:as_linestring()
  142. })
  143. end
  144. end
  145. function osm2pgsql.process_relation(object)
  146. local relation_type = object:grab_tag('type')
  147. -- Store boundary relations as multilinestrings
  148. if relation_type == 'boundary' then
  149. tables.boundaries:insert({
  150. type = object:grab_tag('boundary'),
  151. tags = object.tags,
  152. geom = object:as_multilinestring():line_merge()
  153. })
  154. return
  155. end
  156. -- Store multipolygon relations as polygons
  157. if relation_type == 'multipolygon' then
  158. tables.polygons:insert({
  159. tags = object.tags,
  160. geom = object:as_multipolygon()
  161. })
  162. end
  163. end