Skip to content
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
33 changes: 22 additions & 11 deletions flex-config/attributes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -23,14 +24,15 @@ 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' },
{ column = 'changeset', type = 'int' },
{ 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', {
Expand All @@ -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

5 changes: 3 additions & 2 deletions flex-config/data-types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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

5 changes: 3 additions & 2 deletions flex-config/places.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

6 changes: 3 additions & 3 deletions flex-config/with-schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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