Skip to content

v0.2.54..v0.2.55 changeset DiffConflator.cpp

Garret Voltz edited this page Aug 14, 2020 · 1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/conflate/DiffConflator.cpp b/hoot-core/src/main/cpp/hoot/core/conflate/DiffConflator.cpp
index 7903191..8965d6a 100644
--- a/hoot-core/src/main/cpp/hoot/core/conflate/DiffConflator.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/conflate/DiffConflator.cpp
@@ -57,9 +57,10 @@
 #include <hoot/core/visitors/LengthOfWaysVisitor.h>
 #include <hoot/core/visitors/RemoveElementsVisitor.h>
 #include <hoot/core/io/OsmChangesetFileWriterFactory.h>
-#include <hoot/core/io/OsmChangesetFileWriter.h>
 #include <hoot/core/ops/CopyMapSubsetOp.h>
 #include <hoot/core/criterion/NotCriterion.h>
+#include <hoot/core/io/ChangesetStatsFormat.h>
+#include <hoot/core/util/MemoryUsageChecker.h>
 
 // standard
 #include <algorithm>
@@ -125,6 +126,9 @@ void DiffConflator::apply(OsmMapPtr& map)
   _reset();
   int currentStep = 1;  // tracks the current job task step for progress reporting
   _numSnappedWays = 0;
+  _geometryChangesetStats = "";
+  _tagChangesetStats = "";
+  _unifiedChangesetStats = "";
 
   // Store the map - we might need it for tag diff later.
   _pMap = map;
@@ -140,6 +144,7 @@ void DiffConflator::apply(OsmMapPtr& map)
     LOG_STATUS("Discarding unconflatable elements...");
     const int mapSizeBefore = _pMap->size();
     NonConflatableElementRemover().apply(_pMap);
+    MemoryUsageChecker::getInstance().check();
     _stats.append(
       SingleStat("Remove Non-conflatable Elements Time (sec)", timer.getElapsedAndRestart()));
     OsmMapWriterFactory::writeDebugMap(_pMap, "after-removing non-conflatable");
@@ -162,6 +167,7 @@ void DiffConflator::apply(OsmMapPtr& map)
   {
     _matchFactory.createMatches(_pMap, _matches, _bounds);
   }
+  MemoryUsageChecker::getInstance().check();
   LOG_STATUS(
     "Found: " << StringUtils::formatLargeNumber(_matches.size()) <<
     " Differential Conflation match conflicts to be removed.");
@@ -180,6 +186,7 @@ void DiffConflator::apply(OsmMapPtr& map)
     // because that operation deletes all of the info needed for calculating the tag diff.
     _updateProgress(currentStep - 1, "Storing tag differentials...");
     _calcAndStoreTagChanges();
+    MemoryUsageChecker::getInstance().check();
     currentStep++;
   }
 
@@ -194,6 +201,7 @@ void DiffConflator::apply(OsmMapPtr& map)
   // We're eventually getting rid of all matches from the output, but in order to make the road
   // snapping work correctly we'll get rid of secondary elements in matches first.
   _removeMatches(Status::Unknown2);
+  MemoryUsageChecker::getInstance().check();
 
   if (ConfigOptions().getDifferentialSnapUnconnectedRoads())
   {
@@ -201,6 +209,7 @@ void DiffConflator::apply(OsmMapPtr& map)
     // dumping the ref elements in the matches, or the roads we need to snap back to won't be there
     // anymore.
     _numSnappedWays = _snapSecondaryRoadsBackToRef();
+    MemoryUsageChecker::getInstance().check();
   }
 
   if (ConfigOptions().getDifferentialRemoveReferenceData())
@@ -209,6 +218,7 @@ void DiffConflator::apply(OsmMapPtr& map)
     // belongs to a match pair. Then we will delete all remaining input1 items...leaving us with the
     // differential that we want.
     _removeMatches(Status::Unknown1);
+    MemoryUsageChecker::getInstance().check();
 
     // Now remove input1 elements
     LOG_STATUS("\tRemoving all reference elements...");
@@ -218,6 +228,7 @@ void DiffConflator::apply(OsmMapPtr& map)
     removeRef1Visitor.setRecursive(true);
     removeRef1Visitor.addCriterion(pTagKeyCrit);
     _pMap->visitRw(removeRef1Visitor);
