Skip to content

Commit 12fb9d0

Browse files
committed
Process untagged ways/relations in stage 1b/c correctly
When we introduced the "untagged" callbacks in bc87ea2, we did not call the process_untagged_way/relation callbacks for untagged ways/relations in stage 1b and 1c, but called the normal process_way/relation callbacks. That's not correct. So this is changed in this commit. For stage2 processing the answer which callback to call is a bit more complicated: On first glance we should also call the "untagged" function for untagged objects. But if we call the "untagged" function in that case, we would have to implement that function and it would be called for the millions of untagged objects we are not interested in. So it is arguably better to call the normal processing functions here. After all we explicitly requested the processing function to be called with the select_relation_members() call. So we are keeping this behaviour.
1 parent cff21ad commit 12fb9d0

File tree

4 files changed

+170
-11
lines changed

4 files changed

+170
-11
lines changed

src/output-flex.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ void output_flex_t::get_mutex_and_call_lua_function(
835835

836836
void output_flex_t::pending_way(osmid_t id)
837837
{
838-
if (!m_process_way) {
838+
if (!m_process_way && !m_process_untagged_way) {
839839
return;
840840
}
841841

@@ -844,8 +844,11 @@ void output_flex_t::pending_way(osmid_t id)
844844
}
845845

846846
way_delete(id);
847-
848-
get_mutex_and_call_lua_function(m_process_way, m_way_cache.get());
847+
auto const &func = m_way_cache.get().tags().empty() ? m_process_untagged_way
848+
: m_process_way;
849+
if (func) {
850+
get_mutex_and_call_lua_function(func, m_way_cache.get());
851+
}
849852
}
850853

851854
void output_flex_t::select_relation_members()
@@ -892,9 +895,20 @@ void output_flex_t::select_relation_members(osmid_t id)
892895
select_relation_members();
893896
}
894897

