Skip to content

Commit 672b1b0

Browse files
authored
Merge pull request #1784 from joto/modernize-flex-config
Modernize flex config
2 parents 44f0023 + eb53204 commit 672b1b0

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
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

flex-config/data-types.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function osm2pgsql.process_way(object)
102102
-- We want to put the name in its own column
103103
local name = object:grab_tag('name')
104104

105-
highways:add_row({
105+
highways:insert({
106106
name = name,
107107
type = highway_type,
108108

@@ -122,7 +122,8 @@ function osm2pgsql.process_way(object)
122122
-- for a column of type "int8[]".
123123
nodes = '{' .. table.concat(object.nodes, ',') .. '}',
124124

125-
tags = object.tags
125+
tags = object.tags,
126+
geom = object:as_linestring()
126127
})
127128
end
128129

flex-config/places.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ function osm2pgsql.process_node(object)
4242
object.tags.population = tonumber(object.tags.population)
4343
end
4444

45-
places:add_row({
46-
tags = object.tags
45+
places:insert({
46+
tags = object.tags,
47+
geom = object:as_point()
4748
})
4849
end
4950

flex-config/with-schema.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
local dtable = osm2pgsql.define_way_table('data', {
1010
{ column = 'tags', type = 'jsonb' },
11-
{ column = 'geom', type = 'geometry' },
11+
{ column = 'geom', type = 'linestring' },
1212
}, { schema = 'myschema' })
1313

1414
function osm2pgsql.process_way(object)
15-
dtable:add_row({
15+
dtable:insert({
1616
tags = object.tags,
17-
geom = { create = 'line' }
17+
geom = object:as_linestring()
1818
})
1919
end
2020

0 commit comments

Comments
 (0)