Exemplo n.º 1
0
WayLocation PertyWaySplitVisitor::_calcSplitPoint(ConstWayPtr way) const
{
  //create a way location that is the minimum node spacing distance from the beginning of the way
  WayLocation splitWayStart(_map->shared_from_this(), way, _minNodeSpacing);
  //create a way location that is the minimum node spacing from the end of the way
  WayLocation splitWayEnd = WayLocation::createAtEndOfWay(_map->shared_from_this(), way).
      move(-1 * _minNodeSpacing);
  //if the length between the way locations is greater than zero, then then a way location can be
  //selected that doesn't violate the min node spacing
  const double splitWayLength =
    splitWayEnd.calculateDistanceOnWay() - splitWayStart.calculateDistanceOnWay();
  LOG_VART(splitWayLength);
  if (splitWayLength > 0)
  {
    boost::uniform_real<> randomSplitPointDistribution(0.0, splitWayLength);
    const double splitPoint = randomSplitPointDistribution(*_rng);
    LOG_VART(splitPoint);
    return splitWayStart.move(splitPoint);
  }
  //otherwise, return an empty location
  else
  {
    return WayLocation();
  }
}
Exemplo n.º 2
0
void MaximalSubline::_snapToTerminal(WayLocation& wl, bool startOfLines, double thresh)
{
    Meters d1 = wl.calculateDistanceOnWay();

    // if we're not at the start of the line
    if (!startOfLines)
    {
        // calculate the distance from the end to this way location.
        d1 = ElementConverter(wl.getMap()).convertToLineString(wl.getWay())->getLength() - d1;
    }

    if (thresh == -1)
    {
        thresh = _minSplitSize;
    }

    // if we should snap the end points
    if (d1 <= thresh)
    {
        // if we're at the start of the line
        if (startOfLines)
        {
            // snap to the beginning
            wl = WayLocation(wl.getMap(), wl.getWay(), 0, 0.0);
        }
        // if we're at the end of the line
        else
        {
            // snap to the end
            wl = WayLocation(wl.getMap(), wl.getWay(), wl.getWay()->getNodeCount(), 0.0);
        }
    }
}