diff --git a/flex-config/attributes.lua b/flex-config/attributes.lua index 64ed27c53..0acecf085 100644 --- a/flex-config/attributes.lua +++ b/flex-config/attributes.lua @@ -3,14 +3,15 @@ -- This config shows how to access the attributes of OSM objects: the version, -- changeset id, timestamp, user id and user name. For this to work the -- command line option --extra-attributes/-x must be set, otherwise those --- fields will be empty. +-- fields will be empty. Also note that some OSM files do not contain all +-- of those attributes, so check your input data if you get empty fields. -- Set this to the projection you want to use local srid = 4326 local tables = {} -tables.points = osm2pgsql.define_node_table('points', { +tables.nodes = osm2pgsql.define_node_table('nodes', { { column = 'tags', type = 'jsonb' }, { column = 'geom', type = 'point', projection = srid }, { column = 'version', type = 'int' }, @@ -23,7 +24,7 @@ tables.points = osm2pgsql.define_node_table('points', { { column = 'user', type = 'text' }, }) -tables.lines = osm2pgsql.define_way_table('lines', { +tables.ways = osm2pgsql.define_way_table('ways', { { column = 'tags', type = 'jsonb' }, { column = 'geom', type = 'linestring', projection = srid }, { column = 'version', type = 'int' }, @@ -31,6 +32,7 @@ tables.lines = osm2pgsql.define_way_table('lines', { { column = 'created', sql_type = 'timestamp' }, { column = 'uid', type = 'int' }, { column = 'user', type = 'text' }, + { column = 'nodes', type = 'text', sql_type = 'bigint[]' }, }) tables.relations = osm2pgsql.define_relation_table('relations', { @@ -40,42 +42,51 @@ tables.relations = osm2pgsql.define_relation_table('relations', { { column = 'created', sql_type = 'timestamp' }, { column = 'uid', type = 'int' }, { column = 'user', type = 'text' }, + { column = 'members', type = 'jsonb' }, }) +function format_date(ts) + return os.date('!%Y-%m-%dT%H:%M:%SZ', ts) +end + function osm2pgsql.process_node(object) if next(object.tags) == nil then return end - tables.points:add_row({ + tables.nodes:insert({ tags = object.tags, + geom = object:as_point(), version = object.version, changeset = object.changeset, - created = os.date('!%Y-%m-%dT%H:%M:%SZ', object.timestamp), + created = format_date(object.timestamp), uid = object.uid, user = object.user }) end function osm2pgsql.process_way(object) - tables.lines:add_row({ + tables.ways:insert({ tags = object.tags, + geom = object:as_linestring(), version = object.version, changeset = object.changeset, - created = os.date('!%Y-%m-%dT%H:%M:%SZ', object.timestamp), + created = format_date(object.timestamp), uid = object.uid, - user = object.user + user = object.user, + nodes = '{' .. table.concat(object.nodes, ',') .. '}' }) end function osm2pgsql.process_relation(object) - tables.relations:add_row({ + tables.relations:insert({ tags = object.tags, version = object.version, changeset = object.changeset, - created = os.date('!%Y-%m-%dT%H:%M:%SZ', object.timestamp), + created = format_date(object.timestamp), uid = object.uid, - user = object.user + user = object.user, + members = object.members }) end diff --git a/flex-config/data-types.lua b/flex-config/data-types.lua index fecf8027c..b2df74a6b 100644 --- a/flex-config/data-types.lua +++ b/flex-config/data-types.lua @@ -102,7 +102,7 @@ function osm2pgsql.process_way(object) -- We want to put the name in its own column local name = object:grab_tag('name') - highways:add_row({ + highways:insert({ name = name, type = highway_type, @@ -122,7 +122,8 @@ function osm2pgsql.process_way(object) -- for a column of type "int8[]". nodes = '{' .. table.concat(object.nodes, ',') .. '}', - tags = object.tags + tags = object.tags, + geom = object:as_linestring() }) end diff --git a/flex-config/places.lua b/flex-config/places.lua index 4f1206165..0677a2cab 100644 --- a/flex-config/places.lua +++ b/flex-config/places.lua @@ -42,8 +42,9 @@ function osm2pgsql.process_node(object) object.tags.population = tonumber(object.tags.population) end - places:add_row({ - tags = object.tags + places:insert({ + tags = object.tags, + geom = object:as_point() }) end diff --git a/flex-config/with-schema.lua b/flex-config/with-schema.lua index 851e3e8e1..9752018f5 100644 --- a/flex-config/with-schema.lua +++ b/flex-config/with-schema.lua @@ -8,13 +8,13 @@ local dtable = osm2pgsql.define_way_table('data', { { column = 'tags', type = 'jsonb' }, - { column = 'geom', type = 'geometry' }, + { column = 'geom', type = 'linestring' }, }, { schema = 'myschema' }) function osm2pgsql.process_way(object) - dtable:add_row({ + dtable:insert({ tags = object.tags, - geom = { create = 'line' } + geom = object:as_linestring() }) end