Example #1
0
 public String allStopsWithCorrectLink() {
   for (StopTime stopTime : trip.getStopTimes().values()) {
     Stop stop = stops.get(stopTime.getStopId());
     Link link = network.getLinks().get(Id.create(stop.getLinkId(), Link.class));
     Point2D fromPoint =
         new Point2D(link.getFromNode().getCoord().getX(), link.getFromNode().getCoord().getY());
     Point2D toPoint =
         new Point2D(link.getToNode().getCoord().getX(), link.getToNode().getCoord().getY());
     Line2D linkLine = new Line2D(fromPoint, toPoint);
     Point2D point = new Point2D(stop.getPoint().getX(), stop.getPoint().getY());
     if (!linkLine.isNearestInside(point)) {
       int pos = getLinkPosition(link.getId().toString());
       if (pos == -1) return stopTime.getStopId();
       if (pos == links.size() - 1 || pos == 0) return "";
       Link link2 = links.get(pos + 1);
       fromPoint =
           new Point2D(
               link2.getFromNode().getCoord().getX(), link2.getFromNode().getCoord().getY());
       toPoint =
           new Point2D(link2.getToNode().getCoord().getX(), link2.getToNode().getCoord().getY());
       Line2D linkLine2 = new Line2D(fromPoint, toPoint);
       if (!(linkLine.getPointPosition(point).equals(Line2D.PointPosition.AFTER)
           && linkLine2.getPointPosition(point).equals(Line2D.PointPosition.BEFORE)))
         return stopTime.getStopId();
     }
   }
   return "";
 }
Example #2
0
 private List<Link> getBestLinksMode(Network network, Coord coord, Shape shape) {
   List<Double> nearestDistances = new ArrayList<Double>();
   List<Link> nearestLinks = new ArrayList<Link>();
   for (double minDistance = this.minDistance;
       nearestLinks.size() < numCandidates;
       minDistance += MIN_DISTANCE_DELTA)
     for (Link link : network.getLinks().values())
       if (link.getAllowedModes().contains(mode)) {
         Point2D fromPoint =
             new Point2D(
                 link.getFromNode().getCoord().getX(), link.getFromNode().getCoord().getY());
         Point2D toPoint =
             new Point2D(link.getToNode().getCoord().getX(), link.getToNode().getCoord().getY());
         Vector2D linkVector = new Vector2D(fromPoint, toPoint);
         Line2D linkSegment = new Line2D(fromPoint, toPoint);
         if (!withInsideStops
             || linkSegment.isNearestInside(new Point2D(coord.getX(), coord.getY())))
           if (!withAngleShape
               || shape == null
               || linkVector.getAngleTo(shape.getVector(coord)) < Math.PI / 16) {
             double distance = ((LinkImpl) link).calcDistance(coord);
             if (distance < minDistance) {
               int i = 0;
               for (; i < nearestDistances.size() && distance < nearestDistances.get(i); i++) ;
               if (i > 0 || nearestLinks.size() < numCandidates) {
                 nearestDistances.add(i, distance);
                 nearestLinks.add(i, link);
                 if (nearestLinks.size() > numCandidates) {
                   nearestDistances.remove(0);
                   nearestLinks.remove(0);
                 }
               }
             }
           }
       }
   return nearestLinks;
 }
Example #3
0
 private double calculateDistance(Path path, Coord prevStop, Coord nextStop) {
   LinkImpl firstLink = (LinkImpl) path.links.get(0);
   Point2D fromPoint =
       new Point2D(
           firstLink.getFromNode().getCoord().getX(), firstLink.getFromNode().getCoord().getY());
   Point2D toPoint =
       new Point2D(
           firstLink.getToNode().getCoord().getX(), firstLink.getToNode().getCoord().getY());
   Line2D firstLinkLine = new Line2D(fromPoint, toPoint);
   double distance = firstLink.calcDistance(prevStop);
   if (path.links.size() == 1) {
     distance +=
         firstLinkLine
             .getNearestPoint(new Point2D(prevStop.getX(), prevStop.getY()))
             .getDistance(
                 firstLinkLine.getNearestPoint(new Point2D(nextStop.getX(), nextStop.getY())));
     distance += firstLink.calcDistance(nextStop);
   } else {
     Coord firstToNodeCoord = firstLink.getToNode().getCoord();
     distance +=
         firstLinkLine
             .getNearestPoint(new Point2D(prevStop.getX(), prevStop.getY()))
             .getDistance(new Point2D(firstToNodeCoord.getX(), firstToNodeCoord.getY()));
     LinkImpl lastLink = (LinkImpl) path.links.get(path.links.size() - 1);
     Point2D fromPoint2 =
         new Point2D(
             lastLink.getFromNode().getCoord().getX(), lastLink.getFromNode().getCoord().getY());
     Point2D toPoint2 =
         new Point2D(
             lastLink.getToNode().getCoord().getX(), lastLink.getToNode().getCoord().getY());
     Line2D lastLinkLine = new Line2D(fromPoint2, toPoint2);
     for (int i = 1; i < path.links.size() - 1; i++) distance += path.links.get(i).getLength();
     Coord lastFromNodeCoord = lastLink.getFromNode().getCoord();
     distance +=
         lastLinkLine
             .getNearestPoint(new Point2D(nextStop.getX(), nextStop.getY()))
             .getDistance(new Point2D(lastFromNodeCoord.getX(), lastFromNodeCoord.getY()));
     distance += lastLink.calcDistance(nextStop);
   }
   return distance;
 }