Skip to content
Open
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
22 changes: 8 additions & 14 deletions flex-config/attributes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ tables.nodes = osm2pgsql.define_node_table('nodes', {
{ column = 'geom', type = 'point', projection = srid },
{ column = 'version', type = 'int' },
{ column = 'changeset', type = 'int' },
-- There is no built-in type for timestamps in osm2pgsql. So we use the
-- PostgreSQL type "timestamp" and then have to convert our timestamps
-- to a valid text representation for that type.
-- The timestamp of the object is available as a number (seconds since
-- the epoch), osm2pgsql converts it for the "timestamp" column type.
--
-- Timestamps in OSM are always in UTC, depending on your use case you
-- might want to store them using "timestamptz" instead.
-- See https://github.com/openstreetmap/osm2pgsql/issues/1785
{ column = 'created', sql_type = 'timestamp' },
{ column = 'created', type = 'timestamp' },
{ column = 'uid', type = 'int' },
{ column = 'user', type = 'text' },
})
Expand All @@ -32,7 +30,7 @@ tables.ways = osm2pgsql.define_way_table('ways', {
{ column = 'geom', type = 'linestring', projection = srid },
{ column = 'version', type = 'int' },
{ column = 'changeset', type = 'int' },
{ column = 'created', sql_type = 'timestamp' },
{ column = 'created', type = 'timestamp' },
{ column = 'uid', type = 'int' },
{ column = 'user', type = 'text' },
{ column = 'nodes', type = 'text', sql_type = 'bigint[]' },
Expand All @@ -42,16 +40,12 @@ tables.relations = osm2pgsql.define_relation_table('relations', {
{ column = 'tags', type = 'jsonb' },
{ column = 'version', type = 'int' },
{ column = 'changeset', type = 'int' },
{ column = 'created', sql_type = 'timestamp' },
{ column = 'created', type = 'timestamp' },
{ column = 'uid', type = 'int' },
{ column = 'user', type = 'text' },
{ column = 'members', type = 'jsonb' },
})

local 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
Expand All @@ -62,7 +56,7 @@ function osm2pgsql.process_node(object)
geom = object:as_point(),
version = object.version,
changeset = object.changeset,
created = format_date(object.timestamp),
created = object.timestamp,
uid = object.uid,
user = object.user
})
Expand All @@ -74,7 +68,7 @@ function osm2pgsql.process_way(object)
geom = object:as_linestring(),
version = object.version,
changeset = object.changeset,
created = format_date(object.timestamp),
created = object.timestamp,
uid = object.uid,
user = object.user,
nodes = '{' .. table.concat(object.nodes, ',') .. '}'
Expand All @@ -86,7 +80,7 @@ function osm2pgsql.process_relation(object)
tags = object.tags,
version = object.version,
changeset = object.changeset,
created = format_date(object.timestamp),
created = object.timestamp,
uid = object.uid,
user = object.user,
members = object.members
Expand Down
10 changes: 3 additions & 7 deletions flex-config/track-changes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ local change_table = osm2pgsql.define_table{
-- 'M' for modified,
-- 'D' for deleted
{ column = 'action', type = 'text' },
{ column = 'date', sql_type = 'timestamp' }
{ column = 'date', type = 'timestamp' }
},
indexes = {
{ column = { 'osm_type', 'osm_id' }, method = 'btree' }
Expand All @@ -31,10 +31,6 @@ local change_table = osm2pgsql.define_table{
-- being processed.
local file_reading_in_progress = true

local function format_date(ts)
return os.date('!%Y-%m-%dT%H:%M:%SZ', ts)
end

local function add_object_change(object)
-- In this example only changes while updating the database are recorded.
-- This happens in 'append' mode.
Expand All @@ -44,7 +40,7 @@ local function add_object_change(object)
osm_id = object.id,
version = object.version,
action = (object.version == 1) and 'A' or 'M',
date = format_date(object.timestamp)
date = object.timestamp
}
end
end
Expand All @@ -64,7 +60,7 @@ local function add_deleted_object(object)
osm_id = object.id,
version = object.version,
action = 'D',
date = format_date(object.timestamp)
date = object.timestamp
}
end

Expand Down
Loading