From b49fdd84a8ad2cf5e730a1da0e6cb4dbf85494a4 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sat, 24 Sep 2022 14:34:15 +0200 Subject: [PATCH 1/2] switch unitable example to insert() Also switch to geometrycollection for saving relations. This way all non-empty relations are captured. --- flex-config/unitable.lua | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/flex-config/unitable.lua b/flex-config/unitable.lua index c0a18b39c..bb4b6f622 100644 --- a/flex-config/unitable.lua +++ b/flex-config/unitable.lua @@ -31,42 +31,29 @@ function clean_tags(tags) return next(tags) == nil end -function process(object, geometry_type) +function process(object, geometry) if clean_tags(object.tags) then return end - dtable:add_row({ + dtable:insert({ attrs = { version = object.version, timestamp = object.timestamp, }, tags = object.tags, - geom = { create = geometry_type } + geom = geometry }) end function osm2pgsql.process_node(object) - process(object, 'point') + process(object, object:as_point()) end function osm2pgsql.process_way(object) - process(object, 'line') + process(object, object:as_linestring()) end function osm2pgsql.process_relation(object) - if clean_tags(object.tags) then - return - end - - if object.tags.type == 'multipolygon' or object.tags.type == 'boundary' then - dtable:add_row({ - attrs = { - version = object.version, - timestamp = object.timestamp, - }, - tags = object.tags, - geom = { create = 'area' } - }) - end + process(object, object:as_geometrycollection()) end From 163e3be639a311fc0dde1e62213361e7640f6a72 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sat, 24 Sep 2022 14:55:17 +0200 Subject: [PATCH 2/2] unitable example: explain more about how geometries are added --- flex-config/unitable.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flex-config/unitable.lua b/flex-config/unitable.lua index bb4b6f622..753f3e516 100644 --- a/flex-config/unitable.lua +++ b/flex-config/unitable.lua @@ -5,6 +5,9 @@ -- inspect = require('inspect') -- We define a single table that can take any OSM object and any geometry. +-- OSM nodes are converted to Points, ways to LineStrings and relations +-- to GeometryCollections. If an object would create an invalid geometry +-- it is still added to the table with a NULL geometry. -- XXX expire will currently not work on these tables. local dtable = osm2pgsql.define_table{ name = "data",