void ReportMissingElementsVisitor::_visitRo(ElementType type, long id) { if (type == ElementType::Way) { const shared_ptr<const Way>& w = _map->getWay(id); for (size_t i = 0; i < w->getNodeCount(); i++) { if (_map->containsNode(w->getNodeIds()[i]) == false) { _reportMissing(ElementId(type, id), ElementId::node(w->getNodeIds()[i])); } } } else if (type == ElementType::Relation) { const shared_ptr<const Relation>& r = _map->getRelation(id); for (size_t i = 0; i < r->getMembers().size(); i++) { const RelationData::Entry& e = r->getMembers()[i]; if (_map->containsElement(e.getElementId()) == false) { _reportMissing(ElementId(type, id), e.getElementId()); } } } }
set<ElementId> WayMergeManipulation::getMatchedElements() const { set<ElementId> result; result.insert(ElementId(ElementType::Way, _left)); result.insert(ElementId(ElementType::Way, _right)); return result; }
void IeLinkMetricReport::Print (std::ostream& os) const { os << std::endl << "<information_element id=" << ElementId () << ">" << std::endl; os << "Metric = " << m_metric; os << "</information_element>" << std::endl; }
double WayMergeManipulation::_calculateExpertProbability(ConstOsmMapPtr map) const { OsmMapPtr theMap(new OsmMap()); CopyMapSubsetOp(map, ElementId(ElementType::Way, _left), ElementId(ElementType::Way, _right)).apply(theMap); WayPtr left = theMap->getWay(_left); WayPtr right = theMap->getWay(_right); // use the maximal nearest subline code to find the best subline WayPtr mnsLeft = MaximalNearestSubline::getMaximalNearestSubline(theMap, left, right, _minSplitSize, left->getCircularError() + right->getCircularError()); if (mnsLeft == 0) { return 0.0; } WayPtr mnsRight = MaximalNearestSubline::getMaximalNearestSubline(theMap, right, mnsLeft, _minSplitSize, left->getCircularError() + right->getCircularError()); if (mnsRight == 0) { return 0.0; } // what portion of the original lines is the MNS double pl = ElementConverter(theMap).convertToLineString(mnsLeft)->getLength() / ElementConverter(theMap).convertToLineString(left)->getLength(); double pr = ElementConverter(theMap).convertToLineString(mnsRight)->getLength() / ElementConverter(theMap).convertToLineString(right)->getLength(); // give it a score double ps = std::min(pl, pr) / 2.0 + 0.5; double p; // if either of the lines are zero in length. if (pl == 0 || pr == 0) { p = 0.0; } else { p = ps * ProbabilityOfMatch::getInstance().expertProbability(theMap, mnsLeft, mnsRight); } return p; }
void PertyRemoveRandomElementVisitor::visit(const ConstElementPtr& e) { boost::uniform_real<> uni(0.0, 1.0); if (uni(*_rng) <= _p) { RecursiveElementRemover(ElementId(e->getElementType(), e->getId())).apply(_map->shared_from_this()); } }
void ReportMissingElementsVisitor::_visitRw(ElementType type, long id) { if (type == ElementType::Way) { const shared_ptr<Way>& w = _map->getWay(id); vector<long> newNids; newNids.reserve(w->getNodeCount()); for (size_t i = 0; i < w->getNodeCount(); i++) { if (_map->containsNode(w->getNodeIds()[i]) == false) { _reportMissing(ElementId(type, id), ElementId::node(w->getNodeIds()[i])); } else { newNids.push_back(w->getNodeIds()[i]); } } if (newNids.size() != w->getNodeCount()) { w->setNodes(newNids); } } else if (type == ElementType::Relation) { const shared_ptr<Relation>& r = _map->getRelation(id); vector<RelationData::Entry> newEntries; newEntries.reserve(r->getMembers().size()); for (size_t i = 0; i < r->getMembers().size(); i++) { const RelationData::Entry& e = r->getMembers()[i]; if (_map->containsElement(e.getElementId()) == false) { _reportMissing(ElementId(type, id), e.getElementId()); } else { newEntries.push_back(e); } } if (newEntries.size() != r->getMembers().size()) { r->setMembers(newEntries); } } }
set<ElementId> OsmMapIndex::findWayRelations(const Envelope& e) const { set<ElementId> result; const ElementToRelationMap& e2r = *getElementToRelationMap(); vector<long> wids = findWays(e); for (size_t i = 0; i < wids.size(); i++) { result.insert(ElementId(ElementType::Way, wids[i])); const set<long>& relations = e2r.getRelationByElement(ElementId::way(wids[i])); for (set<long>::const_iterator it = relations.begin(); it != relations.end(); ++it) { result.insert(ElementId(ElementType::Relation, *it)); } } return result; }
void IePerr::Print (std::ostream &os) const { os << std::endl << "<information_element id=" << ElementId () << ">" << std::endl; os << "Number of failed destinations: = " << m_addressUnits.size (); for (unsigned int j = 0; j < m_addressUnits.size (); j++) { os << "Failed destination address: = " << m_addressUnits[j].destination << ", sequence number = " << m_addressUnits[j].seqnum; } os << std::endl << "</information_element>" << std::endl; }
const set<ElementId>& WayMergeManipulation::getImpactedElementIds(const ConstOsmMapPtr& map) const { _impactedElements.clear(); const set<long>& wids = getImpactedWayIds(map); for (set<long>::const_iterator it = wids.begin(); it != wids.end(); ++it) { _impactedElements.insert(ElementId(ElementType::Way, *it)); } return _impactedElements; }
// ----------------------------------------------------------------------------- // CapParser::ParseElement(const TDesC& aText, TInt& aId, TInt& aType) // Parses element's id and type (eg. "<Memory>" -> EMemory, EElementBegin) // ----------------------------------------------------------------------------- // void CapParser::ParseElement(const TDesC& aText, TInt& aId, TInt& aType) { TXmlParser parse; aId=KErrNotFound; parse.Set(aText); aType=parse.Type(); if (aType==TXmlParser::EElementUnknown) { return; } TPtrC ptr=parse.Tag(); aId=ElementId(ptr); }
void RemoveElementsVisitor::visit(const ConstElementPtr& e) { assert(_filter); ElementType type = e->getElementType(); long id = e->getId(); const shared_ptr<Element>& ee = _map->getElement(type, id); if (_filter->isSatisfied(ee)) { if (_recursive) { RecursiveElementRemover(ee->getElementId()).apply(_map->shared_from_this()); } else { _map->removeElement(ElementId(type, id)); } } }
bool ContainsNodeCriterion::isSatisfied(const ConstElementPtr& e) const { if (e->getElementType() == ElementType::Way) { ConstWayPtr w = boost::dynamic_pointer_cast<const Way>(e); return w->hasNode(_nodeId); } else if (e->getElementType() == ElementType::Relation) { ConstRelationPtr r = boost::dynamic_pointer_cast<const Relation>(e); return r->contains(ElementId(ElementType::Node, _nodeId)); } else if (e->getElementType() == ElementType::Node) { ConstNodePtr n = boost::dynamic_pointer_cast<const Node>(e); return (n->getId() == _nodeId); } return false; }
void RemoveRef2Visitor::visit(const ConstElementPtr& e) { if (!_criterion) { throw IllegalArgumentException("You must specify a criterion before calling " "RemoveRef2Visitor."); } ElementType type = e->getElementType(); long id = e->getId(); ElementPtr ee = _map->getElement(ElementId(type, id)); // if e has a REF2 and meets the criterion if (_hasRef2Tag(ee) && _criterion->isSatisfied(ee)) { // go through each REF2 and evaluate for deletion for (int i = 0; i < _ref2Keys.size(); i++) { _checkAndDeleteRef2(ee, _ref2Keys[i]); } } }
vector<RelationData::Entry> OsmApiDb::selectMembersForRelation(long relationId) { vector<RelationData::Entry> result; if (!_selectMembersForRelation) { _selectMembersForRelation.reset(new QSqlQuery(_db)); _selectMembersForRelation->setForwardOnly(true); _selectMembersForRelation->prepare( "SELECT member_type, member_id, member_role FROM " + _getRelationMembersTableName() + " WHERE relation_id = :relationId ORDER BY sequence_id"); } _selectMembersForRelation->bindValue(":relationId", (qlonglong)relationId); if (_selectMembersForRelation->exec() == false) { throw HootException("Error selecting members for relation with ID: " + QString::number(relationId) + " Error: " + _selectMembersForRelation->lastError().text()); } while (_selectMembersForRelation->next()) { const QString memberType = _selectMembersForRelation->value(0).toString(); if (ElementType::isValidTypeString(memberType)) { result.push_back( RelationData::Entry( _selectMembersForRelation->value(2).toString(), ElementId(ElementType::fromString(memberType), _selectMembersForRelation->value(1).toLongLong()))); } else { LOG_WARN("Invalid relation member type: " + memberType + ". Skipping relation member."); } } return result; }
INLINE ElementIterator end () const { return ElementIterator(fes, ElementId(vb,Next()), temp_dnums); }
INLINE ElementIterator begin () const { return ElementIterator(fes, ElementId(vb,First()), temp_dnums); }
void ServicesDbWriter::writePartial(const shared_ptr<const Relation>& r) { long relationId; //LOG_DEBUG("Inside writePartial for Relation"); Tags tags = r->getTags(); if ( _sdb.getDatabaseType() == ServicesDb::DBTYPE_SERVICES) { _addElementTags(r, tags); } if (!r->getType().isEmpty()) { tags["type"] = r->getType(); } if (_remapIds) { relationId = _getRemappedElementId(r->getElementId()); LOG_DEBUG("Inserting relation with source ID = " << QString::number(r->getId()) << " which maps to DB ID = " << QString::number(relationId) ); _sdb.insertRelation(relationId, tags); } else { if (r->getId() < 1) { throw HootException("Non-positive IDs are not supported by ServicesDbWriter without remapping"); } _sdb.insertRelation(r->getId(), tags); relationId = r->getId(); } Tags emptyTags; for (size_t i = 0; i < r->getMembers().size(); ++i) { RelationData::Entry e = r->getMembers()[i]; // May need to create new ID mappings for items we've not yet seen ElementId relationMemberElementId = e.getElementId(); if ( _remapIds == true ) { relationMemberElementId = ElementId(relationMemberElementId.getType(), _getRemappedElementId(relationMemberElementId)); } _sdb.insertRelationMember(relationId, relationMemberElementId.getType(), relationMemberElementId.getId(), e.role, i); } //LOG_DEBUG("All members added to relation " << QString::number(relationId)); _countChange(); //LOG_DEBUG("Leaving relation write cleanly"); _relationsWritten++; }
void Relation::addElement(const QString& role, ElementType t, long id) { addElement(role, ElementId(t, id)); }