Skip to content

Commit 748fc0a

Browse files
committed
Fix: Create point geometry from collection with single-node way
If a geometry collection is created from a relation, any way member will normally end up as linestring relation. But if there is only a single point in the resulting linestring (because the way only contained a single node or multiple nodes with the same position), that linestring would be invalid. In this case create a point geometry instead.
1 parent 8f7ac96 commit 748fc0a

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

src/geom-from-osm.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ void create_collection(geometry_t *geom,
202202
if (line.size() >= 2U) {
203203
collection.add_geometry(std::move(item));
204204
}
205+
if (line.size() == 1) {
206+
collection.add_geometry(geometry_t{std::move(line[0])});
207+
}
205208
}
206209
}
207210

tests/bdd/flex/geometry-collection.feature

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,33 @@ Feature: Create geometry collections from relations
5454
| 10 |
5555
And the OSM data
5656
"""
57-
w20 Nn10
57+
w20 Nn11
5858
r30 Tname=foo Mn11@
5959
r31 Tname=bar Mw20@
6060
r32 Tname=baz Mw21@
6161
"""
6262
When running osm2pgsql flex
6363

6464
Then table osm2pgsql_test_collection contains exactly
65-
| osm_id | name | ST_GeometryType(geom) |
66-
| 30 | foo | NULL |
67-
| 31 | bar | NULL |
68-
| 32 | baz | NULL |
65+
| osm_id | name | geom |
66+
| 30 | foo | NULL |
67+
| 31 | bar | NULL |
68+
| 32 | baz | NULL |
69+
70+
Scenario: Point entry generated for broken way lines
71+
Given the grid
72+
| 10 |
73+
And the OSM data
74+
"""
75+
w20 Nn10
76+
w21 Nn10,n10
77+
r30 Tname=w20 Mw20@
78+
r31 Tname=w21 Mw21@
79+
"""
80+
When running osm2pgsql flex
81+
82+
Then table osm2pgsql_test_collection contains exactly
83+
| osm_id | name | ST_NumGeometries(geom) | ST_AsText(ST_GeometryN(geom, 1)) |
84+
| 30 | w20 | 1 | 10 |
85+
| 31 | w21 | 1 | 10 |
6986

tests/test-geom-collections.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,17 @@ TEST_CASE("create_collection from no OSM data returns null geometry", "[NoDB]")
8181
REQUIRE(geometry_type(geom) == "NULL");
8282
REQUIRE(num_geometries(geom) == 0);
8383
}
84+
85+
TEST_CASE("create_collection from OSM data with single-node way", "[NoDB]")
86+
{
87+
test_buffer_t buffer;
88+
buffer.add_way("w20 Nn1x1y1");
89+
90+
auto const geom = geom::create_collection(buffer.buffer());
91+
92+
REQUIRE(geometry_type(geom) == "GEOMETRYCOLLECTION");
93+
REQUIRE(num_geometries(geom) == 1);
94+
95+
auto const &c = geom.get<geom::collection_t>();
96+
REQUIRE(c[0] == geom::geometry_t{geom::point_t{1, 1}});
97+
}

0 commit comments

Comments
 (0)