Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flex config #1496

Merged
merged 3 commits into from
May 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions flex-config/attributes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local srid = 4326
local tables = {}

tables.points = osm2pgsql.define_node_table('points', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'point', projection = srid },
{ column = 'version', type = 'int' },
{ column = 'changeset', type = 'int' },
Expand All @@ -21,7 +21,7 @@ tables.points = osm2pgsql.define_node_table('points', {
})

tables.lines = osm2pgsql.define_way_table('lines', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'linestring', projection = srid },
{ column = 'version', type = 'int' },
{ column = 'changeset', type = 'int' },
Expand All @@ -31,7 +31,7 @@ tables.lines = osm2pgsql.define_way_table('lines', {
})

tables.relations = osm2pgsql.define_relation_table('relations', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'version', type = 'int' },
{ column = 'changeset', type = 'int' },
{ column = 'created', type = 'timestamp' },
Expand All @@ -48,7 +48,7 @@ function osm2pgsql.process_node(object)
tags = object.tags,
version = object.version,
changeset = object.changeset,
created = os.date('!%Y-%m-%dT%TZ', object.timestamp),
created = os.date('!%Y-%m-%dT%H:%M:%SZ', object.timestamp),
uid = object.uid,
user = object.user
})
Expand All @@ -59,7 +59,7 @@ function osm2pgsql.process_way(object)
tags = object.tags,
version = object.version,
changeset = object.changeset,
created = os.date('!%Y-%m-%dT%TZ', object.timestamp),
created = os.date('!%Y-%m-%dT%H:%M:%SZ', object.timestamp),
uid = object.uid,
user = object.user
})
Expand All @@ -70,7 +70,7 @@ function osm2pgsql.process_relation(object)
tags = object.tags,
version = object.version,
changeset = object.changeset,
created = os.date('!%Y-%m-%dT%TZ', object.timestamp),
created = os.date('!%Y-%m-%dT%H:%M:%SZ', object.timestamp),
uid = object.uid,
user = object.user
})
Expand Down
4 changes: 2 additions & 2 deletions flex-config/data-types.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- This config example file is released into the Public Domain.

-- This is a very simple Lua config for the Flex Backend not intended for
-- This is a very simple Lua config for the Flex output not intended for
-- real-world use. Look at and understand "simple.lua" first, before looking
-- at this file. This file demonstrates some column data type options.

Expand All @@ -19,7 +19,7 @@ local highways = osm2pgsql.define_way_table('highways', {

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

-- an PostgreSQL array type, not specially handled by osm2pgsql, see below
{ column = 'nodes', type = 'int8[]' },
Expand Down
12 changes: 6 additions & 6 deletions flex-config/generic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@

-- This is a generic configuration that is a good starting point for
-- real-world projects. Data is split into tables according to geometry type
-- and most tags are stored in hstore columns.
-- and most tags are stored in jsonb columns.

-- Set this to the projection you want to use
local srid = 3857

local tables = {}

tables.points = osm2pgsql.define_node_table('points', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'point', projection = srid },
})

tables.lines = osm2pgsql.define_way_table('lines', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'linestring', projection = srid },
})

tables.polygons = osm2pgsql.define_area_table('polygons', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'geometry', projection = srid },
{ column = 'area', type = 'area' },
})

tables.routes = osm2pgsql.define_relation_table('routes', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'multilinestring', projection = srid },
})

tables.boundaries = osm2pgsql.define_relation_table('boundaries', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'multilinestring', projection = srid },
})

Expand Down
10 changes: 5 additions & 5 deletions flex-config/geometries.lua
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
-- This config example file is released into the Public Domain.

-- This is a very simple Lua config for the Flex Backend not intended for
-- This is a very simple Lua config for the Flex output not intended for
-- real-world use. Look at and understand "simple.lua" first, before looking
-- at this file. This file will show some options around geometry processing.
-- After you have understood this file, go on to "data-types.lua".

local tables = {}

tables.pois = osm2pgsql.define_node_table('pois', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
-- Create a geometry column for point geometries. The geometry will be
-- in web mercator, EPSG 3857.
{ column = 'geom', type = 'point' },
})

tables.ways = osm2pgsql.define_way_table('ways', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
-- Create a geometry column for linestring geometries. The geometry will
-- be in latlong (WGS84), EPSG 4326.
{ column = 'geom', type = 'linestring', projection = 4326 },
})

