Package org.opentripplanner.routing.graph

Examples of org.opentripplanner.routing.graph.Edge


                    // -- get all Edges needed later for the edge representation
                    // and to calculate an edge-based walkshed
                    // Note, it can happen that we get a null geometry here, e.g. for hop-edges!
                    Collection<Edge> vertexEdgesIn = state.getVertex().getIncoming();
                    for (Iterator<Edge> iterator = vertexEdgesIn.iterator(); iterator.hasNext();) {
                        Edge edge = (Edge) iterator.next();
                        Geometry edgeGeom = edge.getGeometry();
                        if (edgeGeom != null) { // make sure we get only real edges
                            if (edgeGeom instanceof LineString) {
                                // allConnectingEdges.add(edge); // instead of this, use a map now, so we don't have similar edge many times
                                connectingEdgesMap.put(new ReversibleLineStringWrapper(
                                        (LineString) edgeGeom), edge);
                            }
                        }
                    }
                    Collection<Edge> vertexEdgesOut = state.getVertex().getOutgoing();
                    for (Iterator<Edge> iterator = vertexEdgesOut.iterator(); iterator.hasNext();) {
                        Edge edge = (Edge) iterator.next();
                        Geometry edgeGeom = edge.getGeometry();
                        if (edgeGeom != null) {
                            if (edgeGeom instanceof LineString) {
                                // allConnectingEdges.add(edge); // instead of this, use a map now, so we don't similar edge many times
                                connectingEdgesMap.put(new ReversibleLineStringWrapper(
                                        (LineString) edgeGeom), edge);
View Full Code Here


        ArrayList<LineString> borderEdges = new ArrayList<LineString>();
        ArrayList<LineString> uShapes = new ArrayList<LineString>();
        int countEdgesOutside = 0;
        // -- determination of walkshed edges via edge states
        for (Iterator iterator = allConnectingStateEdges.iterator(); iterator.hasNext();) {
            Edge edge = (Edge) iterator.next();
            State sFrom = spt.getState(edge.getFromVertex());
            State sTo = spt.getState(edge.getToVertex());
            if ((sFrom != null) && (sTo != null)) {
                long fromTime = sFrom.getElapsedTimeSeconds();
                long toTime = sTo.getElapsedTimeSeconds();
                long dt = Math.abs(toTime - fromTime);
                Geometry edgeGeom = edge.getGeometry();
                if ((edgeGeom != null) && (edgeGeom instanceof LineString)) {
                    LineString ls = (LineString) edgeGeom;
                    // detect u-shape roads/crescents - they need to be treated separately
                    boolean uShapeOrLonger = testForUshape(edge, maxTime, fromTime, toTime,
                            angleLimit, distanceTolerance, userSpeed, hasCar, performSpeedTest);
                    if (uShapeOrLonger) {
                        uShapes.add(ls);
                    }

                    // evaluate if an edge is completely within the time or only with one end
                    if ((fromTime < maxTime) && (toTime < maxTime)) {
                        // this one is within the time limit on both ends, however we need to do
                        // a second test if we have a u-shaped road.
                        if (uShapeOrLonger) {
                            treatAndAddUshapeWithinTimeLimits(maxTime, userSpeed, walkShedEdges,
                                    edge, fromTime, toTime, ls, hasCar);
                        } else {
                            walkShedEdges.add(ls);
                        }
                    }// end if:fromTime & toTime < maxTime
                    else {
                        // check if at least one end is inside, because then we need to
                        // create the sub edge
                        if ((fromTime < maxTime) || (toTime < maxTime)) {
                            double lineDist = edge.getDistance();
                            LineString inputLS = ls;
                            double fraction = 1.0;
                            if (fromTime < toTime) {
                                double distanceToWalkInTimeMissing = distanceToMoveInRemainingTime(
                                        maxTime, fromTime, dt, userSpeed, edge, hasCar,
                                        uShapeOrLonger);
                                fraction = (double) distanceToWalkInTimeMissing / (double) lineDist;
                            } else {
                                // toTime < fromTime : invert the edge direction
                                inputLS = (LineString) ls.reverse();
                                double distanceToWalkInTimeMissing = distanceToMoveInRemainingTime(
                                        maxTime, toTime, dt, userSpeed, edge, hasCar,
                                        uShapeOrLonger);
                                fraction = (double) distanceToWalkInTimeMissing / (double) lineDist;
                            }
                            // get the subedge
                            LineString subLine = this.getSubLineString(inputLS, fraction);
                            borderEdges.add(subLine);
                        } else {
                            // this edge is completely outside - this should actually not happen
                            // we will not do anything, just count
                            countEdgesOutside++;
                        }
                    }// end else: fromTime & toTime < maxTime
                }// end if: edge instance of LineString
                else {
                    // edge is not instance of LineString
                    LOG.debug("edge not instance of LineString");
                }
            }// end if(sFrom && sTo != null) start Else
            else {
                // LOG.debug("could not retrieve state for edge-endpoint"); //for a 6min car ride, there can be (too) many of such messages
                Geometry edgeGeom = edge.getGeometry();
                if ((edgeGeom != null) && (edgeGeom instanceof LineString)) {
                    otherEdges.add((LineString) edgeGeom);
                }
            }// end else: sFrom && sTo != null
        }// end for loop over edges
View Full Code Here

            TraverseMode backMode = states[i].getBackMode();
            TraverseMode forwardMode = states[i + 1].getBackMode();

            if (backMode == null || forwardMode == null) continue;

            Edge edge = states[i + 1].getBackEdge();

            if (backMode == TraverseMode.LEG_SWITCH || forwardMode == TraverseMode.LEG_SWITCH) {
                if (backMode != TraverseMode.LEG_SWITCH) {              // Start of leg switch
                    legIndexPairs[1] = i;
                } else if (forwardMode != TraverseMode.LEG_SWITCH) {    // End of leg switch
View Full Code Here

     */
    private void addModeAndAlerts(Graph graph, Leg leg, State[] states) {
        for (State state : states) {
            TraverseMode mode = state.getBackMode();
            Set<Alert> alerts = graph.streetNotesService.getNotes(state);
            Edge edge = state.getBackEdge();

            if (mode != null) {
                leg.mode = mode.toString();
            }

View Full Code Here

        String roundaboutPreviousStreet = null;

        for (int i = 0; i < states.length - 1; i++) {
            State backState = states[i];
            State forwardState = states[i + 1];
            Edge edge = forwardState.getBackEdge();
            boolean createdNewStep = false, disableZagRemovalForThisStep = false;
            if (edge instanceof FreeEdge) {
                continue;
            }
            if (forwardState.getBackMode() == null || !forwardState.getBackMode().isOnStreetNonTransit()) {
                continue; // ignore STLs and the like
            }
            Geometry geom = edge.getGeometry();
            if (geom == null) {
                continue;
            }

            // generate a step for getting off an elevator (all
            // elevator narrative generation occurs when alighting). We don't need to know what came
            // before or will come after
            if (edge instanceof ElevatorAlightEdge) {
                // don't care what came before or comes after
                step = createWalkStep(graph, forwardState);
                createdNewStep = true;
                disableZagRemovalForThisStep = true;

                // tell the user where to get off the elevator using the exit notation, so the
                // i18n interface will say 'Elevator to <exit>'
                // what happens is that the webapp sees name == null and ignores that, and it sees
                // exit != null and uses to <exit>
                // the floor name is the AlightEdge name
                // reset to avoid confusion with 'Elevator on floor 1 to floor 1'
                step.streetName = ((ElevatorAlightEdge) edge).getName();

                step.relativeDirection = RelativeDirection.ELEVATOR;

                steps.add(step);
                continue;
            }

            String streetName = edge.getName();
            int idx = streetName.indexOf('(');
            String streetNameNoParens;
            if (idx > 0)
                streetNameNoParens = streetName.substring(0, idx - 1);
            else
                streetNameNoParens = streetName;

            if (step == null) {
                // first step
                step = createWalkStep(graph, forwardState);
                createdNewStep = true;

                steps.add(step);
                double thisAngle = DirectionUtils.getFirstAngle(geom);
                if (previous == null) {
                    step.setAbsoluteDirection(thisAngle);
                    step.relativeDirection = RelativeDirection.DEPART;
                } else {
                    step.setDirections(previous.angle, thisAngle, false);
                }
                // new step, set distance to length of first edge
                distance = edge.getDistance();
            } else if (((step.streetName != null && !step.streetNameNoParens().equals(streetNameNoParens))
                    && (!step.bogusName || !edge.hasBogusName())) ||
                    // if we are on a roundabout now and weren't before, start a new step
                    edge.isRoundabout() != (roundaboutExit > 0) ||
                    isLink(edge) && !isLink(backState.getBackEdge())
                    ) {
                /* street name has changed, or we've changed state from a roundabout to a street */
                if (roundaboutExit > 0) {
                    // if we were just on a roundabout,
                    // make note of which exit was taken in the existing step
                    step.exit = Integer.toString(roundaboutExit); // ordinal numbers from
                    if (streetNameNoParens.equals(roundaboutPreviousStreet)) {
                        step.stayOn = true;
                    }
                    // localization
                    roundaboutExit = 0;
                }
                /* start a new step */
                step = createWalkStep(graph, forwardState);
                createdNewStep = true;

                steps.add(step);
                if (edge.isRoundabout()) {
                    // indicate that we are now on a roundabout
                    // and use one-based exit numbering
                    roundaboutExit = 1;
                    roundaboutPreviousStreet = backState.getBackEdge().getName();
                    idx = roundaboutPreviousStreet.indexOf('(');
                    if (idx > 0)
                        roundaboutPreviousStreet = roundaboutPreviousStreet.substring(0, idx - 1);
                }
                double thisAngle = DirectionUtils.getFirstAngle(geom);
                step.setDirections(lastAngle, thisAngle, edge.isRoundabout());
                // new step, set distance to length of first edge
                distance = edge.getDistance();
            } else {
                /* street name has not changed */
                double thisAngle = DirectionUtils.getFirstAngle(geom);
                RelativeDirection direction = WalkStep.getRelativeDirection(lastAngle, thisAngle,
                        edge.isRoundabout());
                boolean optionsBefore = backState.multipleOptionsBefore();
                if (edge.isRoundabout()) {
                    // we are on a roundabout, and have already traversed at least one edge of it.
                    if (optionsBefore) {
                        // increment exit count if we passed one.
                        roundaboutExit += 1;
                    }
                }
                if (edge.isRoundabout() || direction == RelativeDirection.CONTINUE) {
                    // we are continuing almost straight, or continuing along a roundabout.
                    // just append elevation info onto the existing step.

                } else {
                    // we are not on a roundabout, and not continuing straight through.

                    // figure out if there were other plausible turn options at the last
                    // intersection
                    // to see if we should generate a "left to continue" instruction.
                    boolean shouldGenerateContinue = false;
                    if (edge instanceof StreetEdge) {
                        // the next edges will be PlainStreetEdges, we hope
                        double angleDiff = getAbsoluteAngleDiff(thisAngle, lastAngle);
                        for (Edge alternative : backState.getVertex().getOutgoingStreetEdges()) {
                            if (alternative.getName().equals(streetName)) {
                                // alternatives that have the same name
                                // are usually caused by street splits
                                continue;
                            }
                            double altAngle = DirectionUtils.getFirstAngle(alternative
                                    .getGeometry());
                            double altAngleDiff = getAbsoluteAngleDiff(altAngle, lastAngle);
                            if (angleDiff > Math.PI / 4 || altAngleDiff - angleDiff < Math.PI / 16) {
                                shouldGenerateContinue = true;
                                break;
                            }
                        }
                    } else {
                        double angleDiff = getAbsoluteAngleDiff(lastAngle, thisAngle);
                        // FIXME: this code might be wrong with the removal of the edge-based graph
                        State twoStatesBack = backState.getBackState();
                        Vertex backVertex = twoStatesBack.getVertex();
                        for (Edge alternative : backVertex.getOutgoingStreetEdges()) {
                            List<Edge> alternatives = alternative.getToVertex()
                                    .getOutgoingStreetEdges();
                            if (alternatives.size() == 0) {
                                continue; // this is not an alternative
                            }
                            alternative = alternatives.get(0);
                            if (alternative.getName().equals(streetName)) {
                                // alternatives that have the same name
                                // are usually caused by street splits
                                continue;
                            }
                            double altAngle = DirectionUtils.getFirstAngle(alternative
                                    .getGeometry());
                            double altAngleDiff = getAbsoluteAngleDiff(altAngle, lastAngle);
                            if (angleDiff > Math.PI / 4 || altAngleDiff - angleDiff < Math.PI / 16) {
                                shouldGenerateContinue = true;
                                break;
                            }
                        }
                    }

                    if (shouldGenerateContinue) {
                        // turn to stay on same-named street
                        step = createWalkStep(graph, forwardState);
                        createdNewStep = true;
                        steps.add(step);
                        step.setDirections(lastAngle, thisAngle, false);
                        step.stayOn = true;
                        // new step, set distance to length of first edge
                        distance = edge.getDistance();
                    }
                }
            }

            State exitState = backState;
            Edge exitEdge = exitState.getBackEdge();
            while (exitEdge instanceof FreeEdge) {
                exitState = exitState.getBackState();
                exitEdge = exitState.getBackEdge();
            }
            if (exitState.getVertex() instanceof ExitVertex) {
View Full Code Here

        }
        return angleDiff;
    }

    private static WalkStep createWalkStep(Graph graph, State s) {
        Edge en = s.getBackEdge();
        WalkStep step;
        step = new WalkStep();
        step.streetName = en.getName();
        step.lon = en.getFromVertex().getX();
        step.lat = en.getFromVertex().getY();
        step.elevation = encodeElevationProfile(s.getBackEdge(), 0);
        step.bogusName = en.hasBogusName();
        step.addAlerts(graph.streetNotesService.getNotes(s));
        step.angle = DirectionUtils.getFirstAngle(s.getBackEdge().getGeometry());
        if (s.getBackEdge() instanceof AreaEdge) {
            step.area = true;
        }
View Full Code Here

    final int EXPENSIVE_EXPRESS_BUS = 34;
    final int WALK = -1;

    for (State state : states) {

      Edge backEdge = state.getBackEdge();
      if (backEdge instanceof StreetEdge) {
        if (newRide == null || !newRide.classifier.equals(WALK)) {
          if (rides.size() == 0 || !rides.get(rides.size() - 1).classifier.equals(WALK)) {
            newRide = new Ride();
            newRide.classifier = WALK;
View Full Code Here

        Set<Integer> overlappingIds = uIds;

        // Fetch the edges by ID - important so we aren't stuck with temporary edges.
        Set<StreetEdge> overlap = new HashSet<StreetEdge>();
        for (Integer id : overlappingIds) {
            Edge e = graph.getEdgeById(id);
            if (e == null || !(e instanceof StreetEdge)) {
                continue;
            }

            overlap.add((StreetEdge) e);
View Full Code Here

            }
        }
        calendarService = graph.getCalendarService();
        setServiceDays();

        Edge fromBackEdge = null;
        Edge toBackEdge = null;
        if (findPlaces) {
            // normal mode, search for vertices based RoutingRequest
            if (!opt.batch || opt.arriveBy) {
                // non-batch mode, or arriveBy batch mode: we need a to vertex
                toVertex = graph.streetIndex.getVertexForLocation(opt.to, opt);
View Full Code Here

      public void actionPerformed(ActionEvent e) {
        if(lastStateClicked==null){
          return;
        }
       
        Edge backEdge = lastStateClicked.getBackEdge();
        State backState = lastStateClicked.getBackState();
       
        backEdge.traverse(backState);
      }
        });
        pane.add(traverseButton);
       
        return pane;
View Full Code Here

TOP

Related Classes of org.opentripplanner.routing.graph.Edge

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.