-
Notifications
You must be signed in to change notification settings - Fork 74
v0.2.48..v0.2.49 changeset OsmXmlReader.cpp
Garret Voltz edited this page Oct 2, 2019
·
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 ec70079..444385b 100644
--- a/hoot-core/src/main/cpp/hoot/core/io/OsmXmlReader.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/io/OsmXmlReader.cpp
@@ -106,13 +106,21 @@ void OsmXmlReader::_parseTimeStamp(const QXmlAttributes &attributes)
void OsmXmlReader::_createNode(const QXmlAttributes& attributes)
{
+ _element.reset();
+
long id = _parseLong(attributes.value("id"));
//LOG_VART(id);
if (_nodeIdMap.contains(id))
{
- throw HootException(
- QString("Duplicate node id %1 in map %2 encountered.").arg(id).arg(_path));
+ if (_ignoreDuplicates)
+ {
+ LOG_TRACE("Ignoring node id " << id << " already exists");
+ return;
+ }
+ else
+ throw HootException(
+ QString("Duplicate node id %1 in map %2 encountered.").arg(id).arg(_path));
}
long newId;
@@ -170,14 +178,24 @@ void OsmXmlReader::_createNode(const QXmlAttributes& attributes)
void OsmXmlReader::_createWay(const QXmlAttributes& attributes)
{
- _wayId = _parseLong(attributes.value("id"));
+ _element.reset();
+
+ long id = _parseLong(attributes.value("id"));
- if (_wayIdMap.contains(_wayId))
+ if (_wayIdMap.contains(id))
{
- throw HootException(
- QString("Duplicate way id %1 in map %2 encountered.").arg(_wayId).arg(_path));
+ if (_ignoreDuplicates)
+ {
+ LOG_TRACE("Ignoring way id " << id << " already exists");
+ return;
+ }
+ else
+ throw HootException(
+ QString("Duplicate way id %1 in map %2 encountered.").arg(_wayId).arg(_path));
}
+ _wayId = id;
+
long newId;
if (_useDataSourceId)
{
@@ -225,15 +243,24 @@ void OsmXmlReader::_createWay(const QXmlAttributes& attributes)
void OsmXmlReader::_createRelation(const QXmlAttributes& attributes)
{
- _relationId = _parseLong(attributes.value("id"));
+ _element.reset();
- // Adding this in causes issues with the tests...worth looking into at some point.
+ long id = _parseLong(attributes.value("id"));
+
+ if (_relationIdMap.contains(id) && _ignoreDuplicates)
+ {
+ LOG_TRACE("Ignoring relation id " << id << " already exists");
+ return;
+ }
+// Adding this in causes issues with the tests...worth looking into at some point.
// if (_relationIdMap.contains(_relationId))
// {
// throw HootException(
// QString("Duplicate relation id %1 in map %2 encountered.").arg(_relationId).arg(_path));
// }
+ _relationId = id;
+
long newId = _getRelationId(_relationId);
// check the next 3 attributes to see if a value exists, if not, assign a default since these are
@@ -283,19 +310,14 @@ bool OsmXmlReader::fatalError(const QXmlParseException &exception)
bool OsmXmlReader::isSupported(const QString& url)
{
- const int numExtensions = 3;
- const QString validExtensions[numExtensions] = { ".osm", ".osm.bz2", ".osm.gz" };
+ QStringList validExtensions = supportedFormats().split(";");
const QString checkString(url.toLower());
-
// support compressed osm files
- for (int i = 0; i < numExtensions; ++i)
+ for (int i = 0; i < validExtensions.size(); ++i)
{
- if (checkString.endsWith(validExtensions[i]) == true)
- {
+ if (checkString.endsWith(validExtensions[i]))
return true;
- }
}
-
// If we fall out of loop, no dice
return false;
}