tables.polygons = osm2pgsql.define_area_table('polygons', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'geometry' },
-- The 'area' type is used to store the calculated area of a polygon
-- feature. This can be used in style sheets to only render larger polygons
Expand All @@ -34,7 +34,7 @@ tables.polygons = osm2pgsql.define_area_table('polygons', {

tables.boundaries = osm2pgsql.define_relation_table('boundaries', {
{ column = 'type', type = 'text' },
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
-- Boundaries will be stitched together from relation members into long
-- linestrings. This is a multilinestring column because sometimes the
-- boundaries are not contiguous.
Expand Down
4 changes: 2 additions & 2 deletions flex-config/route-relations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
local tables = {}

tables.highways = osm2pgsql.define_way_table('highways', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'rel_refs', type = 'text' }, -- for the refs from the relations
{ column = 'rel_ids', type = 'int8[]' }, -- array with integers (for relation IDs)
{ column = 'geom', type = 'linestring' },
})

-- Tables don't have to have a geometry column
tables.routes = osm2pgsql.define_relation_table('routes', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
})

-- This will be used to store information about relations queryable by member
Expand Down
10 changes: 5 additions & 5 deletions flex-config/simple.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- This config example file is released into the Public Domain.

-- This is a very simple Lua config for the Flex Backend not intended for
-- This is a very simple Lua config for the Flex output not intended for
-- real-world use. Use it do understand the basic principles of the
-- configuration. After reading and understanding this, have a look at
-- "geometries.lua".
Expand All @@ -24,7 +24,7 @@ local tables = {}
-- "append" mode, osm2pgsql will automatically update this table using the node
-- ids.
tables.pois = osm2pgsql.define_node_table('pois', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'point' }, -- will be something like `GEOMETRY(Point, 4326)` in SQL
})

Expand All @@ -40,7 +40,7 @@ tables.restaurants = osm2pgsql.define_node_table('restaurants', {
-- contain a "way_id" column. When running in "append" mode, osm2pgsql will
-- automatically update this table using the way ids.
tables.ways = osm2pgsql.define_way_table('ways', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'linestring' },
})

Expand All @@ -50,7 +50,7 @@ tables.ways = osm2pgsql.define_way_table('ways', {
-- running in "append" mode, osm2pgsql will automatically update this table
-- using the way/relation ids.
tables.polygons = osm2pgsql.define_area_table('polygons', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
-- The type of the `geom` column is `geometry`, because we need to store
-- polygons AND multipolygons
{ column = 'geom', type = 'geometry' },
Expand Down Expand Up @@ -95,7 +95,7 @@ function osm2pgsql.process_node(object)
})
else
tables.pois:add_row({
-- We know `tags` is of type `hstore` so this will do the
-- We know `tags` is of type `jsonb` so this will do the
-- right thing.
tags = object.tags
})
Expand Down
4 changes: 2 additions & 2 deletions flex-config/unitable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ local dtable = osm2pgsql.define_table{
-- "osm_type CHAR(1)" for the type of object: N(ode), W(way), R(relation)
ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' },
columns = {
{ column = 'attrs', type = 'hstore' },
{ column = 'tags', type = 'hstore' },
{ column = 'attrs', type = 'jsonb' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'geometry' },
}
}
Expand Down
5 changes: 4 additions & 1 deletion flex-config/with-schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

-- This configuration for the flex output shows how to define a table in
-- a PostgreSQL schema.
--
-- This config file expects that you have a schema called `myschema` in
-- your database (created with something like `CREATE SCHEMA myschema;`).

local dtable = osm2pgsql.define_way_table('data', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'geometry' },
}, { schema = 'myschema' })

Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ if (HAVE_LUA)
set_test(test-output-flex-way-relation-del)

set_test(test-output-flex-example-configs)
set(FLEX_EXAMPLE_CONFIGS "compatible,data-types,generic,geometries,route-relations,simple,unitable")
# places.lua not tested because it needs dkjson package
set(FLEX_EXAMPLE_CONFIGS "attributes,compatible,data-types,generic,geometries,places,route-relations,simple,unitable")
# with-schema.lua is not tested because it needs the schema created in the database
set_tests_properties(test-output-flex-example-configs PROPERTIES ENVIRONMENT "EXAMPLE_FILES=${FLEX_EXAMPLE_CONFIGS}")
endif()

Expand Down