Example #1
0
void PointsToTracksOp::apply(shared_ptr<OsmMap>& map)
{
  HashMap<QString, deque<long> > trackIdToNid;

  const OsmMap::NodeMap& nm = map->getNodeMap();

  for (OsmMap::NodeMap::const_iterator it = nm.begin(); it != nm.end(); ++it)
  {
    if (it.value()->getTags().contains("hoot:track:id") &&
        it.value()->getTags().contains("hoot:track:seq"))
    {
      QString trackId = it.value()->getTags()["hoot:track:id"];
      trackIdToNid[trackId].push_back(it.key());
    }
  }

  _sortTracks(map, trackIdToNid);
  _createWays(map, trackIdToNid);
}
Example #2
0
void MapCropper::apply(shared_ptr<OsmMap>& map)
{
  LOG_INFO("Cropping map.");
  shared_ptr<OsmMap> result = map;

  if (MapReprojector::isGeographic(map) == false && _nodeBounds.isNull() == false)
  {
    throw HootException("If the node bounds is set the projection must be geographic.");
  }

  // @todo visit the elements from the most senior (e.g. relation that has no parents) to the
  // most junior (nodes).

  // go through all the ways
  const WayMap ways = result->getWays();
  for (WayMap::const_iterator it = ways.begin(); it != ways.end(); it++)
  {
    const shared_ptr<Way>& w = it->second;
    shared_ptr<LineString> ls = ElementConverter(map).convertToLineString(w);
    const Envelope& e = *(ls->getEnvelopeInternal());

    // if the way is completely outside the region we're keeping
    if (_isWhollyOutside(e))
    {
      // remove the way
      result->removeWayFully(w->getId());
    }
    else if (_isWhollyInside(e))
    {
      // keep the way
    }
    else
    {
      // do an expensive operation to decide how much to keep, if any.
      _cropWay(result, w->getId());
    }
  }

  shared_ptr<NodeToWayMap> n2wp = result->getIndex().getNodeToWayMap();
  NodeToWayMap& n2w = *n2wp;

  LOG_INFO("  Removing nodes...");

  // go through all the nodes
  const OsmMap::NodeMap nodes = result->getNodeMap();
  for (OsmMap::NodeMap::const_iterator it = nodes.constBegin(); it != nodes.constEnd(); it++)
  {
    const Coordinate& c = it.value()->toCoordinate();

    bool nodeInside = false;

    if (_envelope.isNull() == false)
    {
      if (_invert == false)
      {
        nodeInside = _envelope.covers(c);
      }
      else
      {
        nodeInside = !_envelope.covers(c);
      }
    }
    else
    {
      auto_ptr<Point> p(GeometryFactory::getDefaultInstance()->createPoint(c));

      if (_invert == false)
      {
        nodeInside = _envelopeG->intersects(p.get());
      }
      else
      {
        nodeInside = !_envelopeG->intersects(p.get());
      }
    }

    // if the node is outside
    if (!nodeInside)
    {
      // if the node is within the limiting bounds.
      if (_nodeBounds.isNull() == true || _nodeBounds.contains(c))
      {
        // if the node is not part of a way
        if (n2w.find(it.key()) == n2w.end())
        {
          // remove the node
          result->removeNodeNoCheck(it.value()->getId());
        }
      }
    }
  }

  RemoveEmptyRelationsVisitor v;
  map->visitRw(v);
}