Skip to content

Commit 2e6e7ec

Browse files
authored
Merge pull request #1465 from joto/attributes-lua-example
Add flex config example showing how to access attributes in Lua
2 parents 4680152 + 06f4235 commit 2e6e7ec

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

flex-config/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ After that you can dive into more advanced topics:
2424
* [unitable.lua](unitable.lua) -- Put all OSM data into a single table
2525
* [places.lua](places.lua) -- Creating JSON/JSONB columns
2626
* [with-schema.lua](with-schema.lua) -- Use a database schema
27+
* [attributes.lua](attributes.lua) -- How to access OSM object attributes
2728

2829
The "generic" configuration is a full-featured but simple configuration that
2930
is a good starting point for your own real-world configuration:

flex-config/attributes.lua

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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
9+
local srid = 4326
10+
11+
local tables = {}
12+
13+
tables.points = osm2pgsql.define_node_table('points', {
14+
{ column = 'tags', type = 'hstore' },
15+
{ column = 'geom', type = 'point', projection = srid },
16+
{ column = 'version', type = 'int' },
17+
{ column = 'changeset', type = 'int' },
18+
{ column = 'created', type = 'timestamp' },
19+
{ column = 'uid', type = 'int' },
20+
{ column = 'user', type = 'text' },
21+
})
22+
23+
tables.lines = osm2pgsql.define_way_table('lines', {
24+
{ column = 'tags', type = 'hstore' },
25+
{ column = 'geom', type = 'linestring', projection = srid },
26+
{ column = 'version', type = 'int' },
27+
{ column = 'changeset', type = 'int' },
28+
{ column = 'created', type = 'timestamp' },
29+
{ column = 'uid', type = 'int' },
30+
{ column = 'user', type = 'text' },
31+
})
32+
33+
tables.relations = osm2pgsql.define_relation_table('relations', {
34+
{ column = 'tags', type = 'hstore' },
35+
{ column = 'version', type = 'int' },
36+
{ column = 'changeset', type = 'int' },
37+
{ column = 'created', type = 'timestamp' },
38+
{ column = 'uid', type = 'int' },
39+
{ column = 'user', type = 'text' },
40+
})
41+
42+
function osm2pgsql.process_node(object)
43+
if next(object.tags) == nil then
44+
return
45+
end
46+
47+
tables.points:add_row({
48+
tags = object.tags,
49+
version = object.version,
50+
changeset = object.changeset,
51+
created = os.date('!%Y-%m-%dT%TZ', object.timestamp),
52+
uid = object.uid,
53+
user = object.user
54+
})
55+
end
56+
57+
function osm2pgsql.process_way(object)
58+
tables.lines:add_row({
59+
tags = object.tags,
60+
version = object.version,
61+
changeset = object.changeset,
62+
created = os.date('!%Y-%m-%dT%TZ', object.timestamp),
63+
uid = object.uid,
64+
user = object.user
65+
})
66+
end
67+
68+
function osm2pgsql.process_relation(object)
69+
tables.relations:add_row({
70+
tags = object.tags,
71+
version = object.version,
72+
changeset = object.changeset,
73+
created = os.date('!%Y-%m-%dT%TZ', object.timestamp),
74+
uid = object.uid,
75+
user = object.user
76+
})
77+
end
78+

0 commit comments

Comments
 (0)