Skip to content

v0.2.54..v0.2.55 changeset MapCropper.cpp

Garret Voltz edited this page Aug 14, 2020 · 1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/ops/MapCropper.cpp b/hoot-core/src/main/cpp/hoot/core/ops/MapCropper.cpp
index ff3afd6..7bffe7e 100644
--- a/hoot-core/src/main/cpp/hoot/core/ops/MapCropper.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/ops/MapCropper.cpp
@@ -55,7 +55,8 @@
 #include <hoot/core/util/Validate.h>
 #include <hoot/core/ops/RemoveEmptyRelationsOp.h>
 #include <hoot/core/util/StringUtils.h>
-#include <hoot/core/elements/OsmUtils.h>
+#include <hoot/core/elements/WayUtils.h>
+#include <hoot/core/elements/ElementIdUtils.h>
 #include <hoot/core/ops/SuperfluousWayRemover.h>
 #include <hoot/core/ops/SuperfluousNodeRemover.h>
 #include <hoot/core/visitors/RemoveMissingElementsVisitor.h>
@@ -82,6 +83,7 @@ _invert(false),
 _keepEntireFeaturesCrossingBounds(false),
 _keepOnlyFeaturesInsideBounds(false),
 _removeSuperfluousFeatures(true),
+_removeMissingElements(true),
 _statusUpdateInterval(1000),
 _numWaysInBounds(0),
 _numWaysOutOfBounds(0),
@@ -99,6 +101,7 @@ _invert(false),
 _keepEntireFeaturesCrossingBounds(false),
 _keepOnlyFeaturesInsideBounds(false),
 _removeSuperfluousFeatures(true),
+_removeMissingElements(true),
 _statusUpdateInterval(1000),
 _numWaysInBounds(0),
 _numWaysOutOfBounds(0),
@@ -115,6 +118,7 @@ _invert(false),
 _keepEntireFeaturesCrossingBounds(false),
 _keepOnlyFeaturesInsideBounds(false),
 _removeSuperfluousFeatures(true),
+_removeMissingElements(true),
 _statusUpdateInterval(1000),
 _numWaysInBounds(0),
 _numWaysOutOfBounds(0),
@@ -216,7 +220,7 @@ void MapCropper::apply(OsmMapPtr& map)
 
   LOG_DEBUG("Cropping ways...");
   LOG_VARD(map->size());
-  LOG_VART(OsmUtils::allElementIdsPositive(map));
+  LOG_VART(ElementIdUtils::allElementIdsPositive(map));
 
   _numProcessed = 0;
   _numAffected = 0;
@@ -351,10 +355,10 @@ void MapCropper::apply(OsmMapPtr& map)
     LOG_VART(_explicitlyIncludedWayIds.size());
     if (_explicitlyIncludedWayIds.size() > 0)
     {
-      LOG_VART(OsmUtils::nodeContainedByAnyWay(node->getId(), _explicitlyIncludedWayIds, map));
+      LOG_VART(WayUtils::nodeContainedByAnyWay(node->getId(), _explicitlyIncludedWayIds, map));
     }
     if (_inclusionCrit && _explicitlyIncludedWayIds.size() > 0 &&
-        OsmUtils::nodeContainedByAnyWay(node->getId(), _explicitlyIncludedWayIds, map))
+        WayUtils::nodeContainedByAnyWay(node->getId(), _explicitlyIncludedWayIds, map))
     {
       LOG_TRACE(
         "Skipping delete for: " << node->getElementId() <<
@@ -448,11 +452,17 @@ void MapCropper::apply(OsmMapPtr& map)
     numSuperfluousNodesRemoved = SuperfluousNodeRemover::removeNodes(map);
   }
 
-  // This will handle removing refs in relation members we've cropped out.
-  RemoveMissingElementsVisitor missingElementsRemover;
-  LOG_INFO("\t" << missingElementsRemover.getInitStatusMessage());
-  map->visitRw(missingElementsRemover);
-  LOG_DEBUG("\t" << missingElementsRemover.getCompletedStatusMessage());
+  // Most of the time we want to remove missing refs in order for the output to be clean, but in
+  // some workflows, like cut and replace, we need to keep them around to prevent the resulting
+  // changeset from being too heavy handed.
+  if (_removeMissingElements)
+  {
+    // This will handle removing refs in relation members we've cropped out.
+    RemoveMissingElementsVisitor missingElementsRemover;
+    LOG_INFO("\t" << missingElementsRemover.getInitStatusMessage());
+    map->visitRw(missingElementsRemover);
+    LOG_DEBUG("\t" << missingElementsRemover.getCompletedStatusMessage());
+  }
 
   // This will remove any relations that were already empty or became empty after the previous step.
   RemoveEmptyRelationsOp emptyRelationRemover;
@@ -462,7 +472,7 @@ void MapCropper::apply(OsmMapPtr& map)
 
   LOG_VARD(_numAffected);
   LOG_VARD(map->size());
-  LOG_VART(OsmUtils::allElementIdsPositive(map));
+  LOG_VART(ElementIdUtils::allElementIdsPositive(map));
   LOG_VARD(StringUtils::formatLargeNumber(_numWaysInBounds));
   LOG_VARD(StringUtils::formatLargeNumber(_numWaysOutOfBounds));
   LOG_VARD(StringUtils::formatLargeNumber(_numWaysCrossingThreshold));
Clone this wiki locally