@@ -158,39 +158,41 @@ void push_osm_object_to_lua_stack(lua_State *lua_state,
158158 luaX_add_table_str (lua_state, " user" , object.user ());
159159 }
160160
161- if (object.type () == osmium::item_type::way) {
162- auto const &way = static_cast <osmium::Way const &>(object);
163- luaX_add_table_bool (lua_state, " is_closed" ,
164- !way.nodes ().empty () && way.is_closed ());
165- luaX_add_table_array (lua_state, " nodes" , way.nodes (),
166- [&](osmium::NodeRef const &wn) {
167- lua_pushinteger (lua_state, wn.ref ());
168- });
169- } else if (object.type () == osmium::item_type::relation) {
170- auto const &relation = static_cast <osmium::Relation const &>(object);
171- luaX_add_table_array (
172- lua_state, " members" , relation.members (),
173- [&](osmium::RelationMember const &member) {
174- lua_createtable (lua_state, 0 , 3 );
175- std::array<char , 2 > tmp{" x" };
176- tmp[0 ] = osmium::item_type_to_char (member.type ());
177- luaX_add_table_str (lua_state, " type" , tmp.data ());
178- luaX_add_table_int (lua_state, " ref" , member.ref ());
179- luaX_add_table_str (lua_state, " role" , member.role ());
180- });
181- }
182-
183- lua_pushliteral (lua_state, " tags" );
184- lua_createtable (lua_state, 0 , (int )object.tags ().size ());
185- for (auto const &tag : object.tags ()) {
186- luaX_add_table_str (lua_state, tag.key (), tag.value ());
187- }
188- lua_rawset (lua_state, -3 );
189-
190- // Set the metatable of this object
191- lua_pushstring (lua_state, OSM2PGSQL_OSMOBJECT_CLASS);
192- lua_gettable (lua_state, LUA_REGISTRYINDEX);
193- lua_setmetatable (lua_state, -2 );
161+ if (!object.deleted ()) {
162+ if (object.type () == osmium::item_type::way) {
163+ auto const &way = static_cast <osmium::Way const &>(object);
164+ luaX_add_table_bool (lua_state, " is_closed" ,
165+ !way.nodes ().empty () && way.is_closed ());
166+ luaX_add_table_array (lua_state, " nodes" , way.nodes (),
167+ [&](osmium::NodeRef const &wn) {
168+ lua_pushinteger (lua_state, wn.ref ());
169+ });
170+ } else if (object.type () == osmium::item_type::relation) {
171+ auto const &relation = static_cast <osmium::Relation const &>(object);
172+ luaX_add_table_array (
173+ lua_state, " members" , relation.members (),
174+ [&](osmium::RelationMember const &member) {
175+ lua_createtable (lua_state, 0 , 3 );
176+ std::array<char , 2 > tmp{" x" };
177+ tmp[0 ] = osmium::item_type_to_char (member.type ());
178+ luaX_add_table_str (lua_state, " type" , tmp.data ());
179+ luaX_add_table_int (lua_state, " ref" , member.ref ());
180+ luaX_add_table_str (lua_state, " role" , member.role ());
181+ });
182+ }
183+
184+ lua_pushliteral (lua_state, " tags" );
185+ lua_createtable (lua_state, 0 , (int )object.tags ().size ());
186+ for (auto const &tag : object.tags ()) {
187+ luaX_add_table_str (lua_state, tag.key (), tag.value ());
188+ }
189+ lua_rawset (lua_state, -3 );
190+
191+ // Set the metatable of this object
192+ lua_pushstring (lua_state, OSM2PGSQL_OSMOBJECT_CLASS);
193+ lua_gettable (lua_state, LUA_REGISTRYINDEX);
194+ lua_setmetatable (lua_state, -2 );
195+ }
194196}
195197
196198/* *
@@ -1084,6 +1086,37 @@ void output_flex_t::delete_from_tables(osmium::item_type type, osmid_t osm_id)
10841086 }
10851087}
10861088
1089+ void output_flex_t::node_delete (osmium::Node const &node)
1090+ {
1091+ if (m_delete_node) {
1092+ m_context_node = &node;
1093+ get_mutex_and_call_lua_function (m_delete_node, node);
1094+ m_context_node = nullptr ;
1095+ }
1096+
1097+ node_delete (node.id ());
1098+ }
1099+
1100+ void output_flex_t::way_delete (osmium::Way *way)
1101+ {
1102+ if (m_delete_way) {
1103+ m_way_cache.init (way);
1104+ get_mutex_and_call_lua_function (m_delete_way, m_way_cache.get ());
1105+ }
1106+
1107+ way_delete (way->id ());
1108+ }
1109+
1110+ void output_flex_t::relation_delete (osmium::Relation const &rel)
1111+ {
1112+ if (m_delete_relation) {
1113+ m_relation_cache.init (rel);
1114+ get_mutex_and_call_lua_function (m_delete_relation, rel);
1115+ }
1116+
1117+ relation_delete (rel.id ());
1118+ }
1119+
10871120/* Delete is easy, just remove all traces of this object. We don't need to
10881121 * worry about finding objects that depend on it, since the same diff must
10891122 * contain the change for that also. */
@@ -1146,6 +1179,8 @@ output_flex_t::output_flex_t(output_flex_t const *other,
11461179 m_process_untagged_node(other->m_process_untagged_node),
11471180 m_process_untagged_way(other->m_process_untagged_way),
11481181 m_process_untagged_relation(other->m_process_untagged_relation),
1182+ m_delete_node(other->m_delete_node), m_delete_way(other->m_delete_way),
1183+ m_delete_relation(other->m_delete_relation),
11491184 m_select_relation_members(other->m_select_relation_members),
11501185 m_after_nodes(other->m_after_nodes), m_after_ways(other->m_after_ways),
11511186 m_after_relations(other->m_after_relations)
@@ -1330,6 +1365,13 @@ void output_flex_t::init_lua(std::string const &filename,
13301365 prepared_lua_function_t {lua_state (), calling_context::process_relation,
13311366 " process_untagged_relation" };
13321367
1368+ m_delete_node = prepared_lua_function_t {
1369+ lua_state (), calling_context::process_node, " delete_node" };
1370+ m_delete_way = prepared_lua_function_t {
1371+ lua_state (), calling_context::process_way, " delete_way" };
1372+ m_delete_relation = prepared_lua_function_t {
1373+ lua_state (), calling_context::process_relation, " delete_relation" };
1374+
13331375 m_select_relation_members = prepared_lua_function_t {
13341376 lua_state (), calling_context::select_relation_members,
13351377 " select_relation_members" , 1 };
0 commit comments