Example #1
0
void TagComparator::_addAsDefault(Tags& t, const QString& key, const QString& value)
{
  if (t.contains(key) == false || t[key].isEmpty() == true)
  {
    t[key] = value;
  }
}
Example #2
0
void TagComparator::_overwriteUnrecognizedTags(Tags& t1, Tags& t2, Tags& result)
{
  OsmSchema& schema = OsmSchema::getInstance();

  const Tags t1Copy = t1;
  for (Tags::ConstIterator it1 = t1Copy.begin(); it1 != t1Copy.end(); ++it1)
  {
    // if this is an unknown type
    if (schema.getTagVertex(it1.key() + "=" + it1.value()).isEmpty() &&
        schema.getTagVertex(it1.key()).isEmpty())
    {
      // if this is also in t2.
      if (t2.contains(it1.key()))
      {
        result[it1.key()] = it1.value();
        t1.remove(it1.key());
        t2.remove(it1.key());
      }
    }
  }

  // go through any remaining tags in t2
  const Tags t2Copy = t2;
  for (Tags::ConstIterator it2 = t2Copy.begin(); it2 != t2Copy.end(); ++it2)
  {
    // if this is an unknown type
    if (schema.getTagVertex(it2.key() + "=" + it2.value()).isEmpty())
    {
      // we know it isn't in t1, or it would have been handled in the above loop so just deal with
      // t2
      t2.remove(it2.key());
      result[it2.key()] = it2.value();
    }
  }
}
Example #3
0
QString MostEnglishName::getMostEnglishName(const Tags& tags)
{
  if (tags.contains("name:en") && tags.get("name:en").isEmpty() == false)
  {
    return tags.get("name:en");
  }

  QStringList names = tags.getNames();

  double bestScore = -numeric_limits<double>::max();
  QString bestName;

  for (int i = 0; i < names.size(); i++)
  {
    double score = scoreName(names[i]);

    if (score > bestScore)
    {
      bestScore = score;
      bestName = names[i];
    }
  }

  return bestName;
}
Example #4
0
void TagComparator::_mergeText(Tags& t1, Tags& t2, Tags& result)
{
  OsmSchema& schema = OsmSchema::getInstance();

  const Tags t1Copy = t1;
  for (Tags::ConstIterator it1 = t1Copy.begin(); it1 != t1Copy.end(); ++it1)
  {
    const SchemaVertex& tv = schema.getTagVertex(it1.key());

    // if this is a text field and it exists in both tag sets.
    if (tv.valueType == Text && t2.contains(it1.key()))
    {
      // only keep the unique text fields
      QStringList values = t1.getList(it1.key());
      values.append(t2.getList(it1.key()));

      // append all unique values in the existing order.
      for (int i = 0; i < values.size(); i++)
      {
        if (values[i].isEmpty() == false)
        {
          result.appendValueIfUnique(it1.key(), values[i]);
        }
      }

      t1.remove(it1.key());
      t2.remove(it1.key());
    }
  }
}
Example #5
0
void TagComparator::_addDefaults(Tags& t)
{
  if (t.contains("highway"))
  {
    _addAsDefault(t, "bridge", "no");
    _addAsDefault(t, "tunnel", "no");
    _addAsDefault(t, "oneway", "no");
  }
}
int SplitNameVisitor::_getNextNameId(const Tags& t, int lastId)
{
    for (int i = lastId + 1; i < lastId + 100; i++)
    {
        QString k = QString("name:%1").arg(i);

        if (t.contains(k) == false)
        {
            return i;
        }
    }

    throw InternalErrorException("Unable to find a valid key for a new extra name.");
}
Example #7
0
void TagComparator::_mergeUnrecognizedTags(Tags& t1, Tags& t2, Tags& result)
{
  OsmSchema& schema = OsmSchema::getInstance();

  const Tags t1Copy = t1;
  for (Tags::ConstIterator it1 = t1Copy.begin(); it1 != t1Copy.end(); ++it1)
  {
    // if this is an unknown type
    if (schema.getTagVertex(it1.key() + "=" + it1.value()).isEmpty() &&
        schema.getTagVertex(it1.key()).isEmpty())
    {
      // if this is also in t2.
      if (t2.contains(it1.key()))
      {
        // get the set of all values.
        QSet<QString> values = _toSet(t1, it1.key());
        values.unite(_toSet(t2, it1.key()));
        QList<QString> sortEm = values.toList();
        qSort(sortEm);

        // remove it from the inputs
        t1.remove(it1.key());
        t2.remove(it1.key());
        // set the united set in the output
        result.set(it1.key(), sortEm.begin(), sortEm.end());
      }
      else
      {
        result[it1.key()] = it1.value();
      }
    }
  }

  // go through any remaining tags in t2
  const Tags t2Copy = t2;
  for (Tags::ConstIterator it2 = t2Copy.begin(); it2 != t2Copy.end(); ++it2)
  {
    // if this is an unknown type
    if (schema.getTagVertex(it2.key() + "=" + it2.value()).isEmpty())
    {
      // we know it isn't in t1, or it would have been handled in the above loop so just deal with
      // t2
      t2.remove(it2.key());
      result[it2.key()] = it2.value();
    }
  }
}
Example #8
0
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());
    }
  }
}
void DecomposeBuildingRelationsVisitor::_decomposeBuilding(const shared_ptr<Relation>& r)
{
  Tags baseTags = r->getTags();

  const vector<RelationData::Entry> members = r->getMembers();

  for (size_t i = 0; i < members.size(); ++i)
  {
    ElementId eid = members[i].getElementId();
    r->removeElement(eid);
    if (eid.getType() == ElementType::Node)
    {
      LOG_WARN("Unexpected node encountered in building relation. " << r->getElementId());
      continue;
    }
    // we're dropping the outline. We only care about the parts.
    else if (members[i].getRole() == "outline")
    {
      continue;
    }
    else if (members[i].getRole() != "part")
    {
      LOG_WARN("Encountered an unexpected role in a building relation. " << r->getElementId());
    }

    // ok, we've got a building part. Recompose it as a building.
    shared_ptr<Element> e = _map->getElement(members[i].getElementId());

    Tags t = baseTags;
    t.addTags(e->getTags());
    // don't need the building:part tag anymore.
    t.remove("building:part");

    if (!t.contains("building"))
    {
      t["building"] = "yes";
    }

    e->setTags(t);
  }

  // remove the building relation
  RecursiveElementRemover(r->getElementId()).apply(_map->shared_from_this());
}
Example #10
0
void TagComparator::compareTextTags(const Tags& t1, const Tags& t2, double& score, double& weight)
{
  OsmSchema& schema = OsmSchema::getInstance();

  score = 1.0;
  weight = 0.0;

  for (Tags::const_iterator it = t1.begin(); it != t1.end(); it++)
  {
    const SchemaVertex& tv = schema.getTagVertex(it.key());
    if (schema.isAncestor(it.key(), "abstract_name") == false &&
        tv.valueType == Text && t2.contains(it.key()))
    {
      score *= LevenshteinDistance::score(it.value(), t2[it.key()]);
      weight += tv.influence;
    }
  }

  // if the weight is zero don't confuse things with a low score.
  if (weight == 0.0)
  {
    score = 1;
  }
}
Example #11
0
void TagComparator::mergeNames(Tags& t1, Tags& t2, Tags& result)
{
  set<QString> altNames, nonAltNames;
  set<QString> toRemove;

  toRemove.insert("alt_name");

  for (Tags::const_iterator it1 = t1.begin(); it1 != t1.end(); it1++)
  {
    if (it1.key() == "alt_name")
    {
      QStringList sl = Tags::split(it1.value());
      altNames.insert(sl.begin(), sl.end());
    }
    else
    {
      if (OsmSchema::getInstance().isAncestor(it1.key(), "abstract_name"))
      {
        result[it1.key()] = it1.value();
        QStringList sl = Tags::split(it1.value());
        // keep track of all the names we've used
        nonAltNames.insert(sl.begin(), sl.end());
        toRemove.insert(it1.key());
      }
    }
  }

  for (Tags::const_iterator it2 = t2.begin(); it2 != t2.end(); it2++)
  {
    if (it2.key() == "alt_name")
    {
      QStringList sl = Tags::split(it2.value());
      altNames.insert(sl.begin(), sl.end());
    }
    else if (result.contains(it2.key()))
    {
      const Qt::CaseSensitivity caseSensitivity =
        _caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
      if (result[it2.key()].compare(it2.value(), caseSensitivity) != 0)
      {
        QStringList sl = Tags::split(it2.value());
        altNames.insert(sl.begin(), sl.end());
      }
    }
    else
    {
      if (OsmSchema::getInstance().isAncestor(it2.key(), "abstract_name"))
      {
        result[it2.key()] = it2.value();
        QStringList sl = Tags::split(it2.value());
        nonAltNames.insert(sl.begin(), sl.end());
        toRemove.insert(it2.key());
      }
    }
  }

  for (set<QString>::const_iterator it = toRemove.begin(); it != toRemove.end(); it++)
  {
    t1.remove(*it);
    t2.remove(*it);
  }

  // add all the altNames that don't exist in nonAltNames
  QStringList l;
  for (set<QString>::const_iterator it = altNames.begin(); it != altNames.end(); it++)
  {
    if (nonAltNames.find(*it) == nonAltNames.end())
    {
      l.append(*it);
    }
  }

  if (l.size() > 0)
  {
    result.setList("alt_name", l);
  }
}