Skip to content

Commit 3eebee3

Browse files
committed
Wrap linestrings/polygons in multi geometry if needed
1 parent 65d0d27 commit 3eebee3

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/output-flex.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,19 +672,24 @@ void output_flex_t::write_column(
672672
if (ltype == LUA_TUSERDATA) {
673673
auto const *const geom = unpack_geometry(lua_state(), -1);
674674
if (geom && !geom->is_null()) {
675+
auto const type = column.type();
676+
bool const wrap_multi =
677+
(type == table_column_type::multipoint ||
678+
type == table_column_type::multilinestring ||
679+
type == table_column_type::multipolygon);
675680
if (geom->srid() == column.srid()) {
676681
// OSM id not available here, so use dummy 0, it is used
677682
// for debug messages only anyway.
678683
m_expire.from_geometry(*geom, 0);
679-
copy_mgr->add_hex_geom(geom_to_ewkb(*geom));
684+
copy_mgr->add_hex_geom(geom_to_ewkb(*geom, wrap_multi));
680685
} else {
681686
auto const proj =
682687
reprojection::create_projection(column.srid());
683688
auto const tgeom = geom::transform(*geom, *proj);
684689
// OSM id not available here, so use dummy 0, it is used
685690
// for debug messages only anyway.
686691
m_expire.from_geometry(tgeom, 0);
687-
copy_mgr->add_hex_geom(geom_to_ewkb(tgeom));
692+
copy_mgr->add_hex_geom(geom_to_ewkb(tgeom, wrap_multi));
688693
}
689694
} else {
690695
write_null(copy_mgr, column);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Feature: Creating linestring features from way
2+
3+
Scenario:
4+
Given the grid
5+
| 1 | 2 | |
6+
| 4 | | 3 |
7+
| | 5 | |
8+
And the OSM data
9+
"""
10+
w20 Thighway=motorway Nn1,n2,n3
11+
w21 Thighway=motorway Nn4,n5
12+
"""
13+
And the lua style
14+
"""
15+
local lines = osm2pgsql.define_way_table('osm2pgsql_test_lines', {
16+
{ column = 'sgeom', type = 'linestring', projection = 4326 },
17+
{ column = 'mgeom', type = 'multilinestring', projection = 4326 },
18+
{ column = 'xgeom', type = 'multilinestring', projection = 4326 },
19+
})
20+
21+
function osm2pgsql.process_way(object)
22+
if object.tags.highway == 'motorway' then
23+
lines:insert({
24+
sgeom = object:as_linestring(),
25+
mgeom = object:as_multilinestring(),
26+
xgeom = object:as_linestring()
27+
})
28+
end
29+
end
30+
31+
"""
32+
When running osm2pgsql flex
33+
34+
Then table osm2pgsql_test_lines contains exactly
35+
| way_id | ST_AsText(sgeom) | ST_AsText(ST_GeometryN(mgeom, 1)) | ST_AsText(ST_GeometryN(xgeom, 1)) |
36+
| 20 | 1, 2, 3 | 1, 2, 3 | 1, 2, 3 |
37+
| 21 | 4, 5 | 4, 5 | 4, 5 |
38+

0 commit comments

Comments
 (0)