Skip to content

Commit 470a6a3

Browse files
committed
Disable geometry validity check in flex output for point geometries
Point geometries are always valid.
1 parent ba0f8d0 commit 470a6a3

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

src/flex-table-column.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ class flex_table_column_t
8787
(m_type <= table_column_type::multipolygon);
8888
}
8989

90+
/**
91+
* Do we need an ST_IsValid() check in the database for this geometry
92+
* column? If the SRID is 4326 the geometry validity is already assured
93+
* by libosmium, so we don't need it. And Point geometries are always
94+
* valid.
95+
*/
96+
bool needs_isvalid() const noexcept
97+
{
98+
assert(is_geometry_column());
99+
return m_srid != 4326 && m_type != table_column_type::point;
100+
}
101+
90102
std::string const &type_name() const noexcept { return m_type_name; }
91103

92104
bool not_null() const noexcept { return m_not_null; }

src/flex-table.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ void table_connection_t::start(bool append)
177177
: flex_table_t::table_type::permanent,
178178
table().full_name()));
179179

180-
if (table().has_geom_column() && table().geom_column().srid() != 4326) {
180+
if (table().has_geom_column() &&
181+
table().geom_column().needs_isvalid()) {
181182
create_geom_check_trigger(m_db_connection.get(), table().schema(),
182183
table().name(),
183184
table().geom_column().name());
@@ -260,7 +261,8 @@ void table_connection_t::stop(bool updateable, bool append)
260261
if (updateable && table().has_id_column()) {
261262
create_id_index();
262263

263-
if (table().has_geom_column() && table().geom_column().srid() != 4326) {
264+
if (table().has_geom_column() &&
265+
table().geom_column().needs_isvalid()) {
264266
create_geom_check_trigger(m_db_connection.get(), table().schema(),
265267
table().name(),
266268
table().geom_column().name());
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
local dtable = osm2pgsql.define_node_table('osm2pgsql_test_point', {
2+
local dtable = osm2pgsql.define_way_table('osm2pgsql_test_line', {
33
{ column = 'tags', type = 'hstore' },
4-
{ column = 'geom', type = 'point' },
4+
{ column = 'geom', type = 'linestring' },
55
}, { schema = 'myschema' })
66

77
local delete_keys = {
@@ -12,13 +12,14 @@ local delete_keys = {
1212

1313
local clean_tags = osm2pgsql.make_clean_tags_func(delete_keys)
1414

15-
function osm2pgsql.process_node(object)
15+
function osm2pgsql.process_way(object)
1616
if clean_tags(object.tags) then
1717
return
1818
end
1919

2020
dtable:add_row({
21-
tags = object.tags
21+
tags = object.tags,
22+
geom = { create = 'line' }
2223
})
2324
end
2425

tests/test-output-flex-schema.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ TEST_CASE("config with schema should work")
2929
REQUIRE(1 == conn.get_count("pg_namespace", "nspname = 'myschema'"));
3030
REQUIRE(1 == conn.get_count("pg_tables", "schemaname = 'myschema'"));
3131

32-
REQUIRE(1362 == conn.get_count("myschema.osm2pgsql_test_point"));
32+
REQUIRE(7103 == conn.get_count("myschema.osm2pgsql_test_line"));
3333

3434
REQUIRE(1 ==
3535
conn.get_count("pg_proc",
36-
"proname = 'osm2pgsql_test_point_osm2pgsql_valid'"));
36+
"proname = 'osm2pgsql_test_line_osm2pgsql_valid'"));
3737

3838
REQUIRE(1 == conn.get_count("pg_trigger"));
3939
REQUIRE(1 ==
4040
conn.get_count("pg_trigger",
41-
"tgname = 'osm2pgsql_test_point_osm2pgsql_valid'"));
41+
"tgname = 'osm2pgsql_test_line_osm2pgsql_valid'"));
4242
}

0 commit comments

Comments
 (0)