Skip to content

Commit 0430707

Browse files
committed
Make n_points function for geometries available in Lua
1 parent f0aac2b commit 0430707

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/flex-lua-geom.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ int geom_centroid(lua_State *lua_state)
114114
return 1;
115115
}
116116

117+
int geom_n_points(lua_State *lua_state)
118+
{
119+
auto const *const input_geometry = unpack_geometry(lua_state);
120+
121+
try {
122+
lua_pushinteger(lua_state, input_geometry->n_points());
123+
} catch (...) {
124+
return luaL_error(lua_state, "Unknown error in 'n_points()'.\n");
125+
}
126+
127+
return 1;
128+
}
129+
117130
int geom_geometry_n(lua_State *lua_state)
118131
{
119132
auto const *const input_geometry = unpack_geometry(lua_state);
@@ -313,6 +326,7 @@ void init_geometry_class(lua_State *lua_state)
313326
{"geometry_type", geom_geometry_type},
314327
{"is_null", geom_is_null},
315328
{"line_merge", geom_line_merge},
329+
{"n_points", geom_n_points},
316330
{"reverse", geom_reverse},
317331
{"num_geometries", geom_num_geometries},
318332
{"pole_of_inaccessibility", geom_pole_of_inaccessibility},

tests/bdd/flex/geometry-linestring.feature

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ Feature: Creating linestring features from way
1616
{ column = 'sgeom', type = 'linestring', projection = 4326 },
1717
{ column = 'mgeom', type = 'multilinestring', projection = 4326 },
1818
{ column = 'xgeom', type = 'multilinestring', projection = 4326 },
19+
{ column = 'npoints', type = 'int' },
1920
})
2021
2122
function osm2pgsql.process_way(object)
2223
if object.tags.highway == 'motorway' then
2324
lines:insert({
2425
sgeom = object:as_linestring(),
2526
mgeom = object:as_multilinestring(),
26-
xgeom = object:as_linestring()
27+
xgeom = object:as_linestring(),
28+
npoints = object:as_linestring():n_points(),
2729
})
2830
end
2931
end
@@ -32,9 +34,9 @@ Feature: Creating linestring features from way
3234
When running osm2pgsql flex
3335

3436
Then table osm2pgsql_test_lines contains exactly
35-
| way_id | sgeom!geo | mgeom!geo | xgeom!geo |
36-
| 20 | 1, 2, 3 | [ 1, 2, 3 ] | [ 1, 2, 3 ] |
37-
| 21 | 4, 5 | [ 4, 5 ] | [ 4, 5 ] |
37+
| way_id | sgeom!geo | mgeom!geo | xgeom!geo | npoints |
38+
| 20 | 1, 2, 3 | [ 1, 2, 3 ] | [ 1, 2, 3 ] | 3 |
39+
| 21 | 4, 5 | [ 4, 5 ] | [ 4, 5 ] | 2 |
3840

3941
Scenario:
4042
Given the grid

0 commit comments

Comments
 (0)