Skip to content

Commit f4a93e2

Browse files
authored
Merge pull request #2328 from joto/flex-example-configs
Flex example configs
2 parents ce8be4d + d4225a0 commit f4a93e2

10 files changed

+37
-124
lines changed

flex-config/attributes.lua

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
-- This config example file is released into the Public Domain.
22

33
-- 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. Also note that some OSM files do not contain all
7-
-- of those attributes, so check your input data if you get empty fields.
4+
-- changeset id, timestamp, user id and user name. Note that some OSM files do
5+
-- not contain all of those attributes, so check your input data if you get
6+
-- empty fields.
87

98
-- Set this to the projection you want to use
109
local srid = 4326

flex-config/bbox.lua

-23
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@ tables.boundaries = osm2pgsql.define_relation_table('boundaries', {
3030
{ column = 'geom', type = 'multilinestring' },
3131
})
3232

33-
-- Helper function to remove some of the tags we usually are not interested in.
34-
-- Returns true if there are no tags left.
35-
local function clean_tags(tags)
36-
tags.odbl = nil
37-
tags.created_by = nil
38-
tags.source = nil
39-
tags['source:ref'] = nil
40-
41-
return next(tags) == nil
42-
end
43-
4433
-- Helper function that looks at the tags and decides if this is possibly
4534
-- an area.
4635
local function has_area_tags(tags)
@@ -91,10 +80,6 @@ local function format_bbox(object)
9180
end
9281

