Skip to content

v0.2.49..v0.2.50 changeset OsmMap.cpp

Garret Voltz edited this page Nov 6, 2019 · 1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/elements/OsmMap.cpp b/hoot-core/src/main/cpp/hoot/core/elements/OsmMap.cpp
index faf5691..654df8e 100644
--- a/hoot-core/src/main/cpp/hoot/core/elements/OsmMap.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/elements/OsmMap.cpp
@@ -48,10 +48,12 @@
 #include <hoot/core/util/SignalCatcher.h>
 #include <hoot/core/util/Validate.h>
 #include <hoot/core/elements/ElementComparer.h>
+#include <hoot/core/util/StringUtils.h>
 using namespace hoot::elements;
 
 // Qt
 #include <QDebug>
+#include <QFileInfo>
 
 using namespace std;
 
@@ -127,9 +129,11 @@ void OsmMap::append(const ConstOsmMapPtr& appendFromMap, const bool throwOutDupe
     char* wkt1 = 0;
     getProjection()->exportToPrettyWkt(&wkt1);
     QString proj1 = QString::fromLatin1(wkt1);
+    CPLFree(wkt1);
     char* wkt2 = 0;
     appendFromMap->getProjection()->exportToPrettyWkt(&wkt2);
     QString proj2 = QString::fromLatin1(wkt2);
+    CPLFree(wkt2);
     throw HootException(
       "Incompatible maps.  Map being appended to has projection:\n" + proj1 +
       "\nMap being appended from has projection:\n" + proj2);
@@ -349,6 +353,7 @@ void OsmMap::addRelation(const RelationPtr& r)
 
 void OsmMap::addWay(const WayPtr& w)
 {
+  LOG_TRACE("Adding: " << w->getElementId());
   _idGen->ensureWayBounds(w->getId());
   _ways[w->getId()] = w;
   w->registerListener(_index.get());
@@ -419,7 +424,7 @@ void OsmMap::_copy(const ConstOsmMapPtr& from)
   WayMap::const_iterator it = from->_ways.begin();
   while (it != from->_ways.end())
   {
-    WayPtr w = WayPtr(new Way(*(it->second)));
+    WayPtr w(new Way(*(it->second)));
     w->registerListener(_index.get());
     _ways[it->first] = w;
     // no need to add it to the index b/c the index is created in a lazy fashion.
@@ -613,6 +618,7 @@ void OsmMap::replaceNode(long oldId, long newId)
   for (set<long>::iterator it = ways.begin(); it != ways.end(); ++it)
   {
     const WayPtr& w = getWay(*it);
+    LOG_VART(w->getElementId());
 
 #   ifdef DEBUG
       if (w.get() == NULL)
@@ -731,12 +737,22 @@ void OsmMap::visitNodesRo(ConstElementVisitor& visitor) const
 
   // make a copy so we can iterate through even if there are changes.
   const NodeMap& allNodes = getNodes();
+  int numVisited = 0;
+  const int taskStatusUpdateInterval = ConfigOptions().getTaskStatusUpdateInterval();
   for (NodeMap::const_iterator it = allNodes.begin(); it != allNodes.end(); ++it)
   {
     if (containsNode(it->first))
     {
       visitor.visit(std::dynamic_pointer_cast<const Node>(it->second));
     }
+
+    numVisited++;
+    if (numVisited % (taskStatusUpdateInterval * 10) == 0)
+    {
+      PROGRESS_INFO(
+        "\tProcessed " << StringUtils::formatLargeNumber(numVisited) << " / " <<
+        StringUtils::formatLargeNumber(allNodes.size()) << " nodes.");
+    }
   }
 }
 
@@ -750,12 +766,22 @@ void OsmMap::visitWaysRo(ConstElementVisitor& visitor) const
 
   // make a copy so we can iterate through even if there are changes.
   const WayMap& allWays = getWays();
+  int numVisited = 0;
+  const int taskStatusUpdateInterval = ConfigOptions().getTaskStatusUpdateInterval();
   for (WayMap::const_iterator it = allWays.begin(); it != allWays.end(); ++it)
   {
     if (containsWay(it->first))
     {
       visitor.visit(std::dynamic_pointer_cast<const Way>(it->second));
     }
+
+    numVisited++;
+    if (numVisited % (taskStatusUpdateInterval * 10) == 0)
+    {
+      PROGRESS_INFO(
+        "\tProcessed " << StringUtils::formatLargeNumber(numVisited) << " / " <<
+        StringUtils::formatLargeNumber(allWays.size()) << " ways.");
+    }
   }
 }
 
@@ -769,12 +795,22 @@ void OsmMap::visitRelationsRo(ConstElementVisitor& visitor) const
 
   // make a copy so we can iterate through even if there are changes.
   const RelationMap& allRelations = getRelations();
+  int numVisited = 0;
+  const int taskStatusUpdateInterval = ConfigOptions().getTaskStatusUpdateInterval();
   for (RelationMap::const_iterator it = allRelations.begin(); it != allRelations.end(); ++it)
   {
     if (containsRelation(it->first))
     {
       visitor.visit(std::dynamic_pointer_cast<const Relation>(it->second));
     }
+
+    numVisited++;
+    if (numVisited % (taskStatusUpdateInterval * 10) == 0)
+    {
+      PROGRESS_INFO(
+        "\tProcessed " << StringUtils::formatLargeNumber(numVisited) << " / " <<
+        StringUtils::formatLargeNumber(allRelations.size()) << " relations.");
+    }
   }
 }
 
@@ -788,32 +824,60 @@ void OsmMap::visitRw(ConstElementVisitor& visitor)
 
   // make a copy so we can iterate through even if there are changes.
   const NodeMap allNodes = getNodes();
+  int numVisited = 0;
+  const int taskStatusUpdateInterval = ConfigOptions().getTaskStatusUpdateInterval();
   for (NodeMap::const_iterator it = allNodes.begin(); it != allNodes.end(); ++it)
   {
     if (containsNode(it->first))
     {
       visitor.visit(std::dynamic_pointer_cast<const Node>(it->second));
     }
+
+    numVisited++;
+    if (numVisited % (taskStatusUpdateInterval * 10) == 0)
+    {
+      PROGRESS_INFO(
+        "\tProcessed " << StringUtils::formatLargeNumber(numVisited) << " / " <<
+        StringUtils::formatLargeNumber(allNodes.size()) << " nodes.");
+    }
   }
 
   // make a copy so we can iterate through even if there are changes.
   const WayMap allWays = getWays();
+  numVisited = 0;
   for (WayMap::const_iterator it = allWays.begin(); it != allWays.end(); ++it)
   {
     if (containsWay(it->first))
     {
       visitor.visit(std::dynamic_pointer_cast<const Way>(it->second));
     }
+
+    numVisited++;
+    if (numVisited % (taskStatusUpdateInterval * 10) == 0)
+    {
+      PROGRESS_INFO(
+        "\tProcessed " << StringUtils::formatLargeNumber(numVisited) << " / " <<
+        StringUtils::formatLargeNumber(allWays.size()) << " ways.");
+    }
   }
 
   // make a copy so we can iterate through even if there are changes.
   const RelationMap allRelations = getRelations();
+  numVisited = 0;
   for (RelationMap::const_iterator it = allRelations.begin(); it != allRelations.end(); ++it)
   {
     if (containsRelation(it->first))
     {
       visitor.visit(std::dynamic_pointer_cast<const Relation>(it->second));
     }
+
+    numVisited++;
+    if (numVisited % (taskStatusUpdateInterval * 10) == 0)
+    {
+      PROGRESS_INFO(
+        "\tProcessed " << StringUtils::formatLargeNumber(numVisited) << " / " <<
+        StringUtils::formatLargeNumber(allRelations.size()) << " relations.");
+    }
   }
 }
 