898+
void output_flex_t::process_relation()
899+
{
900+
auto const &func = m_relation_cache.get().tags().empty()
901+
? m_process_untagged_relation
902+
: m_process_relation;
903+
if (func) {
904+
get_mutex_and_call_lua_function(func, m_relation_cache.get());
905+
}
906+
}
907+
895908
void output_flex_t::pending_relation(osmid_t id)
896909
{
897-
if (!m_process_relation && !m_select_relation_members) {
910+
if (!m_process_relation && !m_process_untagged_relation &&
911+
!m_select_relation_members) {
898912
return;
899913
}
900914

@@ -904,16 +918,12 @@ void output_flex_t::pending_relation(osmid_t id)
904918

905919
select_relation_members();
906920
delete_from_tables(osmium::item_type::relation, id);
907-
908-
if (m_process_relation) {
909-
get_mutex_and_call_lua_function(m_process_relation,
910-
m_relation_cache.get());
911-
}
921+
process_relation();
912922
}
913923

914924
void output_flex_t::pending_relation_stage1c(osmid_t id)
915925
{
916-
if (!m_process_relation) {
926+
if (!m_process_relation && !m_process_untagged_relation) {
917927
return;
918928
}
919929

@@ -922,7 +932,7 @@ void output_flex_t::pending_relation_stage1c(osmid_t id)
922932
}
923933

924934
m_disable_insert = true;
925-
get_mutex_and_call_lua_function(m_process_relation, m_relation_cache.get());
935+
process_relation();
926936
m_disable_insert = false;
927937
}
928938

src/output-flex.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ class output_flex_t : public output_t
196196
void get_mutex_and_call_lua_function(prepared_lua_function_t func,
197197
osmium::OSMObject const &object);
198198

199+
void process_relation();
200+
199201
void init_lua(std::string const &filename, properties_t const &properties);
200202

201203
void check_context_and_state(char const *name, char const *context,

tests/bdd/flex/untagged.feature

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
Feature: Adding untagged objects to a flex database
2+
3+
Scenario: Import with normal and "untagged" callbacks
4+
Given the style file 'test_output_flex_untagged.lua'
5+
And the OSM data
6+
"""
7+
n11 v1 dV x1 y1
8+
n12 v1 dV x2 y2
9+
n13 v1 dV x3 y3
10+
n14 v1 dV Tamenity=restaurant x4 y4
11+
w20 v1 dV Thighway=primary Nn11,n12
12+
w21 v1 dV Nn13,n14
13+
r30 v1 dV Mn11@,w20@
14+
r31 v1 dV Ttype=route Mw20@
15+
"""
16+
When running osm2pgsql flex
17+
Then table osm2pgsql_test_nodes contains exactly
18+
| node_id | tagged | tags |
19+
| 11 | False | {} |
20+
| 12 | False | {} |
21+
| 13 | False | {} |
22+
| 14 | True | {'amenity': 'restaurant'} |
23+
24+
Then table osm2pgsql_test_ways contains exactly
25+
| way_id | tagged | tags |
26+
| 20 | True | {'highway': 'primary'} |
27+
| 21 | False | {} |
28+
29+
Then table osm2pgsql_test_relations contains exactly
30+
| relation_id | tagged | tags |
31+
| 30 | False | {} |
32+
| 31 | True | {'type': 'route'} |
33+
34+
Scenario: Import then update with normal and "untagged" callbacks
35+
Given the style file 'test_output_flex_untagged.lua'
36+
And the OSM data
37+
"""
38+
n11 v1 dV x1 y1
39+
n12 v1 dV x2 y2
40+
n13 v1 dV x3 y3
41+
n14 v1 dV Tamenity=restaurant x4 y4
42+
w20 v1 dV Thighway=primary Nn11,n12
43+
w21 v1 dV Nn13,n14
44+
w22 v1 dV Nn11,n12
45+
r30 v1 dV Mn11@,w20@
46+
r31 v1 dV Ttype=route Mw20@
47+
"""
48+
When running osm2pgsql flex with parameters
49+
| --slim |
50+
Then table osm2pgsql_test_nodes contains exactly
51+
| node_id | tagged | tags |
52+
| 11 | False | {} |
53+
| 12 | False | {} |
54+
| 13 | False | {} |
55+
| 14 | True | {'amenity': 'restaurant'} |
56+
57+
Then table osm2pgsql_test_ways contains exactly
58+
| way_id | tagged | tags |
59+
| 20 | True | {'highway': 'primary'} |
60+
| 21 | False | {} |
61+
| 22 | False | {} |
62+
63+
Then table osm2pgsql_test_relations contains exactly
64+
| relation_id | tagged | tags |
65+
| 30 | False | {} |
66+
| 31 | True | {'type': 'route'} |
67+
68+
Given the style file 'test_output_flex_untagged.lua'
69+
And the OSM data
70+
"""
71+
n11 v2 dV Tnatural=tree x1 y1
72+
n14 v2 dV x4 y4
73+
w21 v2 dV Nn14,n13
74+
"""
75+
When running osm2pgsql flex with parameters
76+
| --slim | -a |
77+
Then table osm2pgsql_test_nodes contains exactly
78+
| node_id | tagged | tags |
79+
| 11 | True | {'natural': 'tree'} |
80+
| 12 | False | {} |
81+
| 13 | False | {} |
82+
| 14 | False | {} |
83+
84+
Then table osm2pgsql_test_ways contains exactly
85+
| way_id | tagged | tags |
86+
| 20 | True | {'highway': 'primary'} |
87+
| 21 | False | {} |
88+
| 22 | False | {} |
89+
90+
Then table osm2pgsql_test_relations contains exactly
91+
| relation_id | tagged | tags |
92+
| 30 | False | {} |
93+
| 31 | True | {'type': 'route'} |
94+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
local tables = {}
3+
4+
tables.nodes = osm2pgsql.define_node_table('osm2pgsql_test_nodes', {
5+
{ column = 'tags', type = 'jsonb' },
6+
{ column = 'tagged', type = 'bool' },
7+
{ column = 'geom', type = 'point', not_null = true },
8+
})
9+
10+
tables.ways = osm2pgsql.define_way_table('osm2pgsql_test_ways', {
11+
{ column = 'tags', type = 'jsonb' },
12+
{ column = 'tagged', type = 'bool' },
13+
{ column = 'geom', type = 'linestring', not_null = true },
14+
})
15+
16+
tables.relations = osm2pgsql.define_relation_table('osm2pgsql_test_relations', {
17+
{ column = 'tags', type = 'jsonb' },
18+
{ column = 'tagged', type = 'bool' },
19+
{ column = 'geom', type = 'geometry', not_null = true },
20+
})
21+
22+
function insert(dtable, object, tagged, geom)
23+
tables[dtable]:insert({
24+
tags = object.tags,
25+
tagged = tagged,
26+
geom = geom,
27+
})
28+
end
29+
30+
function osm2pgsql.process_node(object)
31+
insert('nodes', object, true, object:as_point())
32+
end
33+
34+
function osm2pgsql.process_way(object)
35+
insert('ways', object, true, object:as_linestring())
36+
end
37+
38+
function osm2pgsql.process_relation(object)
39+
insert('relations', object, true, object:as_geometrycollection())
40+
end
41+
42+
function osm2pgsql.process_untagged_node(object)
43+
insert('nodes', object, false, object:as_point())
44+
end
45+
46+
function osm2pgsql.process_untagged_way(object)
47+
insert('ways', object, false, object:as_linestring())
48+
end
49+
50+
function osm2pgsql.process_untagged_relation(object)
51+
insert('relations', object, false, object:as_geometrycollection())
52+
end
53+

0 commit comments

Comments
 (0)