1-- This config example file is released into the Public Domain.
2
3-- This config shows how to access the attributes of OSM objects: the version,
4-- changeset id, timestamp, user id and user name. For this to work the
5-- command line option --extra-attributes/-x must be set, otherwise those
6-- fields will be empty.
7
8-- Set this to the projection you want to use
9local srid = 4326
10
11local tables = {}
12
13tables.points = osm2pgsql.define_node_table('points', {
14    { column = 'tags', type = 'jsonb' },
15    { column = 'geom', type = 'point', projection = srid },
16    { column = 'version', type = 'int' },
17    { column = 'changeset', type = 'int' },
18    -- There is no built-in type for timestamps in osm2pgsql. So we use the
19    -- PostgreSQL type "timestamp" and then have to convert our timestamps
20    -- to a valid text representation for that type.
21    { column = 'created', sql_type = 'timestamp' },
22    { column = 'uid', type = 'int' },
23    { column = 'user', type = 'text' },
24})
25
26tables.lines = osm2pgsql.define_way_table('lines', {
27    { column = 'tags', type = 'jsonb' },
28    { column = 'geom', type = 'linestring', projection = srid },
29    { column = 'version', type = 'int' },
30    { column = 'changeset', type = 'int' },
31    { column = 'created', sql_type = 'timestamp' },
32    { column = 'uid', type = 'int' },
33    { column = 'user', type = 'text' },
34})
35
36tables.relations = osm2pgsql.define_relation_table('relations', {
37    { column = 'tags', type = 'jsonb' },
38    { column = 'version', type = 'int' },
39    { column = 'changeset', type = 'int' },
40    { column = 'created', sql_type = 'timestamp' },
41    { column = 'uid', type = 'int' },
42    { column = 'user', type = 'text' },
43})
44
45function osm2pgsql.process_node(object)
46    if next(object.tags) == nil then
47        return
48    end
49
50    tables.points:add_row({
51        tags = object.tags,
52        version = object.version,
53        changeset = object.changeset,
54        created = os.date('!%Y-%m-%dT%H:%M:%SZ', object.timestamp),
55        uid = object.uid,
56        user = object.user
57    })
58end
59
60function osm2pgsql.process_way(object)
61    tables.lines:add_row({
62        tags = object.tags,
63        version = object.version,
64        changeset = object.changeset,
65        created = os.date('!%Y-%m-%dT%H:%M:%SZ', object.timestamp),
66        uid = object.uid,
67        user = object.user
68    })
69end
70
71function osm2pgsql.process_relation(object)
72    tables.relations:add_row({
73        tags = object.tags,
74        version = object.version,
75        changeset = object.changeset,
76        created = os.date('!%Y-%m-%dT%H:%M:%SZ', object.timestamp),
77        uid = object.uid,
78        user = object.user
79    })
80end
81
82