Skip to content

v0.2.52..v0.2.53 changeset DiffConflator.cpp

Garret Voltz edited this page Feb 12, 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 2ef81db..76c64f4 100644
--- a/hoot-core/src/main/cpp/hoot/core/conflate/DiffConflator.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/conflate/DiffConflator.cpp
@@ -22,7 +22,7 @@
  * This will properly maintain the copyright information. DigitalGlobe
  * copyrights will be updated automatically.
  *
- * @copyright Copyright (C) 2017, 2018, 2019 DigitalGlobe (http://www.digitalglobe.com/)
+ * @copyright Copyright (C) 2017, 2018, 2019, 2020 DigitalGlobe (http://www.digitalglobe.com/)
  */
 #include "DiffConflator.h"
 
@@ -58,6 +58,8 @@
 #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>
 
 // standard
 #include <algorithm>
@@ -132,11 +134,15 @@ void DiffConflator::apply(OsmMapPtr& map)
   // If we skip this part, then any non-matchable data will simply pass through to output.
   if (ConfigOptions().getDifferentialRemoveUnconflatableData())
   {
-    LOG_INFO("Discarding unconflatable elements...");
+    LOG_STATUS("Discarding unconflatable elements...");
+    const int mapSizeBefore = _pMap->size();
     NonConflatableElementRemover().apply(_pMap);
     _stats.append(
       SingleStat("Remove Non-conflatable Elements Time (sec)", timer.getElapsedAndRestart()));
     OsmMapWriterFactory::writeDebugMap(_pMap, "after-removing non-conflatable");
+    LOG_STATUS(
+      "Discarded " << StringUtils::formatLargeNumber(mapSizeBefore - _pMap->size()) <<
+      " unconflatable elements.");
   }
 
   // will reproject only if necessary
@@ -153,7 +159,7 @@ void DiffConflator::apply(OsmMapPtr& map)
   {
     _matchFactory.createMatches(_pMap, _matches, _bounds);
   }
-  LOG_INFO(
+  LOG_STATUS(
     "Found: " << StringUtils::formatLargeNumber(_matches.size()) <<
     " Differential Conflation matches.");
   double findMatchesTime = timer.getElapsedAndRestart();
@@ -199,13 +205,17 @@ void DiffConflator::apply(OsmMapPtr& map)
     _removeMatches(Status::Unknown1);
 
     // Now remove input1 elements
-    LOG_DEBUG("\tRemoving all reference elements...");
+    LOG_STATUS("\tRemoving all reference elements...");
+    const int mapSizeBefore = _pMap->size();
     ElementCriterionPtr pTagKeyCrit(new TagKeyCriterion(MetadataTags::Ref1()));
     RemoveElementsVisitor removeRef1Visitor;
     removeRef1Visitor.setRecursive(true);
     removeRef1Visitor.addCriterion(pTagKeyCrit);
     _pMap->visitRw(removeRef1Visitor);
     OsmMapWriterFactory::writeDebugMap(_pMap, "after-removing-ref-elements");
+    LOG_STATUS(
+      "Removed " << StringUtils::formatLargeNumber(mapSizeBefore - _pMap->size()) <<
+      " reference elements...");
   }
 }
 
@@ -291,17 +301,17 @@ void DiffConflator::storeOriginalMap(OsmMapPtr& pMap)
       "elements. ");
   }
 
-  // Use the copy constructor
+  // Use the copy constructor to copy the entire map.
   _pOriginalMap.reset(new OsmMap(pMap));
 
   // We're storing this off for potential use later on if any roads get snapped after conflation.
-  // See additional comments in _getChangesetFromMap.
-  _pOriginalRef1Map.reset(new OsmMap(pMap));
-  ElementCriterionPtr pTagKeyCrit(new TagKeyCriterion(MetadataTags::Ref2()));
-  RemoveElementsVisitor removeRef2Visitor;
-  removeRef2Visitor.setRecursive(true);
-  removeRef2Visitor.addCriterion(pTagKeyCrit);
-  _pOriginalRef1Map->visitRw(removeRef2Visitor);
+  // Get rid of ref2 and children. See additional comments in _getChangesetFromMap.
+  // TODO: Can we filter this down to whatever feature type the snapping is configured for?
+  std::shared_ptr<NotCriterion> crit(
+    new NotCriterion(ElementCriterionPtr(new TagKeyCriterion(MetadataTags::Ref2()))));
+  CopyMapSubsetOp mapCopier(pMap, crit);
+  _pOriginalRef1Map.reset(new OsmMap());
+  mapCopier.apply(_pOriginalRef1Map);
 }
 
 void DiffConflator::markInputElements(OsmMapPtr pMap)
@@ -347,10 +357,10 @@ 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 silently 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.
+      // 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.
 
       LOG_DEBUG("Relation handling not implemented with differential conflation: " << c);
       if (Log::getInstance().getLevel() <= Log::Trace)
Clone this wiki locally