Skip to content

Commit b431281

Browse files
committed
Fix bbox calculation for relation with node members
The old code is some left-over from before that was not working any more.
1 parent 9ef933a commit b431281

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/output-flex.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,9 @@ int output_flex_t::app_get_bbox()
430430
osmium::Box bbox;
431431

432432
// Bounding boxes of all the member nodes
433-
for (auto const &wnl :
434-
m_relation_cache.members_buffer().select<osmium::WayNodeList>()) {
435-
bbox.extend(wnl.envelope());
433+
for (auto const &node :
434+
m_relation_cache.members_buffer().select<osmium::Node>()) {
435+
bbox.extend(node.location());
436436
}
437437

438438
// Bounding boxes of all the member ways

tests/bdd/flex/bbox.feature

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Feature: Test get_bbox() function
7777
| 4326 | 20 10.1,20.1 10.1,20.1 10 |
7878
| 3857 | 2226389.8 1130195.4,2237521.8 1130195.4,2237521.8 1118890.0 |
7979

80-
Scenario Outline: for relations
80+
Scenario Outline: for relations with way members only
8181
Given the 0.1 grid with origin 20.0 10.1
8282
| 10 | 11 |
8383
| | 12 |
@@ -124,3 +124,37 @@ Feature: Test get_bbox() function
124124
| 4326 | 10, 11 | 10, 11, 12 |
125125
| 3857 | 2226389.8 1130195.4,2237521.8 1130195.4 | 2226389.8 1130195.4,2237521.8 1130195.4,2237521.8 1118890.0 |
126126

127+
Scenario: for relations with node and way members
128+
Given the 0.1 grid with origin 20.0 10.1
129+
| 10 | 11 | |
130+
| | 12 | 13 |
131+
| 14 | | |
132+
And the OSM data
133+
"""
134+
w20 v1 dV Nn10,n11
135+
w21 v1 dV Nn11,n12
136+
r30 v1 dV Ttype=route,route=bus Mw20@,w21@,n13@,n14@
137+
"""
138+
And the lua style
139+
"""
140+
local rels = osm2pgsql.define_relation_table('osm2pgsql_test_routes', {
141+
{ column = 'min_x', type = 'real' },
142+
{ column = 'min_y', type = 'real' },
143+
{ column = 'max_x', type = 'real' },
144+
{ column = 'max_y', type = 'real' },
145+
{ column = 'geom', type = 'geometry', projection = 4326, not_null = true },
146+
})
147+
148+
function osm2pgsql.process_relation(object)
149+
local row = {}
150+
row.min_x, row.min_y, row.max_x, row.max_y = object:get_bbox()
151+
row.geom = object:as_geometrycollection()
152+
rels:insert(row)
153+
end
154+
"""
155+
When running osm2pgsql flex
156+
157+
Then table osm2pgsql_test_routes contains exactly
158+
| relation_id | min_x | max_x | min_y | max_y |
159+
| 30 | 20.0 | 20.2 | 9.9 | 10.1 |
160+

0 commit comments

Comments
 (0)