Beispiel #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 "";
 }
Beispiel #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;
 }