Skip to content

Commit 7483c08

Browse files
committed
Modernize attributes.lua example config
* Use insert() * Use table names nodes/ways instead of points/lines * Add nodes/members fields for ways/relations
1 parent 5b5685f commit 7483c08

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

flex-config/attributes.lua

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
-- This config shows how to access the attributes of OSM objects: the version,
44
-- changeset id, timestamp, user id and user name. For this to work the
55
-- command line option --extra-attributes/-x must be set, otherwise those
6-
-- fields will be empty.
6+
-- fields will be empty. Also note that some OSM files do not contain all
7+
-- of those attributes, so check your input data if you get empty fields.
78

89
-- Set this to the projection you want to use
910
local srid = 4326
1011

1112
local tables = {}
1213

13-
tables.points = osm2pgsql.define_node_table('points', {
14+
tables.nodes = osm2pgsql.define_node_table('nodes', {
1415
{ column = 'tags', type = 'jsonb' },
1516
{ column = 'geom', type = 'point', projection = srid },
1617
{ column = 'version', type = 'int' },
@@ -23,14 +24,15 @@ tables.points = osm2pgsql.define_node_table('points', {
2324
{ column = 'user', type = 'text' },
2425
})
2526

26-
tables.lines = osm2pgsql.define_way_table('lines', {
27+
tables.ways = osm2pgsql.define_way_table('ways', {
2728
{ column = 'tags', type = 'jsonb' },
2829
{ column = 'geom', type = 'linestring', projection = srid },
2930
{ column = 'version', type = 'int' },
3031
{ column = 'changeset', type = 'int' },
3132
{ column = 'created', sql_type = 'timestamp' },
3233
{ column = 'uid', type = 'int' },
3334
{ column = 'user', type = 'text' },
35+
{ column = 'nodes', type = 'text', sql_type = 'bigint[]' },
3436
})
3537

3638
tables.relations = osm2pgsql.define_relation_table('relations', {
@@ -40,42 +42,51 @@ tables.relations = osm2pgsql.define_relation_table('relations', {
4042
{ column = 'created', sql_type = 'timestamp' },
4143
{ column = 'uid', type = 'int' },
4244
{ column = 'user', type = 'text' },
45+
{ column = 'members', type = 'jsonb' },
4346
})
4447

48+
function format_date(ts)
49+
return os.date('!%Y-%m-%dT%H:%M:%SZ', ts)
50+
end
51+
4552
function osm2pgsql.process_node(object)
4653
if next(object.tags) == nil then
4754
return
4855
end
4956

50-
tables.points:add_row({
57+
tables.nodes:insert({
5158
tags = object.tags,
59+
geom = object:as_point(),
5260
version = object.version,
5361
changeset = object.changeset,
54-
created = os.date('!%Y-%m-%dT%H:%M:%SZ', object.timestamp),
62+
created = format_date(object.timestamp),
5563
uid = object.uid,
5664
user = object.user
5765
})
5866
end
5967

6068
function osm2pgsql.process_way(object)
61-
tables.lines:add_row({
69+
tables.ways:insert({
6270
tags = object.tags,
71+
geom = object:as_linestring(),
6372
version = object.version,
6473
changeset = object.changeset,
65-
created = os.date('!%Y-%m-%dT%H:%M:%SZ', object.timestamp),
74+
created = format_date(object.timestamp),
6675
uid = object.uid,
67-
user = object.user
76+
user = object.user,
77+
nodes = '{' .. table.concat(object.nodes, ',') .. '}'
6878
})
6979
end
7080

7181
function osm2pgsql.process_relation(object)
72-
tables.relations:add_row({
82+
tables.relations:insert({
7383
tags = object.tags,
7484
version = object.version,
7585
changeset = object.changeset,
76-
created = os.date('!%Y-%m-%dT%H:%M:%SZ', object.timestamp),
86+
created = format_date(object.timestamp),
7787
uid = object.uid,
78-
user = object.user
88+
user = object.user,
89+
members = object.members
7990
})
8091
end
8192

0 commit comments

Comments
 (0)