예제 #1
0
void OsmApiDbSqlChangesetFileWriter::_createRelationMembers(ConstRelationPtr relation)
{
  LOG_TRACE("Creating relation members for: " << relation->getElementId());

  const vector<RelationData::Entry> members = relation->getMembers();
  for (size_t i = 0; i < members.size(); i++)
  {
    const RelationData::Entry member = members[i];
    LOG_VART(member.getElementId());

    QString values =
      QString(
        "(relation_id, member_type, member_id, member_role, version, sequence_id) VALUES (%1, '%2', %3, '%4', 1, %5);\n")
        .arg(relation->getId())
        .arg(member.getElementId().getType().toString())
        .arg(member.getElementId().getId())
        .arg(member.getRole())
        .arg(i + 1);
    _outputSql.write(("INSERT INTO " + ApiDb::getRelationMembersTableName() + " " + values).toUtf8());

    values =
      QString(
        "(relation_id, member_type, member_id, member_role, sequence_id) VALUES (%1, '%2', %3, '%4', %5);\n")
        .arg(relation->getId())
        .arg(member.getElementId().getType().toString())
        .arg(member.getElementId().getId())
        .arg(member.getRole())
        .arg(i + 1);
    _outputSql.write(
      ("INSERT INTO " + ApiDb::getCurrentRelationMembersTableName() + " " + values).toUtf8());
  }
}
void MaximalSublineStringMatcher::_validateElement(const ConstOsmMapPtr& map, ElementId eid) const
{
  ConstElementPtr e = map->getElement(eid);

  if (e->getElementType() == ElementType::Relation)
  {
    ConstRelationPtr r = dynamic_pointer_cast<const Relation>(e);

    if (OsmSchema::getInstance().isMultiLineString(*r) == false)
    {
      throw NeedsReviewException("Internal Error: When matching sublines expected a multilinestring "
        "relation not a " + r->getType() + ".  A non-multilinestring should never be found here.  "
        "Please report this to [email protected]");
    }

    const vector<RelationData::Entry>& entries = r->getMembers();
    for (size_t i = 0; i < entries.size(); i++)
    {
      if (entries[i].getElementId().getType() != ElementType::Way)
      {
        throw NeedsReviewException("MultiLineString relations can only contain ways when matching "
                                   "sublines.");
      }
    }
  }
  if (e->getElementType() == ElementType::Way)
  {
    ConstWayPtr w = dynamic_pointer_cast<const Way>(e);

    if (w->getNodeCount() <= 1)
    {
      throw NeedsReviewException("Internal Error: Attempting to match against a zero length way.");
    }
  }
}
예제 #3
0
boost::shared_ptr<Geometry> Building::buildOutline() const
{
  ElementConverter ec(_map.shared_from_this());
  boost::shared_ptr<Geometry> result;

  // if this is a building relation
  if (_e->getElementType() == ElementType::Relation)
  {
    // construct the outline from the union of the parts.
    result.reset(GeometryFactory::getDefaultInstance()->createEmptyGeometry());

    ConstRelationPtr r = boost::dynamic_pointer_cast<const Relation>(_e);
    const vector<RelationData::Entry> entries = r->getMembers();
    for (size_t i = 0; i < entries.size(); i++)
    {
      if (entries[i].role == MetadataTags::RolePart())
      {
        boost::shared_ptr<Geometry> g = ec.convertToGeometry(_map.getElement(entries[i].getElementId()));
        result.reset(result->Union(g.get()));
      }
    }
  }
  else
  {
    result = ec.convertToGeometry(_e);
  }
  return result;
}
void MaximalSublineStringMatcher::_validateElement(const ConstOsmMapPtr& map, ElementId eid) const
{
  ConstElementPtr e = map->getElement(eid);

  if (e->getElementType() == ElementType::Relation)
  {
    ConstRelationPtr r = dynamic_pointer_cast<const Relation>(e);

    if (OsmSchema::getInstance().isMultiLineString(*r) == false)
    {
      throw NeedsReviewException("When matching sublines expected a multilinestring relation not"
                                 " a " + r->getType());
    }

    const vector<RelationData::Entry>& entries = r->getMembers();
    for (size_t i = 0; i < entries.size(); i++)
    {
      if (entries[i].getElementId().getType() != ElementType::Way)
      {
        throw NeedsReviewException("MultiLineString relations can only contain ways when matching "
                                   "sublines.");
      }
    }
  }
}
예제 #5
0
MultiLineStringLocation PertyWaySplitVisitor::_calcSplitPoint(ConstRelationPtr relation,
                                                              ElementId& wayId) const
{
  const vector<RelationData::Entry>& members = relation->getMembers();
  LOG_VART(members.size());

  //find the way to split on
  boost::uniform_int<> randomWayIndexDistribution(0, members.size() - 1);
  int wayIndex = randomWayIndexDistribution(*_rng);
  wayId = members.at(wayIndex).getElementId();
  LOG_VART(wayIndex);
  LOG_VART(wayId);
  ElementPtr element = _map->getElement(wayId);
  if (element->getElementType() != ElementType::Way)
  {
    throw HootException(
      "PERTY feature splitting for multi-line string relations may only occur on relations which contain only ways.");
  }
  WayPtr way = boost::dynamic_pointer_cast<Way>(element);
  LOG_VART(way->getNodeCount());

  //calculate the split point
  WayLocation wayLocation = _calcSplitPoint(way);
  //return it, if its valid
  if (wayLocation.isValid())
  {
    return
      MultiLineStringLocation(
        _map->shared_from_this(),
        relation,
        wayIndex,
        wayLocation);
  }
  //otherwise, return an empty location
  else
  {
    return MultiLineStringLocation();
  }
}
예제 #6
0
geos::geom::GeometryTypeId ElementConverter::getGeometryType(const ConstElementPtr& e,
  bool throwError, const bool statsFlag)
{
  ElementType t = e->getElementType();
  switch (t.getEnum())
  {
  case ElementType::Node:
    return GEOS_POINT;

  case ElementType::Way:
    {
      ConstWayPtr w = dynamic_pointer_cast<const Way>(e);
      assert(w);

      if(statsFlag)
      {
        if (w->isValidPolygon() && OsmSchema::getInstance().isAreaForStats(w->getTags(), ElementType::Way))
          return GEOS_POLYGON;
        else
          return GEOS_LINESTRING;
      } else {
        if (w->isValidPolygon() && OsmSchema::getInstance().isArea(w->getTags(), ElementType::Way))
          return GEOS_POLYGON;
        else
          return GEOS_LINESTRING;
      }

      break;
    }

  case ElementType::Relation:
    {
      ConstRelationPtr r = dynamic_pointer_cast<const Relation>(e);
      assert(r);
      if(statsFlag)
      {
        if (r->isMultiPolygon() || OsmSchema::getInstance().isAreaForStats(r->getTags(), ElementType::Relation))
          return GEOS_MULTIPOLYGON;
        else if (OsmSchema::getInstance().isLinear(*r))
          return GEOS_MULTILINESTRING;
      } else {
        if (r->isMultiPolygon() || OsmSchema::getInstance().isArea(r->getTags(), ElementType::Relation))
          return GEOS_MULTIPOLYGON;
        else if (OsmSchema::getInstance().isLinear(*r))
        {
          return GEOS_MULTILINESTRING;
        }
        else if (r->getMembers().size() == 0 ||
                 OsmSchema::getInstance().isCollection(*r))
        {
          // an empty geometry, pass back a collection
          return GEOS_GEOMETRYCOLLECTION;
        }
      }

      break;

    }

  default:
    LOG_ERROR("Element was not a node, way, or relation");
    break;
  }

  if (throwError)
  {
    throw IllegalArgumentException("Unknown geometry type.");
  }
  else
  {
    return GeometryTypeId(-1);
  }
}