Skip to content

Commit 33fb1c8

Browse files
committed
Cleanup and extend flex invalid geometry test
1 parent 44b1201 commit 33fb1c8

File tree

2 files changed

+78
-33
lines changed

2 files changed

+78
-33
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
local tables = {}
3+
4+
tables.line = osm2pgsql.define_table{
5+
name = 'osm2pgsql_test_line',
6+
ids = { type = 'way', id_column = 'osm_id' },
7+
columns = {
8+
{ column = 'tags', type = 'hstore' },
9+
{ column = 'geom', type = 'linestring' },
10+
}
11+
}
12+
13+
tables.polygon = osm2pgsql.define_table{
14+
name = 'osm2pgsql_test_polygon',
15+
ids = { type = 'area', id_column = 'osm_id' },
16+
columns = {
17+
{ column = 'tags', type = 'hstore' },
18+
{ column = 'geom', type = 'geometry' }
19+
}
20+
}
21+
22+
function osm2pgsql.process_way(object)
23+
if not next(object.tags) then
24+
return
25+
end
26+
27+
if object.tags.natural then
28+
tables.polygon:add_row({
29+
tags = object.tags,
30+
geom = { create = 'area' }
31+
})
32+
else
33+
tables.line:add_row({
34+
tags = object.tags
35+
})
36+
end
37+
end
38+
39+
function osm2pgsql.process_relation(object)
40+
tables.polygon:add_row({
41+
tags = object.tags,
42+
geom = { create = 'area', multi = false }
43+
})
44+
end
45+

tests/test-output-flex-invalid-geom.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,75 @@
55

66
static testing::db::import_t db;
77

8+
static char const *const conf_file = "test_output_flex_invalid_geom.lua";
9+
810
TEST_CASE("invalid way geometry should be ignored")
911
{
10-
testing::opt_t options =
11-
testing::opt_t().slim().flex("test_output_flex.lua").srs(PROJ_LATLONG);
12-
13-
REQUIRE_NOTHROW(
14-
db.run_import(options,
15-
"n10 v1 dV x10.0 y10.0\n"
16-
"n11 v1 dV x10.0 y10.2\n"
17-
"n12 v1 dV x10.2 y10.2\n"
18-
"w20 v1 dV Thighway=primary Nn10,n12\n" // okay
19-
"w21 v1 dV Thighway=primary Nn10,n13\n")); // not okay
12+
options_t const options =
13+
testing::opt_t().flex(conf_file).srs(PROJ_LATLONG);
14+
15+
REQUIRE_NOTHROW(db.run_import(
16+
options,
17+
"n10 v1 dV x10.0 y10.0\n"
18+
"n11 v1 dV x10.0 y10.2\n"
19+
"n12 v1 dV x10.2 y10.2\n"
20+
"n14 v1 dV x10.0 y10.0\n"
21+
"w20 v1 dV Thighway=primary Nn10,n12\n" // okay
22+
"w21 v1 dV Thighway=primary Nn10,n12,n13\n" // okay, unknown node ignored
23+
"w22 v1 dV Thighway=primary Nn10,n13\n" // not okay, unknown node leads to single-node line
24+
"w23 v1 dV Thighway=primary Nn10\n" // not okay, single node in way
25+
"w24 v1 dV Thighway=primary Nn10,n10\n" // not okay, same node twice
26+
"w25 v1 dV Thighway=primary Nn10,n14\n")); // not okay, same location twice
27+
2028
auto conn = db.db().connect();
2129

22-
CHECK(0 == conn.get_count("osm2pgsql_test_point"));
23-
CHECK(1 == conn.get_count("osm2pgsql_test_line"));
30+
CHECK(2 == conn.get_count("osm2pgsql_test_line"));
2431
CHECK(0 == conn.get_count("osm2pgsql_test_polygon"));
25-
CHECK(0 == conn.get_count("osm2pgsql_test_route"));
2632
}
2733

