Skip to content

v0.2.54..v0.2.55 changeset OsmXmlReader.cpp

Garret Voltz edited this page Aug 14, 2020 · 1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/io/OsmXmlReader.cpp b/hoot-core/src/main/cpp/hoot/core/io/OsmXmlReader.cpp
index 37ba853..0fbf6a8 100644
--- a/hoot-core/src/main/cpp/hoot/core/io/OsmXmlReader.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/io/OsmXmlReader.cpp
@@ -31,7 +31,7 @@
 #include <hoot/core/elements/ConstElementVisitor.h>
 #include <hoot/core/elements/Node.h>
 #include <hoot/core/elements/OsmMap.h>
-#include <hoot/core/elements/OsmUtils.h>
+#include <hoot/core/util/DateTimeUtils.h>
 #include <hoot/core/elements/Tags.h>
 #include <hoot/core/elements/Way.h>
 #include <hoot/core/io/IoUtils.h>
@@ -97,9 +97,18 @@ void OsmXmlReader::setConfiguration(const Settings& conf)
   setUseFileStatus(configOptions.getReaderUseFileStatus()),
   setAddSourceDateTime(configOptions.getReaderAddSourceDatetime());
   setPreserveAllTags(configOptions.getReaderPreserveAllTags());
-  setAddChildRefsWhenMissing(configOptions.getOsmMapReaderXmlAddChildRefsWhenMissing());
   setStatusUpdateInterval(configOptions.getTaskStatusUpdateInterval() * 10);
   setBounds(GeometryUtils::envelopeFromConfigString(configOptions.getConvertBoundingBox()));
+  // If a bounds was set and we don't want to remove missing elements as a result of cropping, we
+  // need to modify the reader to allow reading in the missing refs.
+  if (!_bounds.isNull() && !configOptions.getConvertBoundingBoxRemoveMissingElements())
+  {
+    setAddChildRefsWhenMissing(true);
+  }
+  else
+  {
+    setAddChildRefsWhenMissing(configOptions.getOsmMapReaderXmlAddChildRefsWhenMissing());
+  }
   setKeepImmediatelyConnectedWaysOutsideBounds(
     configOptions.getConvertBoundingBoxKeepImmediatelyConnectedWaysOutsideBounds());
   setWarnOnVersionZeroElement(configOptions.getReaderWarnOnZeroVersionElement());
@@ -164,7 +173,7 @@ void OsmXmlReader::_createNode(const QXmlAttributes& attributes)
   unsigned int timestamp = ElementData::TIMESTAMP_EMPTY;
   if (attributes.value("timestamp") != "")
   {
-    timestamp = OsmUtils::fromTimeString(attributes.value("timestamp"));
+    timestamp = DateTimeUtils::fromTimeString(attributes.value("timestamp"));
   }
   QString user = ElementData::USER_EMPTY;
   if (attributes.value("user") != "")
@@ -246,7 +255,7 @@ void OsmXmlReader::_createWay(const QXmlAttributes& attributes)
   unsigned int timestamp = ElementData::TIMESTAMP_EMPTY;
   if (attributes.value("timestamp") != "")
   {
-    timestamp = OsmUtils::fromTimeString(attributes.value("timestamp"));
+    timestamp = DateTimeUtils::fromTimeString(attributes.value("timestamp"));
   }
   QString user = ElementData::USER_EMPTY;
   if (attributes.value("user") != "")
@@ -315,7 +324,7 @@ void OsmXmlReader::_createRelation(const QXmlAttributes& attributes)
   unsigned int timestamp = ElementData::TIMESTAMP_EMPTY;
   if (attributes.value("timestamp") != "")
   {
-    timestamp = OsmUtils::fromTimeString(attributes.value("timestamp"));
+    timestamp = DateTimeUtils::fromTimeString(attributes.value("timestamp"));
   }
   QString user = ElementData::USER_EMPTY;
   if (attributes.value("user") != "")
@@ -459,7 +468,7 @@ void OsmXmlReader::read(const OsmMapPtr& map)
     LOG_VARD(StringUtils::formatLargeNumber(_map->getElementCount()));
   }
 
-  // Should we be using RemoveMissingElementsVisitor here instead?
+  // If cropping was run with missing element being removed, then this shouldn't be necessary.
   ReportMissingElementsVisitor visitor;
   LOG_INFO("\t" << visitor.getInitStatusMessage());
   _map->visitRw(visitor);
Clone this wiki locally