9382
function osm2pgsql.process_node(object)
94-
if clean_tags(object.tags) then
95-
return
96-
end
97-
9883
tables.pois:insert({
9984
tags = object.tags,
10085
bbox = format_bbox(object),
@@ -103,10 +88,6 @@ function osm2pgsql.process_node(object)
10388
end
10489

10590
function osm2pgsql.process_way(object)
106-
if clean_tags(object.tags) then
107-
return
108-
end
109-
11091
-- A closed way that also has the right tags for an area is a polygon.
11192
if object.is_closed and has_area_tags(object.tags) then
11293
tables.polygons:insert({
@@ -124,10 +105,6 @@ function osm2pgsql.process_way(object)
124105
end
125106

126107
function osm2pgsql.process_relation(object)
127-
if clean_tags(object.tags) then
128-
return
129-
end
130-
131108
local relation_type = object:grab_tag('type')
132109

133110
-- Store boundary relations as multilinestrings

flex-config/data-types.lua

+11-9
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,33 @@
55
-- at this file. This file demonstrates some column data type options.
66

77
local highways = osm2pgsql.define_way_table('highways', {
8-
{ column = 'name', type = 'text' },
8+
{ column = 'name', type = 'text' },
99
-- We always need a highway type, so we can declare the column as NOT NULL
10-
{ column = 'type', type = 'text', not_null = true },
10+
{ column = 'type', type = 'text', not_null = true },
1111

1212
-- Add a SERIAL column and tell osm2pgsql not to fill it (PostgreSQL will
1313
-- do that for us)
14-
{ column = 'id', sql_type = 'serial', create_only = true },
14+
{ column = 'id', sql_type = 'serial', create_only = true },
1515

1616
-- type "direction" is special, see below
17-
{ column = 'oneway', type = 'direction' },
17+
{ column = 'oneway', type = 'direction' },
1818
{ column = 'maxspeed', type = 'int' },
1919

2020
-- type "bool" is special, see below
21-
{ column = 'lit', type = 'bool' },
22-
{ column = 'tags', type = 'jsonb' }, -- also available: 'json', 'hstore'
21+
{ column = 'lit', type = 'bool' },
22+
{ column = 'tags', type = 'jsonb' }, -- also available: 'json', 'hstore'
2323

2424
-- osm2pgsql doesn't know about PostgreSQL arrays, so we define the SQL
2525
-- type of this column and then have to convert our array data into a
2626
-- valid text representation for that type, see below.
27-
{ column = 'nodes', sql_type = 'int8[]' },
28-
{ column = 'geom', type = 'linestring' },
27+
{ column = 'nodes', sql_type = 'int8[]' },
28+
{ column = 'geom', type = 'linestring' },
2929
})
3030

3131
-- Helper function to remove some of the tags we usually are not interested in.
32-
-- Returns true if there are no tags left.
32+
-- Something like this can be useful if you are writing all tags to the
33+
-- database in a JSON(B) column and don't want that cluttered with lots of tags
34+
-- nobody cares about. Returns true if there are no tags left.
3335
local function clean_tags(tags)
3436
tags.odbl = nil
3537
tags.created_by = nil

flex-config/expire.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ tables.pois = osm2pgsql.define_node_table('pois', {
4545
-- Zero, one or more expire outputs are referenced in an `expire` field in
4646
-- the definition of any geometry column using the Web Mercator (3857)
4747
-- projection.
48-
{ column = 'geom', type = 'point', not_null = true, expire = { { output = expire_outputs.pois } } },
48+
{ column = 'geom', type = 'point', not_null = true, expire = {
49+
{ output = expire_outputs.pois }
50+
}},
4951
})
5052

5153
tables.lines = osm2pgsql.define_way_table('lines', {

flex-config/geometries.lua

-23
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,6 @@ tables.pubs = osm2pgsql.define_node_table('pubs', {
5555
{ column = 'name', type = 'text' }
5656
})
5757

58-
-- Helper function to remove some of the tags we usually are not interested in.
59-
-- Returns true if there are no tags left.
60-
local function clean_tags(tags)
61-
tags.odbl = nil
62-
tags.created_by = nil
63-
tags.source = nil
64-
tags['source:ref'] = nil
65-
66-
return next(tags) == nil
67-
end
68-
6958
-- Helper function that looks at the tags and decides if this is possibly
7059
-- an area.
7160
local function has_area_tags(tags)
@@ -105,10 +94,6 @@ local function has_area_tags(tags)
10594
end
10695

10796
function osm2pgsql.process_node(object)
108-
if clean_tags(object.tags) then
109-
return
110-
end
111-
11297
local geom = object:as_point()
11398

11499
tables.pois:insert({
@@ -124,10 +109,6 @@ function osm2pgsql.process_node(object)
124109
end
125110

126111
function osm2pgsql.process_way(object)
127-
if clean_tags(object.tags) then
128-
return
129-
end
130-
131112
-- A closed way that also has the right tags for an area is a polygon.
132113
if object.is_closed and has_area_tags(object.tags) then
133114
-- Creating the polygon geometry takes time, so we do it once here
@@ -166,10 +147,6 @@ function osm2pgsql.process_way(object)
166147
end
167148

168149
function osm2pgsql.process_relation(object)
169-
if clean_tags(object.tags) then
170-
return
171-
end
172-
173150
local relation_type = object:grab_tag('type')
174151

175152
-- Store boundary relations as multilinestrings

flex-config/public-transport.lua

+10-21
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,35 @@
2020
local tables = {}
2121

2222
tables.stops = osm2pgsql.define_node_table('stops', {
23-
{ column = 'tags', type = 'jsonb' },
23+
{ column = 'tags', type = 'jsonb' },
2424
{ column = 'rel_refs', type = 'text' }, -- for the refs from the relations
25-
{ column = 'rel_ids', sql_type = 'int8[]' }, -- array with integers (for relation IDs)
26-
{ column = 'geom', type = 'point', not_null = true },
25+
{ column = 'rel_ids', sql_type = 'int8[]' }, -- array with integers (for relation IDs)
26+
{ column = 'geom', type = 'point', not_null = true },
2727
})
2828

2929
tables.lines = osm2pgsql.define_way_table('lines', {
30-
{ column = 'tags', type = 'jsonb' },
30+
{ column = 'tags', type = 'jsonb' },
3131
{ column = 'rel_refs', type = 'text' }, -- for the refs from the relations
32-
{ column = 'rel_ids', sql_type = 'int8[]' }, -- array with integers (for relation IDs)
33-
{ column = 'geom', type = 'linestring', not_null = true },
32+
{ column = 'rel_ids', sql_type = 'int8[]' }, -- array with integers (for relation IDs)
33+
{ column = 'geom', type = 'linestring', not_null = true },
3434
})
3535

3636
-- Tables don't have to have a geometry column
3737
tables.routes = osm2pgsql.define_relation_table('routes', {
38-
{ column = 'ref', type = 'text' },
38+
{ column = 'ref', type = 'text' },
3939
{ column = 'type', type = 'text' },
4040
{ column = 'from', type = 'text' },
41-
{ column = 'to', type = 'text' },
41+
{ column = 'to', type = 'text' },
4242
{ column = 'tags', type = 'jsonb' },
4343
})
4444

4545
-- Stop areas contain everything belonging to a specific public transport
4646
-- stop. We model them here by adding a center point as geometry plus the
4747
-- radius of a circle that contains everything in that stop.
4848
tables.stop_areas = osm2pgsql.define_relation_table('stop_areas', {
49-
{ column = 'tags', type = 'jsonb' },
49+
{ column = 'tags', type = 'jsonb' },
5050
{ column = 'radius', type = 'real', not_null = true },
51-
{ column = 'geom', type = 'point', not_null = true },
51+
{ column = 'geom', type = 'point', not_null = true },
5252
})
5353

5454
-- This will be used to store information about relations queryable by member
@@ -61,15 +61,6 @@ tables.stop_areas = osm2pgsql.define_relation_table('stop_areas', {
6161
local n2r = {}
6262
local w2r = {}
6363

64-
local function clean_tags(tags)
65-
tags.odbl = nil
66-
tags.created_by = nil
67-
tags.source = nil
68-
tags['source:ref'] = nil
69-
70-
return next(tags) == nil
71-
end
72-
7364
local function unique_array(array)
7465
local result = {}
7566

@@ -128,8 +119,6 @@ function osm2pgsql.process_way(object)
128119
return
129120
end
130121

131-
clean_tags(object.tags)
132-
133122
-- Data we will store in the 'lines' table always has the tags from
134123
-- the way
135124
local row = {

flex-config/route-relations.lua

+3-14
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
local tables = {}
1313

1414
tables.highways = osm2pgsql.define_way_table('highways', {
15-
{ column = 'tags', type = 'jsonb' },
15+
{ column = 'tags', type = 'jsonb' },
1616
{ column = 'rel_refs', type = 'text' }, -- for the refs from the relations
17-
{ column = 'rel_ids', sql_type = 'int8[]' }, -- array with integers (for relation IDs)
18-
{ column = 'geom', type = 'linestring', not_null = true },
17+
{ column = 'rel_ids', sql_type = 'int8[]' }, -- array with integers (for relation IDs)
18+
{ column = 'geom', type = 'linestring', not_null = true },
1919
})
2020

2121
-- Tables don't have to have a geometry column
@@ -31,23 +31,12 @@ tables.routes = osm2pgsql.define_relation_table('routes', {
3131
-- it can be called any number of times and will lead to the same result.
3232
local w2r = {}
3333

34-
local function clean_tags(tags)
35-
tags.odbl = nil
36-
tags.created_by = nil
37-
tags.source = nil
38-
tags['source:ref'] = nil
39-
40-
return next(tags) == nil
41-
end
42-
4334
function osm2pgsql.process_way(object)
4435
-- We are only interested in highways
4536
if not object.tags.highway then
4637
return
4738
end
4839

49-
clean_tags(object.tags)
50-
5140
-- Data we will store in the "highways" table always has the tags from
5241
-- the way
5342
local row = {

flex-config/simple.lua

+7-27
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,23 @@ local tables = {}
2222
-- ids.
2323
tables.pois = osm2pgsql.define_node_table('pois', {
2424
{ column = 'tags', type = 'jsonb' },
25-
{ column = 'geom', type = 'point', not_null = true }, -- will be something like `GEOMETRY(Point, 4326)` in SQL
25+
-- In most cases we'll need a column for the geometry. The default
26+
-- projection is Web Mercator (3857), so this will result in an SQL
27+
-- type `geometry(Point, 3857)`.
28+
{ column = 'geom', type = 'point', not_null = true },
2629
})
2730

2831
-- A special table for restaurants to demonstrate that we can have any tables
2932
-- with any columns we want.
3033
tables.restaurants = osm2pgsql.define_node_table('restaurants', {
31-
{ column = 'name', type = 'text' },
34+
{ column = 'name', type = 'text' },
3235
{ column = 'cuisine', type = 'text' },
3336
-- We declare all geometry columns as "NOT NULL". If osm2pgsql encounters
3437
-- an invalid geometry (for whatever reason) it will generate a null
3538
-- geometry which will not be written to the database if "not_null" is
3639
-- set. The result is that broken geometries will just be silently
3740
-- ignored.
38-
{ column = 'geom', type = 'point', not_null = true },
41+
{ column = 'geom', type = 'point', not_null = true },
3942
})
4043

4144
-- This is a "way table", it can only contain data derived from ways and will
@@ -65,29 +68,14 @@ for name, dtable in pairs(tables) do
6568
print(" name='" .. dtable:name() .. "'")
6669
end
6770

68-
-- Helper function to remove some of the tags we usually are not interested in.
69-
-- Returns true if there are no tags left.
70-
local function clean_tags(tags)
71-
tags.odbl = nil
72-
tags.created_by = nil
73-
tags.source = nil
74-
tags['source:ref'] = nil
75-
76-
return next(tags) == nil
77-
end
78-
7971
-- Called for every node in the input. The `object` argument contains all the
8072
-- attributes of the node like `id`, `version`, etc. as well as all tags as a
8173
-- Lua table (`object.tags`).
8274
function osm2pgsql.process_node(object)
83-
if clean_tags(object.tags) then
84-
return
85-
end
86-
8775
if object.tags.amenity == 'restaurant' then
8876
-- Add a row to the SQL table. The keys in the parameter table
8977
-- correspond to the table columns, if one is missing the column will
90-
-- be NULL. Id and geometry columns will be filled automatically.
78+
-- be NULL. The id column will be filled automatically.
9179
tables.restaurants:insert({
9280
name = object.tags.name,
9381
cuisine = object.tags.cuisine,
@@ -107,10 +95,6 @@ end
10795
-- information as with nodes and additionally a boolean `is_closed` flag and
10896
-- the list of node IDs referenced by the way (`object.nodes`).
10997
function osm2pgsql.process_way(object)
110-
if clean_tags(object.tags) then
111-
return
112-
end
113-
11498
-- Very simple check to decide whether a way is a polygon or not, in a
11599
-- real stylesheet we'd have to also look at the tags...
116100
if object.is_closed then
@@ -131,10 +115,6 @@ end
131115
-- same information as with nodes and additionally an array of members
132116
-- (`object.members`).
133117
function osm2pgsql.process_relation(object)
134-
if clean_tags(object.tags) then
135-
return
136-
end
137-
138118
-- Store multipolygons and boundaries as polygons
139119
if object.tags.type == 'multipolygon' or
140120
object.tags.type == 'boundary' then

flex-config/unitable.lua

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
-- OSM nodes are converted to Points, ways to LineStrings and relations
77
-- to GeometryCollections. If an object would create an invalid geometry
88
-- it is still added to the table with a NULL geometry.
9-
-- XXX expire will currently not work on these tables.
109
local dtable = osm2pgsql.define_table{
1110
name = "data",
1211
-- This will generate a column "osm_id INT8" for the id, and a column

flex-config/untagged.lua

-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,3 @@ end
4141
osm2pgsql.process_way = do_way
4242
osm2pgsql.process_untagged_way = do_way
4343

44-

0 commit comments

Comments
 (0)