@@ -827,32 +891,60 @@ void OsmMap::visitRw(ElementVisitor& visitor)
 
   // make a copy so we can iterate through even if there are changes.
   const NodeMap allNodes = getNodes();
+  int numVisited = 0;
+  const int taskStatusUpdateInterval = ConfigOptions().getTaskStatusUpdateInterval();
   for (NodeMap::const_iterator it = allNodes.begin(); it != allNodes.end(); ++it)
   {
     if (containsNode(it->first))
     {
       visitor.visit(it->second);
     }
+
+    numVisited++;
+    if (numVisited % (taskStatusUpdateInterval * 10) == 0)
+    {
+      PROGRESS_INFO(
+        "\tProcessed " << StringUtils::formatLargeNumber(numVisited) << " / " <<
+        StringUtils::formatLargeNumber(allNodes.size()) << " nodes.");
+    }
   }
 
   // make a copy so we can iterate through even if there are changes.
   const WayMap allWays = getWays();
+  numVisited = 0;
   for (WayMap::const_iterator it = allWays.begin(); it != allWays.end(); ++it)
   {
     if (containsWay(it->first))
     {
       visitor.visit(it->second);
     }
+
+    numVisited++;
+    if (numVisited % (taskStatusUpdateInterval * 10) == 0)
+    {
+      PROGRESS_INFO(
+        "\tProcessed " << StringUtils::formatLargeNumber(numVisited) << " / " <<
+        StringUtils::formatLargeNumber(allWays.size()) << " ways.");
+    }
   }
 
   // make a copy so we can iterate through even if there are changes.
   const RelationMap allRelations = getRelations();
