double WayFeatureExtractor::extract(const OsmMap& map, const shared_ptr<const Element>& target, const shared_ptr<const Element>& candidate) const { vector<double> scores; if (target->getElementType() == ElementType::Way && candidate->getElementType() == ElementType::Way) { scores.push_back(_extract(map, dynamic_pointer_cast<const Way>(target), dynamic_pointer_cast<const Way>(candidate))); } else if (target->getElementType() == ElementType::Relation && candidate->getElementType() == ElementType::Relation) { ConstRelationPtr r1 = dynamic_pointer_cast<const Relation>(target); ConstRelationPtr r2 = dynamic_pointer_cast<const Relation>(candidate); if (r1->getType() == Relation::MULTILINESTRING && r2->getType() == Relation::MULTILINESTRING && r1->getMembers().size() == r2->getMembers().size()) { for (size_t i = 0; i < r1->getMembers().size(); i++) { ElementId eid1 = r1->getMembers()[i].getElementId(); ElementId eid2 = r2->getMembers()[i].getElementId(); if (eid1.getType() != ElementType::Way || eid2.getType() != ElementType::Way) { return nullValue(); } scores.push_back(_extract(map, map.getWay(eid1), map.getWay(eid2))); } } else { return nullValue(); } } else { return nullValue(); } return _agg->aggregate(scores); }
InWayNodeFilter::InWayNodeFilter(FilterType type, const OsmMap& map, const vector<long>& wids) { _type = type; for (size_t i = 0; i < wids.size(); i++) { shared_ptr<const Way> w = map.getWay(wids[i]); const vector<long>& nids = w->getNodeIds(); _nids.insert(nids.begin(), nids.end()); } }