bool PoiPolygonMatch::isPoiIsh(ConstElementPtr e) { return e->getElementType() == ElementType::Node && (OsmSchema::getInstance().getCategories(e->getTags()).intersects( OsmSchemaCategory::building() | OsmSchemaCategory::poi()) || e->getTags().getNames().size() > 0); }
void TranslatedTagCountVisitor::visit(const ConstElementPtr& e) { if (e->getTags().getInformationCount() > 0) { shared_ptr<Geometry> g = ElementConverter(_map->shared_from_this()).convertToGeometry(e); Tags t = e->getTags(); t["error:circular"] = QString::number(e->getCircularError()); t["hoot:status"] = e->getStatusString(); // remove all the empty tags. for (Tags::const_iterator it = e->getTags().begin(); it != e->getTags().end(); ++it) { if (t[it.key()] == "") { t.remove(it.key()); } } QString layerName; vector<ScriptToOgrTranslator::TranslatedFeature> f = _translator->translateToOgr(t, e->getElementType(), g->getGeometryTypeId()); // only write the feature if it wasn't filtered by the translation script. for (size_t i = 0; i < f.size(); i++) { _countTags(f[i].feature); } } }
void OgrWriter::_writePartial(ElementProviderPtr& provider, const ConstElementPtr& e) { if (_translator.get() == 0) { throw HootException("You must call open before attempting to write."); } if (e->getTags().getInformationCount() > 0) { // There is probably a cleaner way of doing this. // convertToGeometry calls getGeometryType which will throw an exception if it gets a relation // that it doesn't know about. E.g. "route", "superroute", " turnlanes:turns" etc shared_ptr<Geometry> g; try { g = ElementConverter(provider).convertToGeometry(e); } catch (IllegalArgumentException& err) { LOG_WARN("Error converting geometry: " << err.getWhat() << " (" << e->toString() << ")"); g.reset((GeometryFactory::getDefaultInstance()->createEmptyGeometry())); } /* LOG_DEBUG("After conversion to geometry, element is now a " << g->getGeometryType() ); */ Tags t = e->getTags(); t["error:circular"] = QString::number(e->getCircularError()); t["hoot:status"] = e->getStatusString(); for (Tags::const_iterator it = e->getTags().begin(); it != e->getTags().end(); ++it) { if (t[it.key()] == "") { t.remove(it.key()); } } vector<ScriptToOgrTranslator::TranslatedFeature> tf = _translator->translateToOgr(t, e->getElementType(), g->getGeometryTypeId()); // only write the feature if it wasn't filtered by the translation script. for (size_t i = 0; i < tf.size(); i++) { OGRLayer* layer = _getLayer(tf[i].tableName); if (layer != 0) { _addFeature(layer, tf[i].feature, g); } } } }
static bool isRelated(ConstElementPtr e1, ConstElementPtr e2) { if (e1->getStatus() != e2->getStatus() && e1->isUnknown() && e2->isUnknown() && OsmSchema::getInstance().isBuilding(e1->getTags(), e1->getElementType()) && OsmSchema::getInstance().isBuilding(e2->getTags(), e2->getElementType())) { return true; } else { return false; } }
QString OsmPgCsvWriter::_getTags(const ConstElementPtr& e) { QString buffer; QTextStream stream(&buffer); stream.setCodec("UTF-8"); const Tags& tags = e->getTags(); QRegExp regex("[\"=>, -]"); for (Tags::const_iterator it = tags.constBegin(); it != tags.constEnd(); ++it) { // Comma separated list if (it != tags.constBegin()) stream << ","; // Surround the key with quotes if it contains a special character requiring it if (it.key().contains(regex)) stream << "\"" << QString(it.key()).replace("\"", "\\\"") << "\""; else stream << it.key(); stream<< "=>"; // Surround the value with quotes if it contains a special character requiring it if (it.value().contains(regex)) stream << "\"" << QString(it.value()).replace("\"", "\\\"") << "\""; else stream << it.value(); } return stream.readAll(); }
Handle<Value> ElementJs::getTags(const Arguments& args) { HandleScope scope; ConstElementPtr e = ObjectWrap::Unwrap<ElementJs>(args.This())->getConstElement(); return scope.Close(TagsJs::New(e->getTags())); }
virtual void visit(const ConstElementPtr& e) { const Tags& t = e->getTags(); const QString REV = MetadataTags::TrainingReview(); const QString MAT = MetadataTags::TrainingMatch(); if (t.contains(MetadataTags::TrainingId()) || t.contains(MAT) || t.contains(REV)) { if (t.contains(MetadataTags::TrainingId()) == false || t.contains(MAT) == false) { LOG_WARN(QString("Element %1 doesn't contain %2 and %3.") .arg(e->getElementId().toString()) .arg(MetadataTags::TrainingId()) .arg(MAT)); } if (t[MAT] == "todo") { LOG_WARN("Element " << e->getElementId().toString() << " (" << t[MetadataTags::TrainingId()] << ") is still marked as todo: "); } if (!(t[MAT] == "none" || t[MAT] == "") && !(t[REV] == "none" || t[REV] == "")) { LOG_WARN("Element " << e->getElementId().toString() << " (" << t[MetadataTags::TrainingId()] << ") has both match and review populated."); LOG_WARN(" '" << t[MAT] << "' and '" << t[REV] << "'"); } } }
bool LinearCriterion::isSatisfied(const ConstElementPtr& e) const { bool result = false; if (e->getElementType() == ElementType::Node) { return false; } const Tags& t = e->getTags(); if (e->getElementType() == ElementType::Relation) { ConstRelationPtr r = boost::dynamic_pointer_cast<const Relation>(e); result |= r->getType() == MetadataTags::RelationMultilineString(); result |= r->getType() == MetadataTags::RelationRoute(); result |= r->getType() == MetadataTags::RelationBoundary(); } for (Tags::const_iterator it = t.constBegin(); it != t.constEnd(); ++it) { const SchemaVertex& tv = OsmSchema::getInstance().getTagVertex(it.key() + "=" + it.value()); uint16_t g = tv.geometries; if (g & (OsmGeometries::LineString | OsmGeometries::ClosedWay) && !(g & OsmGeometries::Area)) { result = true; break; } } return result; }
void TagKeyCountVisitor::visit(const ConstElementPtr& e) { if (e->getTags().contains(_key)) { _keyCount++; } }
virtual void visit(const ConstElementPtr& e) { QStringList refs; if (e->getTags().contains(_ref)) { e->getTags().readValues(_ref, refs); } refs.removeAll("todo"); refs.removeAll("none"); if (refs.size() > 0) { for (int i = 0; i < refs.size(); i++) { _ref2Eid[refs[i]].insert(e->getElementId()); } } }
void UniqueNamesVisitor::visit(const ConstElementPtr& e) { QStringList names = e->getTags().getNames(); for (int i = 0; i < names.size(); i++) { _names.insert(names[i]); } }
double NameExtractor::extract(const ConstElementPtr& target, const ConstElementPtr& candidate) const { QStringList targetNames = target->getTags().getNames(); targetNames.append(target->getTags().getPseudoNames()); QStringList candidateNames = candidate->getTags().getNames(); candidateNames.append(candidate->getTags().getPseudoNames()); double score = -1; for (int i = 0; i < targetNames.size(); i++) { for (int j = 0; j < candidateNames.size(); j++) { double thisScore = _d->compare(targetNames[i], candidateNames[j]); score = max(thisScore, score); } } if (score == -1) { return nullValue(); } else { // LOG_INFO("score: " << score << " weight: " << weight); // LOG_INFO("target: " << target->toString()); // LOG_INFO("candidate: " << candidate->toString()); // if (candidate->getTags()["REF2"].contains(target->getTags()["REF1"])) // { // LOG_INFO(getName() << " | Match: " << score << " | " << // target->getTags().getNames().join(";") << " | " << // candidate->getTags().getNames().join(";")) // } // else // { // LOG_INFO(getName() << " | Miss: " << score << " | " << // target->getTags().getNames().join(";") << " | " << // candidate->getTags().getNames().join(";")) // } } return score; }
bool ReversedRoadCriterion::isSatisfied(const ConstElementPtr& e) const { bool result = false; const QString oneway = e->getTags()["oneway"].toLower(); if (oneway == "-1" || oneway == "reverse") { result = true; } return result; }
bool HgisPoiCriterion::isSatisfied(const ConstElementPtr& e) const { bool result = false; // See ticket #6853 for a definition of a "HGIS POI" if (e->getElementType() == ElementType::Node) { result = OsmSchema::getInstance().hasCategory(e->getTags(), OsmSchemaCategory::hgisPoi().toString()); } return result; }
bool TagValueNumericRangeCriterion::isSatisfied(const ConstElementPtr& e) const { //The element must have tags for all keys passed in, and all the values for those keys must be //within the specified range. for (int i = 0; i < _tagKeys.size(); i++) { const QString tagKey = _tagKeys.at(i); if (!e->getTags().contains(tagKey)) { return false; } bool ok = false; const long val = e->getTags().get(tagKey).toLong(&ok); if (!ok || val < _rangeMin || val > _rangeMax) { return false; } } return true; }
void AverageNumericTagsVisitor::visit(const ConstElementPtr& e) { for (int i = 0; i < _keys.size(); i++) { const QString key = _keys.at(i); LOG_VART(key); if (e->getTags().contains(key)) { bool parsed = false; const QString strValue = e->getTags().get(key); LOG_VART(strValue); const double value = strValue.toDouble(&parsed); LOG_VART(value); LOG_VART(parsed); if (parsed) { _tagCount++; _sum += value; LOG_VART(_tagCount); LOG_VART(_sum); } else { if (logWarnCount < Log::getWarnMessageLimit()) { LOG_WARN( "Unsuccessfully attempted to convert tag with key: " << key << " and value: " << strValue << " to number."); } else if (logWarnCount == Log::getWarnMessageLimit()) { LOG_WARN(className() << ": " << Log::LOG_WARN_LIMIT_REACHED_MESSAGE); } logWarnCount++; } } } }
bool PoiPolygonMatch::_calculateTypeMatch(ConstElementPtr e1, ConstElementPtr e2) const { bool result = false; const Tags& t1 = e1->getTags(); const Tags& t2 = e2->getTags(); for (Tags::const_iterator it = t1.begin(); it != t1.end(); it++) { // if it is a use or POI category if ((OsmSchema::getInstance().getCategories(it.key(), it.value()) & (OsmSchemaCategory::building() | OsmSchemaCategory::use() | OsmSchemaCategory::poi())) != OsmSchemaCategory::Empty) { result = t2.get(it.key()) == it.value(); if (result) { return result; } } } return result; }
bool RoundaboutCriterion::isSatisfied(const ConstElementPtr& e) const { // If it's not a highway, it's not a roundabout if (!HighwayCriterion().isSatisfied(e)) { return false; } // Now check some details... bool result = false; Tags::const_iterator tagIt = e->getTags().find("junction"); if (tagIt != e->getTags().end() && tagIt.value().toLower() == "roundabout") { result = true; } if (result) { LOG_TRACE("isRoundabout; key: " << tagIt.key()); } return result; }
void OsmApiDbSqlChangesetFileWriter::_createTags(ConstElementPtr element) { LOG_TRACE("Creating tags for: " << element->getElementId()); QStringList tableNames = _tagTableNamesForElement(element->getElementId()); Tags tags = element->getTags(); if (_includeDebugTags) { tags.set(MetadataTags::HootStatus(), QString::number(element->getStatus().getEnum())); } LOG_VART(tags); if (element->getElementType().getEnum() == ElementType::Relation && !tags.contains("type")) { ConstRelationPtr tmp = boost::dynamic_pointer_cast<const Relation>(element); tags.appendValue("type", tmp->getType()); } for (Tags::const_iterator it = tags.begin(); it != tags.end(); ++it) { QString k = it.key(); QString v = it.value(); if (k != MetadataTags::HootHash()) { const QString currentTagValues = QString("(%1_id, k, v) VALUES (%2, '%3', '%4');\n") .arg(element->getElementId().getType().toString().toLower()) .arg(element->getElementId().getId()) .arg(k.replace('\'', "''")) .arg(v.replace('\'', "''")); const QString tagValues = QString("(%1_id, k, v, version) VALUES (%2, '%3', '%4', %5);\n") .arg(element->getElementId().getType().toString().toLower()) .arg(element->getElementId().getId()) .arg(k.replace('\'', "''")) .arg(v.replace('\'', "''")) .arg(element->getVersion()); _outputSql.write( (QString("INSERT INTO %1 ").arg(tableNames.at(0)) + currentTagValues).toUtf8()); _outputSql.write((QString("INSERT INTO %1 ").arg(tableNames.at(1)) + tagValues).toUtf8()); } } }
bool MultiUseCriterion::isSatisfied(const ConstElementPtr& e) const { return OsmSchema::getInstance().getCategories(e->getTags()).intersects(OsmSchemaCategory::multiUse()); }
static bool isMatchCandidate(ConstElementPtr element) { return OsmSchema::getInstance().isLinearHighway(element->getTags(), element->getElementType()); }
virtual void visit(const ConstElementPtr& e) { QStringList refs; if (e->getTags().contains("REF1")) { e->getTags().readValues("REF1", refs); refs.removeAll("todo"); refs.removeAll("none"); if (refs.size() > 0) { // Find the REF1 id's in REF2. // NOTE: this blindly assumes that there is only ONE value in the REF1 tag list RefToEidVisitor::RefToEid::const_iterator refId = _refSet.find(refs[0]); if (refId != _refSet.end()) { // Loop through the element Id's in REF2 for (set<ElementId>::const_iterator eid = refId->second.begin(); eid != refId->second.end(); ++eid) { // Loop through the Tags in REF1 for (Tags::const_iterator tag1 = e->getTags().begin(); tag1 != e->getTags().end(); ++tag1 ) { QString kvp1 = OsmSchema::getInstance().toKvp(tag1.key(),tag1.value()); // We are only looking at Enumerated tags if (OsmSchema::getInstance().getTagVertex(kvp1).valueType == hoot::Enumeration) { // Get the value from the corresponding tag in REF2 QString kvp2 = OsmSchema::getInstance().toKvp(tag1.key(), _map->getElement(*eid)->getTags()[tag1.key()]); // LOG_INFO("Got Tags:" + kvp1 + " " + kvp2); _coOccurence[kvp1][kvp2]++; } } // End for REF1 tag list // now loop through the REF2 tag list and fill in any missing tags. for (Tags::const_iterator tag2 = _map->getElement(*eid)->getTags().begin(); tag2 != _map->getElement(*eid)->getTags().end(); ++tag2 ) { QString kvp2 = OsmSchema::getInstance().toKvp(tag2.key(),tag2.value()); // Skip the tags that are common if (e->getTags().contains(tag2.key())) continue; if (OsmSchema::getInstance().getTagVertex(kvp2).valueType == hoot::Enumeration) { // "Missing" == "" tag value QString kvp1 = OsmSchema::getInstance().toKvp(tag2.key(),""); // LOG_INFO("Got Tags:" + kvp1 + " " + kvp2); _coOccurence[kvp1][kvp2]++; } } // End for REF2 tag list // now try matching up the "name" fields QString name1 = e->getTags()["name"]; QString name2 = _map->getElement(*eid)->getTags()["name"]; QString kvpNull = OsmSchema::getInstance().toKvp("name","<NULL>"); QString kvpNonNull = OsmSchema::getInstance().toKvp("name","<NON NULL>"); QString kvpSame = OsmSchema::getInstance().toKvp("name","<SIMILAR>"); if (name1 == "") { if (name2 == "") { _coOccurence[kvpNull][kvpNull]++; } else { _coOccurence[kvpNull][kvpNonNull]++; } } else if (name2 == "") { _coOccurence[kvpNonNull][kvpNull]++; } else { // Check if the names match double nameScore = _calculateNameScore(e, _map->getElement(*eid)); bool nameMatch = nameScore >= ConfigOptions().getPoiPolygonMatchNameThreshold(); if (nameMatch) { _coOccurence[kvpSame][kvpSame]++; } else { _coOccurence[kvpNonNull][kvpNonNull]++; } } } // End for ref2 Element ID's } // End refId != End } // End refs > 0 } // End contains "REF1" } // End Visit
static bool isMatchCandidate(ConstElementPtr element) { return OsmSchema::getInstance().isBuilding(element->getTags(), element->getElementType()); }
bool PoiPolygonMatch::isBuildingIsh(ConstElementPtr e) { return OsmSchema::getInstance().isArea(e->getTags(), e->getElementType()) && OsmSchema::getInstance().getCategories(e->getTags()).intersects( OsmSchemaCategory::building() | OsmSchemaCategory::poi()); }