unitable.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. -- Put all OSM data into a single table
  5. -- We define a single table that can take any OSM object and any geometry.
  6. -- OSM nodes are converted to Points, ways to LineStrings and relations
  7. -- to GeometryCollections. If an object would create an invalid geometry
  8. -- it is still added to the table with a NULL geometry.
  9. local dtable = osm2pgsql.define_table{
  10. name = "data",
  11. schema = schema,
  12. proj = 3301,
  13. -- This will generate a column "osm_id INT8" for the id, and a column
  14. -- "osm_type CHAR(1)" for the type of object: N(ode), W(way), R(relation)
  15. ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' },
  16. columns = {
  17. { column = 'attrs', type = 'jsonb' },
  18. { column = 'tags', type = 'jsonb' },
  19. { column = 'geom', type = 'geometry' },
  20. }}
  21. -- Helper function to remove some of the tags we usually are not interested in.
  22. -- Returns true if there are no tags left.
  23. local function clean_tags(tags)
  24. tags.odbl = nil
  25. tags.created_by = nil
  26. tags.source = nil
  27. tags['source:ref'] = nil
  28. return next(tags) == nil
  29. end
  30. local function process(object, geometry)
  31. if clean_tags(object.tags) then
  32. return
  33. end
  34. dtable:insert({
  35. attrs = {
  36. version = object.version,
  37. timestamp = object.timestamp,
  38. },
  39. tags = object.tags,
  40. geom = geometry
  41. })
  42. end
  43. function osm2pgsql.process_node(object)
  44. process(object, object:as_point())
  45. end
  46. function osm2pgsql.process_way(object)
  47. process(object, object:as_linestring())
  48. end
  49. function osm2pgsql.process_relation(object)
  50. process(object, object:as_geometrycollection())
  51. end