+  numVisited = 0;
   for (RelationMap::const_iterator it = allRelations.begin(); it != allRelations.end(); ++it)
   {
     if (containsRelation(it->first))
     {
       visitor.visit(it->second);
     }
+
+    numVisited++;
+    if (numVisited % (taskStatusUpdateInterval * 10) == 0)
+    {
+      PROGRESS_INFO(
+        "\tProcessed " << StringUtils::formatLargeNumber(numVisited) << " / " <<
+        StringUtils::formatLargeNumber(allRelations.size()) << " relations.");
+    }
   }
 }
 
@@ -866,12 +958,22 @@ void OsmMap::visitWaysRw(ConstElementVisitor& visitor)
 
   // make a copy so we can iterate through even if there are changes.
   const WayMap allWays = getWays();
+  int numVisited = 0;
+  const int taskStatusUpdateInterval = ConfigOptions().getTaskStatusUpdateInterval();
   for (WayMap::const_iterator it = allWays.begin(); it != allWays.end(); ++it)
   {
     if (containsWay(it->first))
     {
       visitor.visit(std::dynamic_pointer_cast<const Way>(it->second));
     }
+
+    numVisited++;
+    if (numVisited % (taskStatusUpdateInterval * 10) == 0)
+    {
+      PROGRESS_INFO(
+        "\tProcessed " << StringUtils::formatLargeNumber(numVisited) << " / " <<
+        StringUtils::formatLargeNumber(allWays.size()) << " ways.");
+    }
   }
 }
 
@@ -885,12 +987,22 @@ void OsmMap::visitWaysRw(ElementVisitor& visitor)
 
   // make a copy so we can iterate through even if there are changes.
   const WayMap allWays = getWays();
+  int numVisited = 0;
+  const int taskStatusUpdateInterval = ConfigOptions().getTaskStatusUpdateInterval();
   for (WayMap::const_iterator it = allWays.begin(); it != allWays.end(); ++it)
   {
     if (containsWay(it->first))
     {
       visitor.visit(std::dynamic_pointer_cast<Way>(it->second));
     }
+
+    numVisited++;
+    if (numVisited % (taskStatusUpdateInterval * 10) == 0)
+    {
+      PROGRESS_INFO(
+        "\tProcessed " << StringUtils::formatLargeNumber(numVisited) << " / " <<
+        StringUtils::formatLargeNumber(allWays.size()) << " ways.");
+    }
   }
 }
 
@@ -904,12 +1016,22 @@ void OsmMap::visitRelationsRw(ConstElementVisitor& visitor)
 
   // make a copy so we can iterate through even if there are changes.
   const RelationMap allRs = getRelations();
