diff --git a/middle-pgsql.cpp b/middle-pgsql.cpp index b0f5ba19c..865a254f7 100644 --- a/middle-pgsql.cpp +++ b/middle-pgsql.cpp @@ -384,6 +384,11 @@ void middle_pgsql_t::nodes_set(osmium::Node const &node) } } +osmium::Location middle_pgsql_t::nodes_get(osmid_t osm_id) +{ + return persistent_cache->get(osm_id); +} + size_t middle_query_pgsql_t::nodes_get_list(osmium::WayNodeList *nodes) const { return m_persistent_cache ? m_persistent_cache->get_list(nodes) diff --git a/middle-pgsql.hpp b/middle-pgsql.hpp index 8cf3c7445..b2ac1b2c4 100644 --- a/middle-pgsql.hpp +++ b/middle-pgsql.hpp @@ -59,6 +59,7 @@ struct middle_pgsql_t : public slim_middle_t void commit() override; void nodes_set(osmium::Node const &node) override; + osmium::Location nodes_get(osmid_t osm_id) override; void nodes_delete(osmid_t id) override; void node_changed(osmid_t id) override; diff --git a/middle-ram.cpp b/middle-ram.cpp index c4ec82031..95b26a19a 100644 --- a/middle-ram.cpp +++ b/middle-ram.cpp @@ -38,6 +38,11 @@ void middle_ram_t::nodes_set(osmium::Node const &node) cache->set(node.id(), node.location()); } +osmium::Location middle_ram_t::nodes_get(osmid_t osm_id) +{ + return cache->get(osm_id); +} + void middle_ram_t::ways_set(osmium::Way const &way) { ways.set(way.id(), new ramWay(way, extra_attributes)); diff --git a/middle-ram.hpp b/middle-ram.hpp index 212421438..b84cfe7b9 100644 --- a/middle-ram.hpp +++ b/middle-ram.hpp @@ -91,6 +91,7 @@ struct middle_ram_t : public middle_t, public middle_query_t void commit(void) override; void nodes_set(osmium::Node const &node) override; + osmium::Location nodes_get(osmid_t osm_id) override; size_t nodes_get_list(osmium::WayNodeList *nodes) const override; int nodes_delete(osmid_t id); int node_changed(osmid_t id); diff --git a/middle.hpp b/middle.hpp index 1b58aae52..3c971bb09 100644 --- a/middle.hpp +++ b/middle.hpp @@ -88,6 +88,8 @@ struct middle_t virtual void commit(void) = 0; virtual void nodes_set(osmium::Node const &node) = 0; + virtual osmium::Location nodes_get(osmid_t osm_id) = 0; + virtual void ways_set(osmium::Way const &way) = 0; virtual void relations_set(osmium::Relation const &rel) = 0; diff --git a/osmdata.cpp b/osmdata.cpp index c6838e8de..764f85295 100644 --- a/osmdata.cpp +++ b/osmdata.cpp @@ -14,6 +14,8 @@ #include "osmdata.hpp" #include "output.hpp" +int nodes_moved = 0; + osmdata_t::osmdata_t(std::shared_ptr mid_, std::shared_ptr const &out_) : mid(mid_) @@ -82,15 +84,21 @@ int osmdata_t::node_modify(osmium::Node const &node) { slim_middle_t *slim = dynamic_cast(mid.get()); - slim->nodes_delete(node.id()); - slim->nodes_set(node); + osmium::Location oldnode = slim->nodes_get(node.id()); + if ( node.location().x() != oldnode.x() || node.location().y() != oldnode.y() ) { + slim->nodes_delete(node.id()); + slim->nodes_set(node); + nodes_moved++; + } int status = 0; for (auto& out: outs) { status |= out->node_modify(node); } - slim->node_changed(node.id()); + if ( node.location().x() != oldnode.x() || node.location().y() != oldnode.y() ) { + slim->node_changed(node.id()); + } return status; } @@ -275,6 +283,7 @@ struct pending_threaded_processor : public middle_t::pending_processor { //reset the number we've done ids_done = 0; + fprintf(stderr, "\n%i nodes moved\n", nodes_moved); fprintf(stderr, "\nGoing over pending ways...\n"); fprintf(stderr, "\t%zu ways are pending\n", ids_queued); fprintf(stderr, "\nUsing %zu helper-processes\n", clones.size());