2834
TEST_CASE("invalid area geometry from way should be ignored")
2935
{
30-
testing::opt_t options =
31-
testing::opt_t().slim().flex("test_output_flex.lua").srs(PROJ_LATLONG);
36+
options_t const options =
37+
testing::opt_t().flex(conf_file).srs(PROJ_LATLONG);
3238

3339
REQUIRE_NOTHROW(db.run_import(
3440
options,
3541
"n10 v1 dV x10.0 y10.0\n"
3642
"n11 v1 dV x10.0 y10.2\n"
3743
"n12 v1 dV x10.2 y10.2\n"
38-
"w20 v1 dV Tnatural=wood Nn10,n11,n12,n10\n" // okay
39-
"w21 v1 dV Tnatural=wood Nn10,n11,n12,n13,n10\n" // okay
40-
"w22 v1 dV Tnatural=wood Nn10,n11,n12,n10,n11\n" // not okay
41-
"w23 v1 dV Tnatural=wood Nn10,n11,n12\n")); // not okay
44+
"w20 v1 dV Tnatural=wood Nn10,n11,n12,n10\n" // okay
45+
"w21 v1 dV Tnatural=wood Nn10,n11,n12,n13,n10\n" // okay, unknown node ignored
46+
"w22 v1 dV Tnatural=wood Nn10,n11,n12,n10,n11\n" // not okay, duplicate segment
47+
"w23 v1 dV Tnatural=wood Nn10,n11,n12\n")); // not okay, ring not closed
4248

4349
auto conn = db.db().connect();
4450

45-
CHECK(0 == conn.get_count("osm2pgsql_test_point"));
4651
CHECK(0 == conn.get_count("osm2pgsql_test_line"));
4752
CHECK(2 == conn.get_count("osm2pgsql_test_polygon"));
48-
CHECK(0 == conn.get_count("osm2pgsql_test_route"));
4953
}
5054

51-
TEST_CASE("invalid area geometry from way should be ignored 2")
55+
TEST_CASE("area with self-intersection from way should be ignored")
5256
{
53-
testing::opt_t options =
54-
testing::opt_t().slim().flex("test_output_flex.lua").srs(PROJ_LATLONG);
57+
options_t const options =
58+
testing::opt_t().flex(conf_file).srs(PROJ_LATLONG);
5559

5660
REQUIRE_NOTHROW(db.run_import(
5761
options, "n10 v1 dV x1.70 y1.78\n"
5862
"n11 v1 dV x1.87 y1.68\n"
5963
"n12 v1 dV x1.84 y1.84\n"
6064
"n13 v1 dV x1.82 y1.67\n"
61-
"w20 v1 dV Tamenity=parking Nn10,n11,n12,n13,n10\n"));
65+
"w20 v1 dV Tnatural=wood Nn10,n11,n12,n13,n10\n"));
6266

6367
auto conn = db.db().connect();
6468

65-
CHECK(0 == conn.get_count("osm2pgsql_test_point"));
6669
CHECK(0 == conn.get_count("osm2pgsql_test_line"));
6770
CHECK(0 == conn.get_count("osm2pgsql_test_polygon"));
68-
CHECK(0 == conn.get_count("osm2pgsql_test_route"));
6971
}
7072

7173
TEST_CASE("invalid area geometry from relation should be ignored")
7274
{
73-
testing::opt_t options =
74-
testing::opt_t().slim().flex("test_output_flex.lua").srs(PROJ_LATLONG);
75+
options_t const options =
76+
testing::opt_t().flex(conf_file).srs(PROJ_LATLONG);
7577

7678
REQUIRE_NOTHROW(db.run_import(options,
7779
"n10 v1 dV x10.0 y10.0\n"
@@ -83,14 +85,12 @@ TEST_CASE("invalid area geometry from relation should be ignored")
8385
"r30 v1 dV Ttype=multipolygon,landuse=forest "
8486
"Mw20@,w21@\n" // okay
8587
"r31 v1 dV Ttype=multipolygon,landuse=forest "
86-
"Mw20@\n" // not okay
88+
"Mw20@\n" // not okay, ring not closed
8789
"r32 v1 dV Ttype=multipolygon,landuse=forest "
88-
"Mw20@,w22@\n")); // not okay
90+
"Mw20@,w22@\n")); // not okay, missing way
8991

9092
auto conn = db.db().connect();
9193

92-
CHECK(0 == conn.get_count("osm2pgsql_test_point"));
9394
CHECK(0 == conn.get_count("osm2pgsql_test_line"));
9495
CHECK(1 == conn.get_count("osm2pgsql_test_polygon"));
95-
CHECK(0 == conn.get_count("osm2pgsql_test_route"));
9696
}

0 commit comments

Comments
 (0)