generic.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. -- This is a generic configuration that is a good starting point for
  5. -- real-world projects. Data is split into tables according to geometry type
  6. -- and most tags are stored in jsonb columns.
  7. -- Set this to the projection you want to use
  8. local srid = 3857
  9. local tables = {}
  10. tables.points = osm2pgsql.define_node_table('generic_points', {
  11. { column = 'tags', type = 'jsonb' },
  12. { column = 'geom', type = 'point', projection = srid, not_null = true },
  13. }, {
  14. schema = schema,
  15. proj = 3301
  16. })
  17. tables.lines = osm2pgsql.define_way_table('generic_lines', {
  18. { column = 'tags', type = 'jsonb' },
  19. { column = 'geom', type = 'linestring', projection = srid, not_null = true },
  20. }, {
  21. schema = schema,
  22. proj = 3301
  23. })
  24. tables.polygons = osm2pgsql.define_area_table('generic_polygons', {
  25. { column = 'tags', type = 'jsonb' },
  26. { column = 'geom', type = 'geometry', projection = srid, not_null = true },
  27. }, {
  28. schema = schema,
  29. proj = 3301
  30. })
  31. tables.routes = osm2pgsql.define_relation_table('generic_routes', {
  32. { column = 'tags', type = 'jsonb' },
  33. { column = 'geom', type = 'multilinestring', projection = srid, not_null = true },
  34. }, {
  35. schema = schema,
  36. proj = 3301
  37. })
  38. tables.boundaries = osm2pgsql.define_relation_table('generic_boundaries', {
  39. { column = 'tags', type = 'jsonb' },
  40. { column = 'geom', type = 'multilinestring', projection = srid, not_null = true },
  41. }, {
  42. schema = schema,
  43. proj = 3301
  44. })
  45. -- These tag keys are generally regarded as useless for most rendering. Most
  46. -- of them are from imports or intended as internal information for mappers.
  47. --
  48. -- If a key ends in '*' it will match all keys with the specified prefix.
  49. --
  50. -- If you want some of these keys, perhaps for a debugging layer, just
  51. -- delete the corresponding lines.
  52. local delete_keys = {
  53. -- "mapper" keys
  54. 'attribution',
  55. 'comment',
  56. 'created_by',
  57. 'fixme',
  58. 'note',
  59. 'note:*',
  60. 'odbl',
  61. 'odbl:note',
  62. 'source',
  63. 'source:*',
  64. 'source_ref',
  65. -- "import" keys
  66. -- Corine Land Cover (CLC) (Europe)
  67. 'CLC:*',
  68. -- Geobase (CA)
  69. 'geobase:*',
  70. -- CanVec (CA)
  71. 'canvec:*',
  72. -- osak (DK)
  73. 'osak:*',
  74. -- kms (DK)
  75. 'kms:*',
  76. -- ngbe (ES)
  77. -- See also note:es and source:file above
  78. 'ngbe:*',
  79. -- Friuli Venezia Giulia (IT)
  80. 'it:fvg:*',
  81. -- KSJ2 (JA)
  82. -- See also note:ja and source_ref above
  83. 'KSJ2:*',
  84. -- Yahoo/ALPS (JA)
  85. 'yh:*',
  86. -- LINZ (NZ)
  87. 'LINZ2OSM:*',
  88. 'linz2osm:*',
  89. 'LINZ:*',
  90. 'ref:linz:*',
  91. -- WroclawGIS (PL)
  92. 'WroclawGIS:*',
  93. -- Naptan (UK)
  94. 'naptan:*',
  95. -- TIGER (US)
  96. 'tiger:*',
  97. -- GNIS (US)
  98. 'gnis:*',
  99. -- National Hydrography Dataset (US)
  100. 'NHD:*',
  101. 'nhd:*',
  102. -- mvdgis (Montevideo, UY)
  103. 'mvdgis:*',
  104. -- EUROSHA (Various countries)
  105. 'project:eurosha_2012',
  106. -- UrbIS (Brussels, BE)
  107. 'ref:UrbIS',
  108. -- NHN (CA)
  109. 'accuracy:meters',
  110. 'sub_sea:type',
  111. 'waterway:type',
  112. -- StatsCan (CA)
  113. 'statscan:rbuid',
  114. -- RUIAN (CZ)
  115. 'ref:ruian:addr',
  116. 'ref:ruian',
  117. 'building:ruian:type',
  118. -- DIBAVOD (CZ)
  119. 'dibavod:id',
  120. -- UIR-ADR (CZ)
  121. 'uir_adr:ADRESA_KOD',
  122. -- GST (DK)
  123. 'gst:feat_id',
  124. -- Maa-amet (EE)
  125. 'maaamet:ETAK',
  126. -- FANTOIR (FR)
  127. 'ref:FR:FANTOIR',
  128. -- 3dshapes (NL)
  129. '3dshapes:ggmodelk',
  130. -- AND (NL)
  131. 'AND_nosr_r',
  132. -- OPPDATERIN (NO)
  133. 'OPPDATERIN',
  134. -- Various imports (PL)
  135. 'addr:city:simc',
  136. 'addr:street:sym_ul',
  137. 'building:usage:pl',
  138. 'building:use:pl',
  139. -- TERYT (PL)
  140. 'teryt:simc',
  141. -- RABA (SK)
  142. 'raba:id',
  143. -- DCGIS (Washington DC, US)
  144. 'dcgis:gis_id',
  145. -- Building Identification Number (New York, US)
  146. 'nycdoitt:bin',
  147. -- Chicago Building Inport (US)
  148. 'chicago:building_id',
  149. -- Louisville, Kentucky/Building Outlines Import (US)
  150. 'lojic:bgnum',
  151. -- MassGIS (Massachusetts, US)
  152. 'massgis:way_id',
  153. -- Los Angeles County building ID (US)
  154. 'lacounty:*',
  155. -- Address import from Bundesamt für Eich- und Vermessungswesen (AT)
  156. 'at_bev:addr_date',
  157. -- misc
  158. 'import',
  159. 'import_uuid',
  160. 'OBJTYPE',
  161. 'SK53_bulk:load',
  162. 'mml:class'
  163. }
  164. -- The osm2pgsql.make_clean_tags_func() function takes the list of keys
  165. -- and key prefixes defined above and returns a function that can be used
  166. -- to clean those tags out of a Lua table. The clean_tags function will
  167. -- return true if it removed all tags from the table.
  168. local clean_tags = osm2pgsql.make_clean_tags_func(delete_keys)
  169. -- Helper function that looks at the tags and decides if this is possibly
  170. -- an area.
  171. local function has_area_tags(tags)
  172. if tags.area == 'yes' then
  173. return true
  174. end
  175. if tags.area == 'no' then
  176. return false
  177. end
  178. return tags.aeroway
  179. or tags.amenity
  180. or tags.building
  181. or tags.harbour
  182. or tags.historic
  183. or tags.landuse
  184. or tags.leisure
  185. or tags.man_made
  186. or tags.military
  187. or tags.natural
  188. or tags.office
  189. or tags.place
  190. or tags.power
  191. or tags.public_transport
  192. or tags.shop
  193. or tags.sport
  194. or tags.tourism
  195. or tags.water
  196. or tags.waterway
  197. or tags.wetland
  198. or tags['abandoned:aeroway']
  199. or tags['abandoned:amenity']
  200. or tags['abandoned:building']
  201. or tags['abandoned:landuse']
  202. or tags['abandoned:power']
  203. or tags['area:highway']
  204. or tags['building:part']
  205. end
  206. function osm2pgsql.process_node(object)
  207. if clean_tags(object.tags) then
  208. return
  209. end
  210. tables.points:insert({
  211. tags = object.tags,
  212. geom = object:as_point()
  213. })
  214. end
  215. function osm2pgsql.process_way(object)
  216. if clean_tags(object.tags) then
  217. return
  218. end
  219. if object.is_closed and has_area_tags(object.tags) then
  220. tables.polygons:insert({
  221. tags = object.tags,
  222. geom = object:as_polygon()
  223. })
  224. else
  225. tables.lines:insert({
  226. tags = object.tags,
  227. geom = object:as_linestring()
  228. })
  229. end
  230. end
  231. function osm2pgsql.process_relation(object)
  232. local relation_type = object:grab_tag('type')
  233. if clean_tags(object.tags) then
  234. return
  235. end
  236. if relation_type == 'route' then
  237. tables.routes:insert({
  238. tags = object.tags,
  239. geom = object:as_multilinestring()
  240. })
  241. return
  242. end
  243. if relation_type == 'boundary' or (relation_type == 'multipolygon' and object.tags.boundary) then
  244. tables.boundaries:insert({
  245. tags = object.tags,
  246. geom = object:as_multilinestring():line_merge()
  247. })
  248. return
  249. end
  250. if relation_type == 'multipolygon' then
  251. tables.polygons:insert({
  252. tags = object.tags,
  253. geom = object:as_multipolygon()
  254. })
  255. end
  256. end