bool WayCleaner::hasDuplicateCoords(ConstWayPtr way, const OsmMap& map, const bool logDetails) { const vector<long> nodeIds = way->getNodeIds(); if (nodeIds.size() == 2 && map.getNode(nodeIds.at(0))->toCoordinate() == map.getNode(nodeIds.at(1))->toCoordinate()) { if (logDetails) { LOG_WARN( "Duplicate coordinate " << map.getNode(nodeIds.at(0))->toCoordinate() << " for node with ID:'s " << nodeIds[0] << " and " << nodeIds[1] << " found at indexes 0 and 1; For way with ID: " << way->getElementId().getId()); LOG_VARW(nodeIds); } return true; } bool found = false; QList<Coordinate> coords; for (size_t i = 0; i < nodeIds.size(); i++) { const Coordinate coord = map.getNode(nodeIds[i])->toCoordinate(); if (coords.contains(coord)) { //the only duplicated coords allowed are the first and last for a closed way, if the node ID's //match if (i == (nodeIds.size() - 1) && nodeIds[0] == nodeIds[i]) { found = false; } else { found = true; } if (found) { if (logDetails) { LOG_WARN( "Duplicate coord " << map.getNode(nodeIds[i])->toCoordinate() << " for node with ID: " << nodeIds[i] << " found at index: " << i << " For way with ID: " << way->getElementId().getId()); LOG_VARW(nodeIds); } return found; } } else { coords.append(coord); } } return found; }
WaySubline::WaySubline(const WayLocation& start, const WayLocation& end) : _start(start), _end(end) { assert(_start.getWay() == _end.getWay()); if (_start > _end) { LOG_VARW(start); LOG_VARW(end); throw IllegalArgumentException("Start must be <= end."); } }
bool WayCleaner::hasDuplicateNodes(ConstWayPtr way, const bool logDetails) { const vector<long> nodeIds = way->getNodeIds(); if (nodeIds.size() == 2 && nodeIds.at(0) == nodeIds.at(1)) { if (logDetails) { LOG_WARN( "Duplicate node with ID: " << nodeIds[0] << " found at indexes 0 and 1; For way with ID: " << way->getElementId().getId()); LOG_VARW(nodeIds); } return true; } bool found = false; QList<long> nodeIdsTemp; for (size_t i = 0; i < nodeIds.size(); i++) { if (nodeIdsTemp.contains(nodeIds[i])) { //the only duplicated nodes allowed are the first and last for a closed way if (i == (nodeIds.size() - 1) && nodeIds[0] == nodeIds[i]) { found = false; } else { found = true; } if (found) { if (logDetails) { LOG_WARN( "Duplicate node with ID: " << nodeIds[i] << " found at index: " << i << " For way with ID: " << way->getElementId().getId()); LOG_VARW(nodeIds); } return found; } } else { nodeIdsTemp.append(nodeIds[i]); } } return found; }
void MultiaryPoiMerger::apply(const OsmMapPtr& map, std::vector< std::pair<ElementId, ElementId> >& replaced) { // find the appropriate match creator for calculating scores between clusters std::vector< boost::shared_ptr<MatchCreator> > matchCreators = MatchFactory::getInstance(). getCreators(); foreach (boost::shared_ptr<MatchCreator> mc, matchCreators) { if (mc->isMatchCandidate(map->getElement(_pairs.begin()->first), map)) { if (_matchCreator.get()) { LOG_VARW(_matchCreator->getDescription()); LOG_VARW(mc->getDescription()); throw HootException("Expected only a single match creator to be a candidate for the given " "element. This method may need to be more restrictive, or you may need to reduce your " "list of match creators."); } _matchCreator = mc; } } // find the appropriate merger creator for merging elements in clusters foreach (const CreatorDescription& d, MergerFactory::getInstance().getAllAvailableCreators()) { // ugh. Magic string. To work around this we'll need to link against hoot-js, or find another // way to add that dep. if (d.className == "hoot::ScriptMergerCreator") { _mergerCreator.reset(Factory::getInstance().constructObject<MergerCreator>(d.className)); } } MultiaryScoreCachePtr score(new MultiaryScoreCache(map, _matchCreator)); MultiaryPoiMergeCachePtr merge(new MultiaryPoiMergeCache(map, _matchCreator, _mergerCreator)); MultiaryHierarchicalClusterAlgorithm clusterer(merge, score, _matchCreator->getMatchThreshold()->getMissThreshold()); MultiaryClusterAlgorithm::ClusterList clusters = clusterer.calculateClusters(map, _pairs); QList<MultiaryClusterAlgorithm::ClusterLinkPtr> reviews = clusterer.takeReviews(); _mergeClusters(map, replaced, clusters); _createReviews(map, reviews); }
long SequenceIdReserver::_reserveIds() { if (_query == 0) { _query.reset(new QSqlQuery(_db)); _query->setForwardOnly(true); //// // This query contains a race condition. It is possible that one process could call SETVAL // between the call to CURRVAL and SETVAL. This can result in a smaller value than expected // and duplicate IDs. See #3607 for details. // LOG_WARN("This query contains a race condition and may not do what you want."); _query->prepare( QString("SELECT NEXTVAL('%1'), " "SETVAL('%1', CURRVAL('%1') + :count)").arg(_sequenceName)); } _query->bindValue(0, (qlonglong)_bulkSize - 1); if (_query->exec() == false) { throw HootException("Error reserving IDs. count: " + QString::number(_bulkSize) + " Error: " + _query->lastError().text()); } long result = -1; if (_query->next()) { bool ok; result = _query->value(1).toLongLong(&ok); if (!ok) { throw HootException("Did not retrieve starting reserved ID."); } } else { LOG_VARW(_nextId); LOG_VARW(result); LOG_VARW(_bulkSize); throw HootException("Error retrieving sequence value. count: " + QString::number(_bulkSize) + " Error: " + _query->lastError().text()); } if (result < _nextId) { LOG_VARW(_nextId); LOG_VARW(result); LOG_VARW(_bulkSize); QString err = QString("Error allocating new sequence value. Expected to retrieve a value " ">= %1, but got %2.").arg(_nextId).arg(result); LOG_WARN(err); throw HootException(err); } _query->finish(); return result; }