+  int numVisited = 0;
+  const int taskStatusUpdateInterval = ConfigOptions().getTaskStatusUpdateInterval();
   for (RelationMap::const_iterator it = allRs.begin(); it != allRs.end(); ++it)
   {
     if (containsRelation(it->first))
     {
       visitor.visit(std::dynamic_pointer_cast<const Relation>(it->second));
     }
+
+    numVisited++;
+    if (numVisited % (taskStatusUpdateInterval * 10) == 0)
+    {
+      PROGRESS_INFO(
+        "\tProcessed " << StringUtils::formatLargeNumber(numVisited) << " / " <<
+        StringUtils::formatLargeNumber(allRs.size()) << " relations.");
+    }
   }
 }
 
@@ -923,12 +1045,22 @@ void OsmMap::visitRelationsRw(ElementVisitor& visitor)
 
   // make a copy so we can iterate through even if there are changes.
   const RelationMap allRs = getRelations();
+  int numVisited = 0;
+  const int taskStatusUpdateInterval = ConfigOptions().getTaskStatusUpdateInterval();
   for (RelationMap::const_iterator it = allRs.begin(); it != allRs.end(); ++it)
   {
     if (containsRelation(it->first))
     {
       visitor.visit(std::dynamic_pointer_cast<Relation>(it->second));
     }
+
+    numVisited++;
+    if (numVisited % (taskStatusUpdateInterval * 10) == 0)
+    {
+      PROGRESS_INFO(
+        "\tProcessed " << StringUtils::formatLargeNumber(numVisited) << " / " <<
+        StringUtils::formatLargeNumber(allRs.size()) << " relations.");
+    }
   }
 }
 
@@ -974,4 +1106,76 @@ void OsmMap::_replaceNodeInRelations(long oldId, long newId)
   }
 }
 
+QString OsmMap::getSource() const
+{
+  QString buffer;
+  QTextStream ts(&buffer);
+  bool first = true;
+  for (std::set<QString>::iterator it = _sources.begin(); it != _sources.end(); ++it)
+  {
+    if (first)
+      first = false;
+    else
+      ts << ";";
+    ts << *it;
+  }
+  return ts.readAll();
+}
+
+void OsmMap::appendSource(const QString& url)
+{
+  QStringList urls = url.split(";");
+  for (int i = 0; i < urls.size(); ++i)
+  {
+    QUrl src(urls[i]);
+    QString source;
+    if (src.scheme() == "")
+      source = QFileInfo(src.toString()).fileName();
+    else if (src.isLocalFile())
+      source = QFileInfo(src.toLocalFile()).fileName();
+    else if (src.scheme().toLower() == MetadataTags::HootApiDbScheme() ||
+             src.scheme().toLower() == MetadataTags::OsmApiDbScheme())
+      source = src.scheme() + ":" + src.path().split("/").last();
+    else
+      source = src.toDisplayString();
+    _sources.insert(source);
+  }
+}
+
+void OsmMap::replaceSource(const QString &url)
+{
+  _sources.clear();
+  appendSource(url);
+}
+
+QSet<long> OsmMap::getNodeIds() const
+{
+  QSet<long> ids;
+  for (NodeMap::const_iterator it = _nodes.begin(); it != _nodes.end(); ++it)
+  {
+    ids.insert(it->first);
+  }
+  return ids;
+}
+
+QSet<long> OsmMap::getWayIds() const
+{
+  QSet<long> ids;
+  for (WayMap::const_iterator it = _ways.begin(); it != _ways.end(); ++it)
+  {
+    ids.insert(it->first);
+  }
+  return ids;
+}
+
+QSet<long> OsmMap::getRelationIds() const
+{
+  QSet<long> ids;
+  for (RelationMap::const_iterator it = _relations.begin(); it != _relations.end(); ++it)
+  {
+    ids.insert(it->first);
+  }
+  return ids;
+}
+
 }
Clone this wiki locally