attributes.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 config shows how to access the attributes of OSM objects: the version,
  5. -- changeset id, timestamp, user id and user name. Note that some OSM files do
  6. -- not contain all of those attributes, so check your input data if you get
  7. -- empty fields.
  8. -- Set this to the projection you want to use
  9. local srid = 3301
  10. local tables = {}
  11. tables.nodes = osm2pgsql.define_node_table('nodes', {
  12. { column = 'tags', type = 'jsonb' },
  13. { column = 'geom', type = 'point', projection = srid },
  14. { column = 'version', type = 'int' },
  15. { column = 'changeset', type = 'int' },
  16. -- There is no built-in type for timestamps in osm2pgsql. So we use the
  17. -- PostgreSQL type "timestamp" and then have to convert our timestamps
  18. -- to a valid text representation for that type.
  19. --
  20. -- Timestamps in OSM are always in UTC, depending on your use case you
  21. -- might want to store them using "timestamptz" instead.
  22. -- See https://github.com/openstreetmap/osm2pgsql/issues/1785
  23. { column = 'created', sql_type = 'timestamp' },
  24. { column = 'uid', type = 'int' },
  25. { column = 'user', type = 'text' },
  26. }, {
  27. schema = schema,
  28. proj = 3301
  29. })
  30. tables.ways = osm2pgsql.define_way_table('ways', {
  31. { column = 'tags', type = 'jsonb' },
  32. { column = 'geom', type = 'linestring', projection = srid },
  33. { column = 'version', type = 'int' },
  34. { column = 'changeset', type = 'int' },
  35. { column = 'created', sql_type = 'timestamp' },
  36. { column = 'uid', type = 'int' },
  37. { column = 'user', type = 'text' },
  38. { column = 'nodes', type = 'text', sql_type = 'bigint[]' },
  39. }, {
  40. schema = schema,
  41. proj = 3301
  42. })
  43. tables.relations = osm2pgsql.define_relation_table('relations', {
  44. { column = 'tags', type = 'jsonb' },
  45. { column = 'version', type = 'int' },
  46. { column = 'changeset', type = 'int' },
  47. { column = 'created', sql_type = 'timestamp' },
  48. { column = 'uid', type = 'int' },
  49. { column = 'user', type = 'text' },
  50. { column = 'members', type = 'jsonb' },
  51. }, {
  52. schema = schema,
  53. proj = 3301
  54. })
  55. local function format_date(ts)
  56. return os.date('!%Y-%m-%dT%H:%M:%SZ', ts)
  57. end
  58. function osm2pgsql.process_node(object)
  59. if next(object.tags) == nil then
  60. return
  61. end
  62. tables.nodes:insert({
  63. tags = object.tags,
  64. geom = object:as_point(),
  65. version = object.version,
  66. changeset = object.changeset,
  67. created = format_date(object.timestamp),
  68. uid = object.uid,
  69. user = object.user
  70. })
  71. end
  72. function osm2pgsql.process_way(object)
  73. tables.ways:insert({
  74. tags = object.tags,
  75. geom = object:as_linestring(),
  76. version = object.version,
  77. changeset = object.changeset,
  78. created = format_date(object.timestamp),
  79. uid = object.uid,
  80. user = object.user,
  81. nodes = '{' .. table.concat(object.nodes, ',') .. '}'
  82. })
  83. end
  84. function osm2pgsql.process_relation(object)
  85. tables.relations:insert({
  86. tags = object.tags,
  87. version = object.version,
  88. changeset = object.changeset,
  89. created = format_date(object.timestamp),
  90. uid = object.uid,
  91. user = object.user,
  92. members = object.members
  93. })
  94. end