void runRoadsTest() { //test highway (linestring) OsmMapPtr map(new OsmMap()); _map = map; WayPtr w1(new Way(Status::Unknown1, map->createNextWayId(), 13.0)); w1->setTag("highway", "track"); w1->setTag("name", "w1"); w1->addNode(createNode(-104.9, 38.855)->getId()); w1->addNode(createNode(-104.899, 38.8549)->getId()); _map->addWay(w1); WayPtr w2(new Way(Status::Unknown1, map->createNextWayId(), 13.0)); w2->setTag("highway", "road"); w2->setTag("name", "w2"); w2->addNode(createNode(-104.91, 38.8548)->getId()); w2->addNode(createNode(-104.8993, 38.8548)->getId()); _map->addWay(w2); CentroidDistanceExtractor uut; const OsmMap* constMap = const_cast<const OsmMap*>(_map.get()); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.00515218, uut.distance(*constMap, boost::const_pointer_cast<const Way>(w1), boost::const_pointer_cast<const Way>(w2)), 0.000001); }
void RemoveRelationOp::apply(OsmMapPtr& map) { if (_rIdToRemove == -std::numeric_limits<int>::max()) { throw IllegalArgumentException("No relation ID specified for RemoveRelationOp."); } if (map->_relations.find(_rIdToRemove) != map->_relations.end()) { // determine if this relation is a part of any other relations // make a copy of the rids in case the index gets changed. const set<long> rids = map->_index->getElementToRelationMap()->getRelationByElement( ElementId::relation(_rIdToRemove)); // remove this relation from all other parent relations. for (set<long>::const_iterator it = rids.begin(); it != rids.end(); ++it) { const long parentRelationId = *it; LOG_TRACE("Removing relation: " << _rIdToRemove << " from relation: " << parentRelationId); map->getRelation(parentRelationId)->removeElement(ElementId::relation(_rIdToRemove)); } map->_index->removeRelation(map->getRelation(_rIdToRemove)); map->_relations.erase(_rIdToRemove); VALIDATE(map->validate()); } }
OsmMapPtr AlphaShapeGenerator::generateMap(OsmMapPtr inputMap) { boost::shared_ptr<Geometry> cutterShape = generateGeometry(inputMap); if (cutterShape->getArea() == 0.0) { //would rather this be thrown than a warning logged, as the warning may go unoticed by web //clients who are expecting the alpha shape to be generated throw HootException("Alpha Shape area is zero. Try increasing the buffer size and/or alpha."); } OsmMapPtr result; result.reset(new OsmMap(inputMap->getProjection())); // add the resulting alpha shape for debugging. GeometryConverter(result).convertGeometryToElement(cutterShape.get(), Status::Invalid, -1); const RelationMap& rm = result->getRelations(); for (RelationMap::const_iterator it = rm.begin(); it != rm.end(); ++it) { Relation* r = result->getRelation(it->first).get(); r->setTag("area", "yes"); } return result; }
boost::shared_ptr<Geometry> AlphaShapeGenerator::generateGeometry(OsmMapPtr inputMap) { MapProjector::projectToPlanar(inputMap); // put all the nodes into a vector of points. std::vector< std::pair<double, double> > points; points.reserve(inputMap->getNodes().size()); const NodeMap& nodes = inputMap->getNodes(); for (NodeMap::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { pair<double, double> p; p.first = (it->second)->getX(); p.second = (it->second)->getY(); points.push_back(p); } // create a complex geometry representing the alpha shape boost::shared_ptr<Geometry> cutterShape; { AlphaShape alphaShape(_alpha); alphaShape.insert(points); cutterShape = alphaShape.toGeometry(); cutterShape.reset(cutterShape->buffer(_buffer)); } return cutterShape; }
void UnifyingConflator::_addReviewTags(const OsmMapPtr& map, const vector<const Match*>& matches) { if (ConfigOptions(_settings).getConflateAddScoreTags()) { for (size_t i = 0; i < matches.size(); i++) { const Match* m = matches[i]; const MatchClassification& mc = m->getClassification(); set< pair<ElementId, ElementId> > pairs = m->getMatchPairs(); for (set< pair<ElementId, ElementId> >::const_iterator it = pairs.begin(); it != pairs.end(); ++it) { if (mc.getReviewP() > 0.0) { ElementPtr e1 = map->getElement(it->first); ElementPtr e2 = map->getElement(it->second); _addScoreTags(e1, mc); _addScoreTags(e2, mc); e1->getTags().appendValue(scoreUuidKey(), e2->getTags().getCreateUuid()); e2->getTags().appendValue(scoreUuidKey(), e1->getTags().getCreateUuid()); } } } } }
void MatchScoringMapPreparer::prepMap(OsmMapPtr map, const bool removeNodes) { // if an element has a uuid, but no REF1/REF2 tag then create a REF tag with the uuid. The // 1/2 is determined by the unknown status. ConvertUuidToRefVisitor convertUuidToRef; map->visitRw(convertUuidToRef); // #5891 if the feature is marked as todo then there is no need to conflate & evaluate it. shared_ptr<TagCriterion> isTodo(new TagCriterion("REF2", "todo")); RemoveElementsVisitor remover(isTodo); remover.setRecursive(true); map->visitRw(remover); // add a uuid to all elements with a REF tag. HasTagCriterion criterion("REF1", "REF2", "REVIEW"); AddUuidVisitor uuid("uuid"); FilteredVisitor v(criterion, uuid); map->visitRw(v); if (removeNodes) { // remove all REF1/REF2 tags from the nodes. RemoveTagVisitor removeRef("REF1", "REF2"); IsNodeFilter nodeFilter(Filter::KeepMatches); FilteredVisitor removeRefV(nodeFilter, removeRef); map->visitRw(removeRefV); } //MapCleaner().apply(map); }
void runCombineMapTest() { OsmXmlReader reader; OsmMapPtr referenceMap(new OsmMap()); reader.setDefaultStatus(Status::Unknown1); reader.setUseDataSourceIds(true); reader.read( inputPath + "PertyMatchScorerTest-reference-out-1.osm", referenceMap); CPPUNIT_ASSERT_EQUAL(44, (int)referenceMap->getElementCount()); PertyMatchScorer matchScorer; matchScorer.setSearchDistance(15.0); matchScorer.setApplyRubberSheet(false); OsmMapPtr combinedMap = matchScorer._combineMapsAndPrepareForConflation( referenceMap, inputPath + "PertyMatchScorerTest-perturbed-out-1.osm"); //can't do a file comparison on the output here since the UUID's added to the file will be //different with each run CPPUNIT_ASSERT_EQUAL(100, (int)combinedMap->getElementCount()); boost::shared_ptr<TagKeyCountVisitor> tagKeyCountVisitorRef1(new TagKeyCountVisitor(MetadataTags::Ref1())); combinedMap->visitRo(*tagKeyCountVisitorRef1); CPPUNIT_ASSERT_EQUAL(8, (int)tagKeyCountVisitorRef1->getStat()); boost::shared_ptr<TagKeyCountVisitor> tagKeyCountVisitorRef2(new TagKeyCountVisitor(MetadataTags::Ref2())); combinedMap->visitRo(*tagKeyCountVisitorRef2); CPPUNIT_ASSERT_EQUAL(10, (int)tagKeyCountVisitorRef2->getStat()); }
void CookieCutter::cut(OsmMapPtr cutterShapeMap, OsmMapPtr doughMap) { OGREnvelope env = cutterShapeMap->calculateBounds(); env.Merge(doughMap->calculateBounds()); // reproject the dough and cutter into the same planar projection. MapReprojector::reprojectToPlanar(doughMap, env); MapReprojector::reprojectToPlanar(cutterShapeMap, env); // create a complex geometry representing the alpha shape UnionPolygonsVisitor v; cutterShapeMap->visitRo(v); shared_ptr<Geometry> cutterShape = v.getUnion(); if (_outputBuffer != 0.0) { cutterShape.reset(cutterShape->buffer(_outputBuffer)); } if (cutterShape->getArea() == 0.0) { LOG_WARN("Cutter area is zero. Try increasing the buffer size or check the input."); } // free up a little RAM cutterShapeMap.reset(); // remove the cookie cutter portion from the "dough" // if crop is true, then the cookie cutter portion is kept and the "dough" is dropped. MapCropper::crop(doughMap, cutterShape, !_crop); // clean up any ugly bits left over SuperfluousWayRemover::removeWays(doughMap); SuperfluousNodeRemover::removeNodes(doughMap); }
void tagKeyCountTest() { OsmMapPtr map = _loadMap(); boost::shared_ptr<TagKeyCountVisitor> visitor(new TagKeyCountVisitor("source")); map->visitRo(*visitor); CPPUNIT_ASSERT_EQUAL((long)6, (long)visitor->getStat()); }
void WayMergeManipulation::addBogusReviewTags(const OsmMapPtr& map) const { assert(isValid(map)); ElementPtr left = map->getWay(_left); ElementPtr right = map->getWay(_right); QString note("The review scores on this way are bogus. See #3242."); ReviewMarker().mark(map, left, right, note, "Bogus", getBogusReviewScore()); }
RelationPtr GeometryConverter::convertPolygonToRelation(const Polygon* polygon, const OsmMapPtr& map, Status s, double circularError) { RelationPtr r(new Relation(s, map->createNextRelationId(), circularError, MetadataTags::RelationMultiPolygon())); convertPolygonToRelation(polygon, map, r, s, circularError); map->addRelation(r); return r; }
NodePtr GeometryConverter::_createNode(const OsmMapPtr& map, const Coordinate& c, Status s, double circularError) { if (_nf == 0) { NodePtr n = NodePtr(new Node(s, map->createNextNodeId(), c, circularError)); map->addNode(n); return n; } else { return _nf->createNode(map, c, s, circularError); } }
RelationPtr GeometryConverter::convertMultiPolygonToRelation(const MultiPolygon* mp, const OsmMapPtr& map, Status s, double circularError) { RelationPtr r( new Relation( s, map->createNextRelationId(), circularError, MetadataTags::RelationMultiPolygon())); for (size_t i = 0; i < mp->getNumGeometries(); i++) { convertPolygonToRelation( dynamic_cast<const Polygon*>(mp->getGeometryN(i)), map, r, s, circularError); } map->addRelation(r); return r; }
void PertyDuplicatePoiOp::duplicateNode(const NodePtr& n, const OsmMapPtr& map) { boost::normal_distribution<> nd; boost::variate_generator<boost::minstd_rand&, boost::normal_distribution<> > N(*_rng, nd); Meters sigma = n->getCircularError() / 2.0; double x = n->getX() + N() * sigma * _moveMultiplier; double y = n->getY() + N() * sigma * _moveMultiplier; NodePtr newNode(new Node(n->getStatus(), map->createNextNodeId(), x, y, n->getCircularError())); map->addNode(newNode); }
WayPtr WaySubline::toWay(const OsmMapPtr& map, GeometryConverter::NodeFactory* nf) const { ConstWayPtr way = _start.getWay(); auto_ptr<GeometryConverter::NodeFactory> nfPtr; if (nf == 0) { nf = new FindNodesInWayFactory(way); // delete it automatically. nfPtr.reset(nf); } WayPtr result(new Way(way->getStatus(), map->createNextWayId(), way->getCircularError())); result->setTags(way->getTags()); int includedStartIndex = _start.getSegmentIndex(); if (_start.getSegmentFraction() > 0.0) { includedStartIndex += 1; } int includedEndIndex = _end.getSegmentIndex(); if (_end.getSegmentFraction() >= 1.0) { includedEndIndex += 1; } if (!_start.isNode()) { Coordinate c = _start.getCoordinate(); shared_ptr<Node> n = nf->createNode(map, c, way->getStatus(), way->getCircularError()); map->addNode(n); result->addNode(n->getId()); } for (int i = includedStartIndex; i <= includedEndIndex; i++) { result->addNode(way->getNodeId(i)); } if (!_end.isNode()) { Coordinate c = _end.getCoordinate(); shared_ptr<Node> n = nf->createNode(map, c, way->getStatus(), way->getCircularError()); map->addNode(n); result->addNode(n->getId()); } return result; }
void tagRenameKeyTest() { OsmMapPtr map = _loadMap(); TagRenameKeyVisitor visitor("source", "source_modified"); map->visitRw(visitor); boost::shared_ptr<TagKeyCountVisitor> keyCountVisitor1(new TagKeyCountVisitor("source")); map->visitRo(*keyCountVisitor1); CPPUNIT_ASSERT_EQUAL((long)0, (long)keyCountVisitor1->getStat()); boost::shared_ptr<TagKeyCountVisitor> keyCountVisitor2(new TagKeyCountVisitor("source_modified")); map->visitRo(*keyCountVisitor2); CPPUNIT_ASSERT_EQUAL((long)6, (long)keyCountVisitor2->getStat()); }
Meters CalculateAreaForStatsVisitor::getArea(const OsmMapPtr& map, ElementPtr e) { CalculateAreaForStatsVisitor v; v.setOsmMap(map.get()); e->visitRo(*map, v); return v.getArea(); }
void MergerFactory::createMergers(const OsmMapPtr& map, const MatchSet& matches, vector<Merger*>& result) const { for (size_t i = 0; i < _creators.size(); i++) { OsmMapConsumer* omc = dynamic_cast<OsmMapConsumer*>(_creators[i]); if (omc) { omc->setOsmMap(map.get()); } if (_creators[i]->createMergers(matches, result)) { return; } // we don't want the creators to hold onto a map pointer that will go out of scope if (omc) { omc->setOsmMap((OsmMap*)0); } } LOG_WARN("Error finding Mergers for these matches: " << matches); LOG_WARN("Creators: " << _creators); throw HootException("Error creating a merger for the provided set of matches."); }
bool WayMergeManipulation::_directConnect(const OsmMapPtr& map, WayPtr w) const { boost::shared_ptr<LineString> ls = ElementConverter(map).convertToLineString(w); CoordinateSequence* cs = GeometryFactory::getDefaultInstance()->getCoordinateSequenceFactory()-> create(2, 2); cs->setAt(map->getNode(w->getNodeId(0))->toCoordinate(), 0); cs->setAt(map->getNode(w->getLastNodeId())->toCoordinate(), 1); // create a straight line and buffer it boost::shared_ptr<LineString> straight(GeometryFactory::getDefaultInstance()->createLineString(cs)); boost::shared_ptr<Geometry> g(straight->buffer(w->getCircularError())); // is the way in question completely contained in the buffer? return g->contains(ls.get()); }
void PertyMatchScorer::_saveMap(OsmMapPtr map, QString path) { BuildingOutlineUpdateOp().apply(map); LOG_VARD(map->getNodeMap().size()); LOG_VARD(map->getWays().size()); if (Log::getInstance().getLevel() <= Log::Debug) { TagCountVisitor tagCountVisitor; map->visitRo(tagCountVisitor); const long numTotalTags = (long)tagCountVisitor.getStat(); LOG_VARD(numTotalTags); } MapProjector::projectToWgs84(map); OsmUtils::saveMap(map, path); }
OsmMapPtr AlphaShapeGenerator::generate(OsmMapPtr cutterShapeMap) { MapProjector::projectToPlanar(cutterShapeMap); // put all the nodes into a vector of points. std::vector< std::pair<double, double> > points; points.reserve(cutterShapeMap->getNodeMap().size()); const NodeMap& nodes = cutterShapeMap->getNodeMap(); for (NodeMap::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { pair<double, double> p; p.first = (it->second)->getX(); p.second = (it->second)->getY(); points.push_back(p); } // create a complex geometry representing the alpha shape shared_ptr<Geometry> cutterShape; { AlphaShape alphaShape(_alpha); alphaShape.insert(points); cutterShape = alphaShape.toGeometry(); cutterShape.reset(cutterShape->buffer(_buffer)); } if (cutterShape->getArea() == 0.0) { LOG_WARN("Alpha Shape area is zero. Try increasing the buffer size and/or alpha."); } shared_ptr<OsmMap> result; result.reset(new OsmMap(cutterShapeMap->getProjection())); // add the resulting alpha shape for debugging. GeometryConverter(result).convertGeometryToElement(cutterShape.get(), Status::Invalid, -1); const RelationMap& rm = result->getRelationMap(); for (RelationMap::const_iterator it = rm.begin(); it != rm.end(); ++it) { Relation* r = result->getRelation(it->first).get(); r->setTag("area", "yes"); } return result; }
void runIsCandidateTest() { PoiPolygonMatchCreator uut; OsmMapPtr map = getTestMap1(); CPPUNIT_ASSERT( uut.isMatchCandidate(map->getNode(FindNodesVisitor::findNodesByTag(map, "name", "foo")[0]), map)); CPPUNIT_ASSERT( uut.isMatchCandidate(map->getWay(FindWaysVisitor::findWaysByTag(map, "name", "foo")[0]), map)); OsmXmlReader reader; map.reset(new OsmMap()); reader.setDefaultStatus(Status::Unknown1); reader.read("test-files/ToyTestA.osm", map); MapProjector::projectToPlanar(map); CPPUNIT_ASSERT( !uut.isMatchCandidate(map->getWay(FindWaysVisitor::findWaysByTag(map, "note", "1")[0]), map)); }
WayPtr GeometryConverter::convertLineStringToWay(const LineString* ls, const OsmMapPtr& map, Status s, double circularError) { WayPtr way; if (ls->getNumPoints() > 0) { Coordinate c = ls->getCoordinateN(0); way.reset(new Way(s, map->createNextWayId(), circularError)); for (size_t i = 0; i < ls->getNumPoints(); i++) { c = ls->getCoordinateN(i); way->addNode(_createNode(map, c, s, circularError)->getId()); } map->addWay(way); } return way; }
void MapStatsMapper::_map(OsmMapPtr& m, HadoopPipes::MapContext& context) { _context = &context; const NodeMap& nm = m->getNodes(); for (NodeMap::const_iterator it = nm.begin(); it != nm.end(); ++it) { const ConstNodePtr& n = it->second; _stats.expandNodeRange(n); _nodeCount++; } const WayMap& wm = m->getWays(); for (WayMap::const_iterator it = wm.begin(); it != wm.end(); ++it) { const ConstWayPtr& w = it->second; _stats.expandWayRange(w->getId()); _wayCount++; } }
vector<WayPtr> MaximalSublineStringMatcher::_changeMap(const vector<ConstWayPtr>& ways, OsmMapPtr map) const { vector<WayPtr> result; result.reserve(ways.size()); for (size_t i = 0; i < ways.size(); ++i) { result.push_back(map->getWay(ways[i]->getId())); } return result; }
boost::shared_ptr<Element> GeometryConverter::convertMultiLineStringToElement(const MultiLineString* mls, const OsmMapPtr& map, Status s, double circularError) { if (mls->getNumGeometries() > 1) { RelationPtr r(new Relation(s, map->createNextRelationId(), circularError, MetadataTags::RelationMultilineString())); for (size_t i = 0; i < mls->getNumGeometries(); i++) { WayPtr w = convertLineStringToWay( dynamic_cast<const LineString*>(mls->getGeometryN(i)), map, s, circularError); r->addElement("", w); } map->addRelation(r); return r; } else { return convertLineStringToWay(dynamic_cast<const LineString*>(mls->getGeometryN(0)), map, s, circularError); } }
void RemoveNodeOp::_removeNode(OsmMapPtr& map, long nId) { const boost::shared_ptr<NodeToWayMap>& n2w = map->getIndex().getNodeToWayMap(); const set<long>& ways = n2w->getWaysByNode(nId); if (ways.size() > 0) { if (_removeOnlyUnused) return; else throw HootException("Removing a node, but it is still part of one or more ways."); } _removeNodeNoCheck(map, nId); }
vector<ElementId> PoiPolygonMerger::_getBuildingParts(const OsmMapPtr& map, Status s) const { vector<ElementId> result; for (set< pair<ElementId, ElementId> >::const_iterator it = _pairs.begin(); it != _pairs.end(); ++it) { const pair<ElementId, ElementId>& p = *it; ElementPtr e1 = map->getElement(p.first); ElementPtr e2 = map->getElement(p.second); if (e1->getStatus() == s && e1->getElementType() != ElementType::Node) { result.push_back(e1->getElementId()); } if (e2->getStatus() == s && e2->getElementType() != ElementType::Node) { result.push_back(e2->getElementId()); } } return result; }
void RemoveNodeOp::_removeNodeFully(OsmMapPtr& map, long nId) { // copy the set because we may modify it later. set<long> rid = map->getIndex().getElementToRelationMap()-> getRelationByElement(ElementId::way(nId)); for (set<long>::const_iterator it = rid.begin(); it != rid.end(); ++it) { map->getRelation(*it)->removeElement(ElementId::node(nId)); } const boost::shared_ptr<NodeToWayMap>& n2w = map->getIndex().getNodeToWayMap(); const set<long> ways = n2w->getWaysByNode(nId); for (set<long>::const_iterator it = ways.begin(); it != ways.end(); ++it) { map->getWay(*it)->removeNode(nId); } _removeNodeNoCheck(map, nId); VALIDATE(map->validate()); }
void MarkForReviewMerger::apply(const OsmMapPtr& map, vector< pair<ElementId, ElementId> >& /*replaced*/) const { for (set< pair<ElementId, ElementId> >::const_iterator it = _pairs.begin(); it != _pairs.end(); ++it) { ElementId eid1 = it->first; ElementId eid2 = it->second; ElementPtr e1 = map->getElement(eid1); ElementPtr e2 = map->getElement(eid2); ReviewMarker().mark(e1, e2, _note, _score); } }