+    MemoryUsageChecker::getInstance().check();
     OsmMapWriterFactory::writeDebugMap(_pMap, "after-removing-ref-elements");
     LOG_STATUS(
       "Removed " << StringUtils::formatLargeNumber(mapSizeBefore - _pMap->size()) <<
@@ -364,9 +375,9 @@ void DiffConflator::addChangesToMap(OsmMapPtr pMap, ChangesetProviderPtr pChange
     else if (ElementType::Relation == c.getElement()->getElementType().getEnum())
     {
       // Diff conflation w/ tags doesn't handle relations. Changed this to log that the relations
-      // are being skipped for now. #3449 was created to deal with adding relation support and then
-      // closed since we lack a use case currently that requires it. If we ever get one, then we
-      // can re-open that issue.
+      // are being skipped for now. #3449 was originally created to deal with adding relation
+      // support and then closed since we lack a use case currently that requires it. If we ever
+      // get one, then we can re-open that issue.
 
       LOG_DEBUG("Relation handling not implemented with differential conflation: " << c);
       if (Log::getInstance().getLevel() <= Log::Trace)
@@ -505,7 +516,8 @@ Change DiffConflator::_getChange(ConstElementPtr pOldElement, ConstElementPtr pN
 
   // Need to merge tags into the new element. Keeps all names, chooses tags1 in event of a conflict.
   Tags newTags =
-    TagComparator::getInstance().overwriteMerge(pNewElement->getTags(), pOldElement->getTags());
+    TagComparator::getInstance().overwriteMerge(pNewElement->getTags(), pOldElement->getTags(), QStringList(),
+                                                ConfigOptions().getDuplicateNameCaseSensitive());
   pChangeElement->setTags(newTags);
 
   // Create the change
@@ -571,8 +583,9 @@ ChangesetProviderPtr DiffConflator::_getChangesetFromMap(OsmMapPtr pMap)
   }
 }
 
-void DiffConflator::writeChangeset(OsmMapPtr pResultMap, QString& output, bool separateOutput,
-                                   const QString& osmApiDbUrl)
+void DiffConflator::writeChangeset(
+  OsmMapPtr pResultMap, QString& output, bool separateOutput,
+  const ChangesetStatsFormat& changesetStatsFormat, const QString& osmApiDbUrl)
 {
   if (output.endsWith(".osc.sql") && osmApiDbUrl.trimmed().isEmpty())
   {
@@ -606,12 +619,22 @@ void DiffConflator::writeChangeset(OsmMapPtr pResultMap, QString& output, bool s
     // only one changeset to write
     LOG_DEBUG("Writing single changeset...");
     writer->write(output, pGeoChanges);
+    // ChangesetStatsFormat::Unknown is the default format setting, and we'll assume no stats are
+    // to be output if that's the requested format.
+    if (changesetStatsFormat != ChangesetStatsFormat::Unknown)
+    {
+      _geometryChangesetStats = writer->getStatsTable(changesetStatsFormat);
+    }
   }
   else if (separateOutput)
   {
     // write two changesets
     LOG_DEBUG("Writing separate changesets...");
     writer->write(output, pGeoChanges);
+    if (changesetStatsFormat != ChangesetStatsFormat::Unknown)
+    {
+      _geometryChangesetStats = writer->getStatsTable(changesetStatsFormat);
+    }
 
     QString outFileName = output;
     if (outFileName.endsWith(".osc"))
@@ -627,6 +650,10 @@ void DiffConflator::writeChangeset(OsmMapPtr pResultMap, QString& output, bool s
     }
     LOG_VARD(outFileName);
     writer->write(outFileName, _pTagChanges);
+    if (changesetStatsFormat != ChangesetStatsFormat::Unknown)
+    {
+      _tagChangesetStats = writer->getStatsTable(changesetStatsFormat);
+    }
   }
   else
   {
@@ -637,6 +664,10 @@ void DiffConflator::writeChangeset(OsmMapPtr pResultMap, QString& output, bool s
     pChanges->addChangesetProvider(pGeoChanges);
     pChanges->addChangesetProvider(_pTagChanges);
     writer->write(output, pChanges);
+    if (changesetStatsFormat != ChangesetStatsFormat::Unknown)
+    {
+      _unifiedChangesetStats = writer->getStatsTable(changesetStatsFormat);
+    }
   }
 }
 
Clone this wiki locally