void runIsCandidateTest() { CustomPoiMatchCreator uut; OsmMapPtr map(new OsmMap()); OGREnvelope env; env.MinX = 0.0; env.MinY = 0.0; env.MaxX = 1.0; env.MaxY = 1.0; MapProjector::projectToPlanar(map, env); //to be a match candidate: needs to be a node and a poi; being a poi means its tagged as a //poi OR has a name tag Tags tags; tags.appendValue("name", "node1"); tags.appendValue("poi", "yes"); NodePtr node1 = TestUtils::createNode(map, Status::Unknown1, 10.0, 10.0, 250.0, tags); CPPUNIT_ASSERT(uut.isMatchCandidate(node1, map)); tags.clear(); tags.appendValue("name", "node2"); NodePtr node2 = TestUtils::createNode(map, Status::Unknown1, 10.0, 10.0, 250.0, tags); CPPUNIT_ASSERT(uut.isMatchCandidate(node2, map)); tags.clear(); tags.appendValue("poi", "yes"); NodePtr node3 = TestUtils::createNode(map, Status::Unknown1, 10.0, 10.0, 250.0, tags); CPPUNIT_ASSERT(uut.isMatchCandidate(node3, map)); NodePtr node4 = TestUtils::createNode(map, Status::Unknown1, 10.0, 10.0, 250.0); CPPUNIT_ASSERT(!uut.isMatchCandidate(node4, map)); QList<NodePtr> wayNodes; wayNodes.append(node1); wayNodes.append(node2); WayPtr way1 = TestUtils::createWay(map, wayNodes, Status::Unknown1); CPPUNIT_ASSERT(!uut.isMatchCandidate(way1, map)); }
void TagComparator::_overwriteRemainingTags(Tags& t1, Tags& t2, Tags& result) { // Add t2 tags for (Tags::ConstIterator it2 = t2.constBegin(); it2 != t2.constEnd(); ++it2) { if (it2.value().isEmpty() == false) { result[it2.key()] = it2.value(); } } // Add t1 tags overwriting any t2 tags in the process. for (Tags::ConstIterator it1 = t1.constBegin(); it1 != t1.constEnd(); ++it1) { if (it1.value().isEmpty() == false) { result[it1.key()] = it1.value(); } } t1.clear(); t2.clear(); }
void runToOsmTest() { // Great bit of code taken from TranslatedTagDifferencer.cpp shared_ptr<ScriptTranslator> st(ScriptTranslatorFactory::getInstance().createTranslator( "test-files/io/SampleTranslation.js")); shared_ptr<ScriptToOgrTranslator>uut = dynamic_pointer_cast<ScriptToOgrTranslator>(st); if (!uut) { throw HootException("Error allocating translator. the translation script must support " "converting to OGR."); } shared_ptr<const Schema> schema = uut->getOgrOutputSchema(); // JavaScriptTranslator::TranslatedFeature tf; ScriptToOgrTranslator::TranslatedFeature tf; QString layer; Tags t; t.clear(); t["building"] = "yes"; t["name"] = "foo"; tf = uut->translateToOgr(t, ElementType::Node, GEOS_POINT)[0]; HOOT_STR_EQUALS("PAL015", tf.tableName); HOOT_STR_EQUALS("[2]{(ARA, -999999), (NAM, foo)}", tf.feature->getValues()); t.clear(); t["building"] = "yes"; t["name"] = "foo"; tf = uut->translateToOgr(t, ElementType::Way, GEOS_POLYGON)[0]; HOOT_STR_EQUALS("AAL015", tf.tableName); HOOT_STR_EQUALS("[2]{(ARA, 10), (NAM, foo)}", tf.feature->getValues()); t.clear(); t["highway"] = "track"; t["name"] = "bar"; tf = uut->translateToOgr(t, ElementType::Way, GEOS_LINESTRING)[0]; HOOT_STR_EQUALS("LAP010", tf.tableName); HOOT_STR_EQUALS("[3]{(ARA, -999999), (NAM, bar), (PCF, 1)}", tf.feature->getValues()); t.clear(); t["highway"] = "road"; t["name"] = "bar"; tf = uut->translateToOgr(t, ElementType::Way, GEOS_LINESTRING)[0]; HOOT_STR_EQUALS("LAP030", tf.tableName); HOOT_STR_EQUALS("[4]{(ARA, -999999), (LTN, 2), (NAM, bar), (PCF, 2)}", tf.feature->getValues()); // throw an exception because the BAD field shouldn't be there. t.clear(); t["tableName"] = "PAL015"; t["NAM"] = "foo"; t["BAD"] = "tag"; t["ARA"] = "-999999"; CPPUNIT_ASSERT_THROW(uut->translateToOgr(t, ElementType::Node, GEOS_POINT), FieldDefinition::InvalidValueException); // throw an exception because ARA can't be -1. t.clear(); t["tableName"] = "PAL015"; t["NAM"] = "foo"; t["ARA"] = "-1"; CPPUNIT_ASSERT_THROW(uut->translateToOgr(t, ElementType::Node, GEOS_POINT), FieldDefinition::InvalidValueException); // throw an exception because the NAM field is missing. t.clear(); t["tableName"] = "PAL015"; t["ARA"] = "-999999"; CPPUNIT_ASSERT_THROW(uut->translateToOgr(t, ElementType::Node, GEOS_POINT), FieldDefinition::InvalidValueException); // throw an exception because the PCF field has an invalid value. t.clear(); t["tableName"] = "LAP030"; t["ARA"] = "-999999"; t["NAM"] = "foo"; t["LTN"] = "2"; t["PCF"] = "3"; CPPUNIT_ASSERT_THROW(uut->translateToOgr(t, ElementType::Way, GEOS_LINESTRING), FieldDefinition::InvalidValueException); }
void TagComparator::averageTags(const Tags& t1In, double w1, const Tags& t2In, double w2, Tags& result, bool keepAllUnknownTags) { //LOG_WARN("score: " << OsmSchema::getInstance().score("highway=road", "highway=unclassified")); result.clear(); OsmSchema& schema = OsmSchema::getInstance(); Tags t1 = t1In; Tags t2 = t2In; set<QString> k1, k2; mergeNames(t1, t2, result); // Merge any text fields by concatenating the lists. _mergeText(t1, t2, result); if (keepAllUnknownTags) { _mergeUnrecognizedTags(t1, t2, result); } for (Tags::const_iterator it1 = t1.begin(); it1 != t1.end(); it1++) { QString kvp1 = it1.key() + "=" + it1.value(); QString kvp2; double bestScore = 0; QString bestKvp; QString bestK2; for (Tags::const_iterator it2 = t2.begin(); it2 != t2.end(); it2++) { kvp2 = it2.key() + "=" + it2.value(); double score; QString thisKvp = schema.average(kvp1, w1, kvp2, w2, score); if (score > bestScore && k2.find(it2.key()) == k2.end()) { bestScore = score; bestKvp = thisKvp; bestK2 = it2.key(); } } if (bestKvp.isEmpty() == false) { k1.insert(it1.key()); k2.insert(bestK2); if (bestKvp.contains("=")) { QStringList sl = bestKvp.split("="); result[sl[0]] = sl[1]; } else { result[it1.key()] = it1.value(); } } } for (Tags::const_iterator it2 = t2.begin(); it2 != t2.end(); it2++) { if (k2.find(it2.key()) == k2.end()) { result[it2.key()] = it2.value(); } } for (Tags::const_iterator it1 = t1.begin(); it1 != t1.end(); it1++) { if (k1.find(it1.key()) == k1.end()) { result[it1.key()] = it1.value(); } } }
void clear() { text.clear(); tags.clear(); }