Skip to content

Commit 2fe8f89

Browse files
committed
Add tests for linestring geometry (with and without split)
1 parent 0089df9 commit 2fe8f89

File tree

4 files changed

+62
-26
lines changed

4 files changed

+62
-26
lines changed

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ if (HAVE_LUA)
7676
set_test(test-output-flex-attr)
7777
set_test(test-output-flex-bbox)
7878
set_test(test-output-flex-invalid-geom)
79+
set_test(test-output-flex-line)
7980
set_test(test-output-flex-lua-fail)
8081
set_test(test-output-flex-nogeom)
8182
set_test(test-output-flex-uni)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
local tables = {}
3+
4+
tables.line = osm2pgsql.define_way_table('osm2pgsql_test_line', {
5+
{ column = 'tags', type = 'hstore' },
6+
{ column = 'geom', type = 'linestring' }
7+
})
8+
9+
tables.split = osm2pgsql.define_way_table('osm2pgsql_test_split', {
10+
{ column = 'tags', type = 'hstore' },
11+
{ column = 'geom', type = 'linestring' }
12+
})
13+
14+
function osm2pgsql.process_way(object)
15+
tables.line:add_row({
16+
tags= object.tags,
17+
geom = { create = 'line' }
18+
})
19+
tables.split:add_row({
20+
tags = object.tags,
21+
geom = { create = 'line', split_at = 1.0 }
22+
})
23+
end
24+

tests/test-output-flex-line.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <catch.hpp>
2+
3+
#include "common-import.hpp"
4+
#include "common-options.hpp"
5+
6+
static testing::db::import_t db;
7+
8+
static char const *const conf_file = "test_output_flex_line.lua";
9+
10+
TEST_CASE("linestring in latlon projection (unsplit and split)")
11+
{
12+
options_t const options =
13+
testing::opt_t().flex(conf_file).srs(PROJ_LATLONG);
14+
15+
REQUIRE_NOTHROW(db.run_import(options,
16+
"n10 v1 dV x1.0 y1.0\n"
17+
"n11 v1 dV x1.0 y2.0\n"
18+
"n12 v1 dV x1.0 y3.5\n"
19+
"w20 v1 dV Thighway=primary Nn10,n11\n"
20+
"w21 v1 dV Thighway=primary Nn10,n12\n"));
21+
22+
auto conn = db.db().connect();
23+
24+
REQUIRE(2 == conn.get_count("osm2pgsql_test_line"));
25+
REQUIRE(4 == conn.get_count("osm2pgsql_test_split"));
26+
REQUIRE(4 ==
27+
conn.get_count("osm2pgsql_test_split", "ST_Length(geom) <= 1.0"));
28+
29+
REQUIRE(1 == conn.get_count("osm2pgsql_test_split", "way_id=20"));
30+
REQUIRE(3 == conn.get_count("osm2pgsql_test_split", "way_id=21"));
31+
32+
REQUIRE(2 == conn.get_count("osm2pgsql_test_split",
33+
"way_id=21 AND ST_Length(geom) = 1.0"));
34+
35+
conn.assert_double(
36+
1.0, "SELECT ST_Length(geom) FROM osm2pgsql_test_line WHERE way_id=20");
37+
}

tests/test-output-flex.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,6 @@ TEST_CASE("liechtenstein slim regression simple")
2828
CHECK(2932 == conn.get_count("osm2pgsql_test_line"));
2929
CHECK(4136 == conn.get_count("osm2pgsql_test_polygon"));
3030
CHECK(35 == conn.get_count("osm2pgsql_test_route"));
31-
32-
// Check size of lines
33-
conn.assert_double(
34-
1696.04,
35-
"SELECT ST_Length(geom) FROM osm2pgsql_test_line WHERE osm_id = 1101");
36-
conn.assert_double(1151.26,
37-
"SELECT ST_Length(ST_Transform(geom,4326)::geography) "
38-
"FROM osm2pgsql_test_line WHERE osm_id = 1101");
39-
40-
// Check a point's location
41-
REQUIRE(1 == conn.get_count("osm2pgsql_test_point",
42-
"ST_DWithin(geom, 'SRID=3857;POINT(1062645.12 "
43-
"5972593.4)'::geometry, 0.1)"));
4431
}
4532

4633
TEST_CASE("liechtenstein slim latlon")
@@ -56,19 +43,6 @@ TEST_CASE("liechtenstein slim latlon")
5643
REQUIRE(1362 == conn.get_count("osm2pgsql_test_point"));
5744
REQUIRE(2932 == conn.get_count("osm2pgsql_test_line"));
5845
REQUIRE(4136 == conn.get_count("osm2pgsql_test_polygon"));
59-
60-
// Check size of lines
61-
conn.assert_double(
62-
0.0105343,
63-
"SELECT ST_Length(geom) FROM osm2pgsql_test_line WHERE osm_id = 1101");
64-
conn.assert_double(1151.26,
65-
"SELECT ST_Length(ST_Transform(geom,4326)::geography) "
66-
"FROM osm2pgsql_test_line WHERE osm_id = 1101");
67-
68-
// Check a point's location
69-
REQUIRE(1 == conn.get_count("osm2pgsql_test_point",
70-
"ST_DWithin(geom, 'SRID=4326;POINT(9.5459035 "
71-
"47.1866494)'::geometry, 0.00001)"));
7246
}
7347

7448
TEST_CASE("way area slim flatnode")

0 commit comments

Comments
 (0)