From b4312816f447be74e085a2ab469d62ac1466fa1c Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Tue, 29 Jul 2025 21:55:39 +0200 Subject: [PATCH] Fix bbox calculation for relation with node members The old code is some left-over from before that was not working any more. --- src/output-flex.cpp | 6 +++--- tests/bdd/flex/bbox.feature | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/output-flex.cpp b/src/output-flex.cpp index 31980384c..4c9e052c7 100644 --- a/src/output-flex.cpp +++ b/src/output-flex.cpp @@ -430,9 +430,9 @@ int output_flex_t::app_get_bbox() osmium::Box bbox; // Bounding boxes of all the member nodes - for (auto const &wnl : - m_relation_cache.members_buffer().select()) { - bbox.extend(wnl.envelope()); + for (auto const &node : + m_relation_cache.members_buffer().select()) { + bbox.extend(node.location()); } // Bounding boxes of all the member ways diff --git a/tests/bdd/flex/bbox.feature b/tests/bdd/flex/bbox.feature index da1e606c2..6daadbd9e 100644 --- a/tests/bdd/flex/bbox.feature +++ b/tests/bdd/flex/bbox.feature @@ -77,7 +77,7 @@ Feature: Test get_bbox() function | 4326 | 20 10.1,20.1 10.1,20.1 10 | | 3857 | 2226389.8 1130195.4,2237521.8 1130195.4,2237521.8 1118890.0 | - Scenario Outline: for relations + Scenario Outline: for relations with way members only Given the 0.1 grid with origin 20.0 10.1 | 10 | 11 | | | 12 | @@ -124,3 +124,37 @@ Feature: Test get_bbox() function | 4326 | 10, 11 | 10, 11, 12 | | 3857 | 2226389.8 1130195.4,2237521.8 1130195.4 | 2226389.8 1130195.4,2237521.8 1130195.4,2237521.8 1118890.0 | + Scenario: for relations with node and way members + Given the 0.1 grid with origin 20.0 10.1 + | 10 | 11 | | + | | 12 | 13 | + | 14 | | | + And the OSM data + """ + w20 v1 dV Nn10,n11 + w21 v1 dV Nn11,n12 + r30 v1 dV Ttype=route,route=bus Mw20@,w21@,n13@,n14@ + """ + And the lua style + """ + local rels = osm2pgsql.define_relation_table('osm2pgsql_test_routes', { + { column = 'min_x', type = 'real' }, + { column = 'min_y', type = 'real' }, + { column = 'max_x', type = 'real' }, + { column = 'max_y', type = 'real' }, + { column = 'geom', type = 'geometry', projection = 4326, not_null = true }, + }) + + function osm2pgsql.process_relation(object) + local row = {} + row.min_x, row.min_y, row.max_x, row.max_y = object:get_bbox() + row.geom = object:as_geometrycollection() + rels:insert(row) + end + """ + When running osm2pgsql flex + + Then table osm2pgsql_test_routes contains exactly + | relation_id | min_x | max_x | min_y | max_y | + | 30 | 20.0 | 20.2 | 9.9 | 10.1 | +