Skip to content

Commit 3eaf81b

Browse files
committed
Add line_merge to functions callable from Lua
1 parent a89afda commit 3eaf81b

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/flex-lua-geom.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ static int geom_is_null(lua_State *lua_state)
119119
return 1;
120120
}
121121

122+
static int geom_line_merge(lua_State *lua_state)
123+
{
124+
auto const *const input_geometry = unpack_geometry(lua_state);
125+
126+
try {
127+
auto *geom = create_lua_geometry_object(lua_state);
128+
geom::line_merge(geom, *input_geometry);
129+
} catch (...) {
130+
return luaL_error(lua_state, "Unknown error in 'line_merge()'.\n");
131+
}
132+
133+
return 1;
134+
}
135+
122136
static int geom_num_geometries(lua_State *lua_state)
123137
{
124138
auto const *const input_geometry = unpack_geometry(lua_state);
@@ -215,6 +229,7 @@ void init_geometry_class(lua_State *lua_state)
215229
luaX_add_table_func(lua_state, "geometry_n", geom_geometry_n);
216230
luaX_add_table_func(lua_state, "geometry_type", geom_geometry_type);
217231
luaX_add_table_func(lua_state, "is_null", geom_is_null);
232+
luaX_add_table_func(lua_state, "line_merge", geom_line_merge);
218233
luaX_add_table_func(lua_state, "num_geometries", geom_num_geometries);
219234
luaX_add_table_func(lua_state, "segmentize", geom_segmentize);
220235
luaX_add_table_func(lua_state, "simplify", geom_simplify);

tests/bdd/flex/geometry-multilinestring.feature

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,37 @@ Feature: Creating (multi)linestring features from way and relations
4747
| R | 30 | ST_LineString | 1, 2, 3 | NULL |
4848
| R | 31 | ST_MultiLineString | 1, 2, 3 | 4, 5, 6 |
4949

50+
Scenario:
51+
Given the grid
52+
| 1 | 2 | | |
53+
| | | 3 | 4 |
54+
And the OSM data
55+
"""
56+
w20 Thighway=motorway Nn1,n2
57+
w21 Thighway=motorway Nn2,n3
58+
w22 Thighway=motorway Nn3,n4
59+
r30 Ttype=route,route=road Mw20@,w21@
60+
r31 Ttype=route,route=road Mw20@,w22@
61+
"""
62+
And the lua style
63+
"""
64+
local roads = osm2pgsql.define_relation_table('osm2pgsql_test_roads', {
65+
{ column = 'geom', type = 'geometry', projection = 4326 },
66+
{ column = 'merged', type = 'geometry', projection = 4326 }
67+
})
68+
69+
function osm2pgsql.process_relation(object)
70+
local g = object:as_multilinestring()
71+
roads:insert({
72+
geom = g,
73+
merged = g:line_merge()
74+
})
75+
end
76+
"""
77+
When running osm2pgsql flex
78+
79+
Then table osm2pgsql_test_roads contains exactly
80+
| relation_id | ST_GeometryType(geom) | ST_GeometryType(merged) | ST_AsText(ST_GeometryN(merged, 1)) | ST_AsText(ST_GeometryN(merged, 2)) |
81+
| 30 | ST_MultiLineString | ST_MultiLineString | 1, 2, 3 | NULL |
82+
| 31 | ST_MultiLineString | ST_MultiLineString | 1, 2 | 3, 4 |
83+

0 commit comments

Comments
 (0)