diff --git a/hoot-core/src/main/cpp/hoot/core/elements/OsmUtils.cpp b/hoot-core/src/main/cpp/hoot/core/elements/OsmUtils.cpp
index de488a7..5ca0849 100644
--- a/hoot-core/src/main/cpp/hoot/core/elements/OsmUtils.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/elements/OsmUtils.cpp
@@ -45,6 +45,8 @@
#include <hoot/core/criterion/AttributeValueCriterion.h>
#include <hoot/core/util/StringUtils.h>
#include <hoot/core/criterion/PointCriterion.h>
+#include <hoot/core/visitors/UniqueElementIdVisitor.h>
+#include <hoot/core/criterion/IdTagMatchesId.h>
// Qt
#include <QDateTime>
@@ -274,24 +276,21 @@ long OsmUtils::getFirstWayIdFromRelation(const ConstRelationPtr& relation, const
}
}
-void OsmUtils::logElementDetail(const ConstElementPtr& element, const ConstOsmMapPtr& map,
- const Log::WarningLevel& logLevel, const QString& message)
+QString OsmUtils::getElementDetailString(const ConstElementPtr& element, const ConstOsmMapPtr& map)
{
- if (Log::getInstance().getLevel() <= logLevel)
+ QString str;
+ str += element->toString() + "\n";
+ if (element->getElementType() == ElementType::Way)
{
- LOG_VAR(message);
- LOG_VAR(element);
- if (element->getElementType() == ElementType::Way)
- {
- ConstWayPtr way = std::dynamic_pointer_cast<const Way>(element);
- LOG_VAR(OsmUtils::getWayNodesDetailedString(way, map));
- }
- else if (element->getElementType() == ElementType::Relation)
- {
- ConstRelationPtr relation = std::dynamic_pointer_cast<const Relation>(element);
- LOG_VAR(OsmUtils::getRelationMembersDetailedString(relation, map));
- }
+ ConstWayPtr way = std::dynamic_pointer_cast<const Way>(element);
+ str += OsmUtils::getWayNodesDetailedString(way, map) + "\n";
+ }
+ else if (element->getElementType() == ElementType::Relation)
+ {
+ ConstRelationPtr relation = std::dynamic_pointer_cast<const Relation>(element);
+ str += OsmUtils::getRelationMembersDetailedString(relation, map) + "\n";
}
+ return str;
}
bool OsmUtils::oneWayConflictExists(const ConstElementPtr& element1,
@@ -439,7 +438,7 @@ long OsmUtils::closestWayNodeIdToNode(const ConstNodePtr& node, const ConstWayPt
const vector<long>& wayNodeIds = way->getNodeIds();
for (size_t i = 0; i < wayNodeIds.size(); i++)
{
- ConstNodePtr wayNode = map->getNode(wayNodeIds[i]);;
+ ConstNodePtr wayNode = map->getNode(wayNodeIds[i]);
const double distanceFromNodeToWayNode =
Distance::euclidean(node->toCoordinate(), wayNode->toCoordinate());
if (distanceFromNodeToWayNode < shortestDistance)
@@ -522,6 +521,35 @@ bool OsmUtils::isChild(const ElementId& elementId, const ConstOsmMapPtr& map)
return false;
}
+bool OsmUtils::allElementIdsPositive(const ConstOsmMapPtr& map)
+{
+ std::shared_ptr<AttributeValueCriterion> attrCrit(
+ new AttributeValueCriterion(
+ ElementAttributeType(ElementAttributeType::Id), 1, NumericComparisonType::LessThan));
+ return
+ (int)FilteredVisitor::getStat(
+ attrCrit, std::shared_ptr<ElementCountVisitor>(new ElementCountVisitor()), map) == 0;
+}
+
+bool OsmUtils::allElementIdsNegative(const ConstOsmMapPtr& map)
+{
+ std::shared_ptr<AttributeValueCriterion> attrCrit(
+ new AttributeValueCriterion(
+ ElementAttributeType(ElementAttributeType::Id), -1, NumericComparisonType::GreaterThan));
+ return
+ (int)FilteredVisitor::getStat(
+ attrCrit, std::shared_ptr<ElementCountVisitor>(new ElementCountVisitor()), map) == 0;
+}
+
+bool OsmUtils::allIdTagsMatchIds(const ConstOsmMapPtr& map)
+{
+ std::shared_ptr<IdTagMatchesId> idCrit(new IdTagMatchesId());
+ return
+ (int)FilteredVisitor::getStat(
+ idCrit, std::shared_ptr<ElementCountVisitor>(new ElementCountVisitor()), map) ==
+ (int)map->size();
+}
+
int OsmUtils::versionLessThanOneCount(const OsmMapPtr& map)
{
std::shared_ptr<AttributeValueCriterion> attrCrit(
@@ -532,7 +560,7 @@ int OsmUtils::versionLessThanOneCount(const OsmMapPtr& map)
attrCrit, std::shared_ptr<ElementCountVisitor>(new ElementCountVisitor()), map);
}
-void OsmUtils::checkVersionLessThanOneCountAndLogWarning(const OsmMapPtr& map)
+bool OsmUtils::checkVersionLessThanOneCountAndLogWarning(const OsmMapPtr& map)
{
const int numberOfRefElementsWithVersionLessThan1 = OsmUtils::versionLessThanOneCount(map);
if (numberOfRefElementsWithVersionLessThan1 > 0)
@@ -541,8 +569,20 @@ void OsmUtils::checkVersionLessThanOneCountAndLogWarning(const OsmMapPtr& map)
StringUtils::formatLargeNumber(numberOfRefElementsWithVersionLessThan1) << " features in " <<
"the reference map have a version less than one. This could lead to difficulties when " <<
"applying the resulting changeset back to an authoritative data store. Are the versions " <<
- "on the features being populated correctly?")
+ "on the features being populated correctly?");
+ return true;
}
+ return false;
+}
+
+std::set<ElementId> OsmUtils::getIdsOfElementsWithVersionLessThanOne(const OsmMapPtr& map)
+{
+ AttributeValueCriterion attrCrit(
+ ElementAttributeType(ElementAttributeType::Version), 1, NumericComparisonType::LessThan);
+ UniqueElementIdVisitor idSetVis;
+ FilteredVisitor filteredVis(attrCrit, idSetVis);
+ map->visitRo(filteredVis);
+ return idSetVis.getElementSet();
}
bool OsmUtils::mapIsPointsOnly(const OsmMapPtr& map)