Search in sources :

Example 16 with IntersectionVertex

use of org.opentripplanner.routing.vertextype.IntersectionVertex in project OpenTripPlanner by opentripplanner.

the class TestGraph method testGetStreetEdgesNone.

public void testGetStreetEdgesNone() {
    Graph g = new Graph();
    Vertex a = new IntersectionVertex(g, "A", 5, 5);
    Vertex b = new IntersectionVertex(g, "B", 6, 6);
    Vertex c = new IntersectionVertex(g, "C", 3, 2);
    Set<Edge> allEdges = new HashSet<Edge>(4);
    allEdges.add(new FreeEdge(a, b));
    allEdges.add(new FreeEdge(b, c));
    allEdges.add(new FreeEdge(c, b));
    allEdges.add(new FreeEdge(c, a));
    Set<StreetEdge> edges = new HashSet<StreetEdge>(g.getStreetEdges());
    assertEquals(0, edges.size());
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Example 17 with IntersectionVertex

use of org.opentripplanner.routing.vertextype.IntersectionVertex in project OpenTripPlanner by opentripplanner.

the class TestBikeRental method testBasic.

public void testBasic() throws Exception {
    // generate a very simple graph
    Graph graph = new Graph();
    StreetVertex v1 = new IntersectionVertex(graph, "v1", -77.0492, 38.856, "v1");
    StreetVertex v2 = new IntersectionVertex(graph, "v2", -77.0492, 38.857, "v2");
    StreetVertex v3 = new IntersectionVertex(graph, "v3", -77.0492, 38.858, "v3");
    @SuppressWarnings("unused") Edge walk = new StreetEdge(v1, v2, GeometryUtils.makeLineString(-77.0492, 38.856, -77.0492, 38.857), "S. Crystal Dr", 87, StreetTraversalPermission.PEDESTRIAN, false);
    @SuppressWarnings("unused") Edge mustBike = new StreetEdge(v2, v3, GeometryUtils.makeLineString(-77.0492, 38.857, -77.0492, 38.858), "S. Crystal Dr", 87, StreetTraversalPermission.BICYCLE, false);
    AStar aStar = new AStar();
    // it is impossible to get from v1 to v3 by walking
    RoutingRequest options = new RoutingRequest(new TraverseModeSet("WALK,TRANSIT"));
    options.setRoutingContext(graph, v1, v3);
    ShortestPathTree tree = aStar.getShortestPathTree(options);
    GraphPath path = tree.getPath(v3, false);
    assertNull(path);
    // or biking + walking (assuming walking bikes is disallowed)
    options = new RoutingRequest(new TraverseModeSet("WALK,BICYCLE,TRANSIT"));
    options.freezeTraverseMode();
    options.setRoutingContext(graph, v1, v3);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(v3, false);
    assertNull(path);
    // so we add a bike share
    BikeRentalStation station = new BikeRentalStation();
    station.id = "id";
    station.name = new NonLocalizedString("station");
    station.x = -77.049;
    station.y = 36.856;
    station.bikesAvailable = 5;
    station.spacesAvailable = 5;
    BikeRentalStationVertex stationVertex = new BikeRentalStationVertex(graph, station);
    new StreetBikeRentalLink(stationVertex, v2);
    new StreetBikeRentalLink(v2, stationVertex);
    Set<String> networks = new HashSet<String>(Arrays.asList("default"));
    new RentABikeOnEdge(stationVertex, stationVertex, networks);
    new RentABikeOffEdge(stationVertex, stationVertex, networks);
    // but we can't get off the bike at v3, so we still fail
    options = new RoutingRequest(new TraverseModeSet("WALK,BICYCLE,TRANSIT"));
    options.freezeTraverseMode();
    options.setRoutingContext(graph, v1, v3);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(v3, false);
    // null is returned because the only state at the target is not final
    assertNull(path);
    BikeRentalStation station2 = new BikeRentalStation();
    station2.id = "id2";
    station2.name = new NonLocalizedString("station2");
    station2.x = -77.049;
    station2.y = 36.857;
    station2.bikesAvailable = 5;
    station2.spacesAvailable = 5;
    BikeRentalStationVertex stationVertex2 = new BikeRentalStationVertex(graph, station2);
    new StreetBikeRentalLink(stationVertex2, v3);
    new StreetBikeRentalLink(v3, stationVertex2);
    new RentABikeOnEdge(stationVertex2, stationVertex2, networks);
    new RentABikeOffEdge(stationVertex2, stationVertex2, networks);
    // now we succeed!
    options = new RoutingRequest();
    new QualifiedModeSet("BICYCLE_RENT,TRANSIT").applyToRoutingRequest(options);
    options.setRoutingContext(graph, v1, v3);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(v3, false);
    assertNotNull(path);
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) BikeRentalStationVertex(org.opentripplanner.routing.vertextype.BikeRentalStationVertex) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Example 18 with IntersectionVertex

use of org.opentripplanner.routing.vertextype.IntersectionVertex in project OpenTripPlanner by opentripplanner.

the class WalkableAreaBuilder method createSegments.

private void createSegments(OSMNode fromNode, OSMNode toNode, IntersectionVertex startEndpoint, IntersectionVertex endEndpoint, Collection<Area> areas, AreaEdgeList edgeList, Set<Edge> edges) {
    List<Area> intersects = new ArrayList<Area>();
    Coordinate[] coordinates = new Coordinate[] { startEndpoint.getCoordinate(), endEndpoint.getCoordinate() };
    GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
    LineString line = geometryFactory.createLineString(coordinates);
    for (Area area : areas) {
        MultiPolygon polygon = area.toJTSMultiPolygon();
        Geometry intersection = polygon.intersection(line);
        if (intersection.getLength() > 0.000001) {
            intersects.add(area);
        }
    }
    if (intersects.size() == 0) {
        // apparently our intersection here was bogus
        return;
    }
    // do we need to recurse?
    if (intersects.size() == 1) {
        Area area = intersects.get(0);
        OSMWithTags areaEntity = area.parent;
        StreetTraversalPermission areaPermissions = OSMFilter.getPermissionsForEntity(areaEntity, StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE);
        float carSpeed = wayPropertySet.getCarSpeedForWay(areaEntity, false);
        double length = SphericalDistanceLibrary.distance(startEndpoint.getCoordinate(), endEndpoint.getCoordinate());
        int cls = StreetEdge.CLASS_OTHERPATH;
        cls |= OSMFilter.getStreetClasses(areaEntity);
        String label = "way (area) " + areaEntity.getId() + " from " + startEndpoint.getLabel() + " to " + endEndpoint.getLabel();
        I18NString name = __handler.getNameForWay(areaEntity, label);
        AreaEdge street = edgeFactory.createAreaEdge(startEndpoint, endEndpoint, line, name, length, areaPermissions, false, edgeList);
        street.setCarSpeed(carSpeed);
        if (!areaEntity.hasTag("name") && !areaEntity.hasTag("ref")) {
            street.setHasBogusName(true);
        }
        if (areaEntity.isTagFalse("wheelchair")) {
            street.setWheelchairAccessible(false);
        }
        street.setStreetClass(cls);
        edges.add(street);
        label = "way (area) " + areaEntity.getId() + " from " + endEndpoint.getLabel() + " to " + startEndpoint.getLabel();
        name = __handler.getNameForWay(areaEntity, label);
        AreaEdge backStreet = edgeFactory.createAreaEdge(endEndpoint, startEndpoint, (LineString) line.reverse(), name, length, areaPermissions, true, edgeList);
        backStreet.setCarSpeed(carSpeed);
        if (!areaEntity.hasTag("name") && !areaEntity.hasTag("ref")) {
            backStreet.setHasBogusName(true);
        }
        if (areaEntity.isTagFalse("wheelchair")) {
            backStreet.setWheelchairAccessible(false);
        }
        backStreet.setStreetClass(cls);
        edges.add(backStreet);
        WayProperties wayData = wayPropertySet.getDataForWay(areaEntity);
        __handler.applyWayProperties(street, backStreet, wayData, areaEntity);
    } else {
        // take the part that intersects with the start vertex
        Coordinate startCoordinate = startEndpoint.getCoordinate();
        Point startPoint = geometryFactory.createPoint(startCoordinate);
        for (Area area : intersects) {
            MultiPolygon polygon = area.toJTSMultiPolygon();
            if (!(polygon.intersects(startPoint) || polygon.getBoundary().intersects(startPoint)))
                continue;
            Geometry lineParts = line.intersection(polygon);
            if (lineParts.getLength() > 0.000001) {
                Coordinate edgeCoordinate = null;
                // this is either a LineString or a MultiLineString (we hope)
                if (lineParts instanceof MultiLineString) {
                    MultiLineString mls = (MultiLineString) lineParts;
                    boolean found = false;
                    for (int i = 0; i < mls.getNumGeometries(); ++i) {
                        LineString segment = (LineString) mls.getGeometryN(i);
                        if (found) {
                            edgeCoordinate = segment.getEndPoint().getCoordinate();
                            break;
                        }
                        if (segment.contains(startPoint) || segment.getBoundary().contains(startPoint)) {
                            found = true;
                            if (segment.getLength() > 0.000001) {
                                edgeCoordinate = segment.getEndPoint().getCoordinate();
                                break;
                            }
                        }
                    }
                } else if (lineParts instanceof LineString) {
                    edgeCoordinate = ((LineString) lineParts).getEndPoint().getCoordinate();
                } else {
                    continue;
                }
                IntersectionVertex newEndpoint = areaBoundaryVertexForCoordinate.get(edgeCoordinate);
                if (newEndpoint == null) {
                    newEndpoint = new IntersectionVertex(graph, "area splitter at " + edgeCoordinate, edgeCoordinate.x, edgeCoordinate.y);
                    areaBoundaryVertexForCoordinate.put(edgeCoordinate, newEndpoint);
                }
                createSegments(fromNode, toNode, startEndpoint, newEndpoint, Arrays.asList(area), edgeList, edges);
                createSegments(fromNode, toNode, newEndpoint, endEndpoint, intersects, edgeList, edges);
                break;
            }
        }
    }
}
Also used : MultiLineString(com.vividsolutions.jts.geom.MultiLineString) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) I18NString(org.opentripplanner.util.I18NString) ArrayList(java.util.ArrayList) OSMWithTags(org.opentripplanner.openstreetmap.model.OSMWithTags) LineString(com.vividsolutions.jts.geom.LineString) I18NString(org.opentripplanner.util.I18NString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) Point(com.vividsolutions.jts.geom.Point) VLPoint(org.opentripplanner.visibility.VLPoint) Point(com.vividsolutions.jts.geom.Point) VLPoint(org.opentripplanner.visibility.VLPoint) AreaEdge(org.opentripplanner.routing.edgetype.AreaEdge) Geometry(com.vividsolutions.jts.geom.Geometry) NamedArea(org.opentripplanner.routing.edgetype.NamedArea) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission)

Example 19 with IntersectionVertex

use of org.opentripplanner.routing.vertextype.IntersectionVertex in project OpenTripPlanner by opentripplanner.

the class WalkableAreaBuilder method createEdgesForRingSegment.

private void createEdgesForRingSegment(Set<Edge> edges, AreaEdgeList edgeList, Area area, Ring ring, int i, HashSet<P2<OSMNode>> alreadyAddedEdges) {
    OSMNode node = ring.nodes.get(i);
    OSMNode nextNode = ring.nodes.get((i + 1) % ring.nodes.size());
    P2<OSMNode> nodePair = new P2<OSMNode>(node, nextNode);
    if (alreadyAddedEdges.contains(nodePair)) {
        return;
    }
    alreadyAddedEdges.add(nodePair);
    IntersectionVertex startEndpoint = __handler.getVertexForOsmNode(node, area.parent);
    IntersectionVertex endEndpoint = __handler.getVertexForOsmNode(nextNode, area.parent);
    createSegments(node, nextNode, startEndpoint, endEndpoint, Arrays.asList(area), edgeList, edges);
}
Also used : P2(org.opentripplanner.common.model.P2) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode)

Example 20 with IntersectionVertex

use of org.opentripplanner.routing.vertextype.IntersectionVertex in project OpenTripPlanner by opentripplanner.

the class AreaEdgeList method createSegments.

private void createSegments(IntersectionVertex from, IntersectionVertex to, List<NamedArea> areas, Graph graph) {
    GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
    LineString line = geometryFactory.createLineString(new Coordinate[] { from.getCoordinate(), to.getCoordinate() });
    List<NamedArea> intersects = new ArrayList<NamedArea>();
    for (NamedArea area : areas) {
        Geometry polygon = area.getPolygon();
        Geometry intersection = polygon.intersection(line);
        if (intersection.getLength() > 0.000001) {
            intersects.add(area);
        }
    }
    if (intersects.size() == 1) {
        NamedArea area = intersects.get(0);
        double length = SphericalDistanceLibrary.distance(to.getCoordinate(), from.getCoordinate());
        AreaEdge forward = new AreaEdge(from, to, line, area.getRawName(), length, area.getPermission(), false, this);
        forward.setStreetClass(area.getStreetClass());
        AreaEdge backward = new AreaEdge(to, from, (LineString) line.reverse(), area.getRawName(), length, area.getPermission(), true, this);
        backward.setStreetClass(area.getStreetClass());
        edges.add(forward);
        edges.add(backward);
    } else {
        Coordinate startCoordinate = from.getCoordinate();
        Point startPoint = geometryFactory.createPoint(startCoordinate);
        for (NamedArea area : intersects) {
            Geometry polygon = area.getPolygon();
            if (!polygon.intersects(startPoint))
                continue;
            Geometry lineParts = line.intersection(polygon);
            if (lineParts.getLength() > 0.000001) {
                Coordinate edgeCoordinate = null;
                // this is either a LineString or a MultiLineString (we hope)
                if (lineParts instanceof MultiLineString) {
                    MultiLineString mls = (MultiLineString) lineParts;
                    for (int i = 0; i < mls.getNumGeometries(); ++i) {
                        LineString segment = (LineString) mls.getGeometryN(i);
                        if (segment.contains(startPoint) || segment.getBoundary().contains(startPoint)) {
                            edgeCoordinate = segment.getEndPoint().getCoordinate();
                        }
                    }
                } else if (lineParts instanceof LineString) {
                    edgeCoordinate = ((LineString) lineParts).getEndPoint().getCoordinate();
                } else {
                    continue;
                }
                String label = "area splitter at " + edgeCoordinate;
                IntersectionVertex newEndpoint = (IntersectionVertex) graph.getVertex(label);
                if (newEndpoint == null) {
                    newEndpoint = new IntersectionVertex(graph, label, edgeCoordinate.x, edgeCoordinate.y);
                }
                createSegments(from, newEndpoint, Arrays.asList(area), graph);
                createSegments(newEndpoint, to, intersects, graph);
                break;
            }
        }
    }
}
Also used : MultiLineString(com.vividsolutions.jts.geom.MultiLineString) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ArrayList(java.util.ArrayList) Point(com.vividsolutions.jts.geom.Point) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) Point(com.vividsolutions.jts.geom.Point) Geometry(com.vividsolutions.jts.geom.Geometry) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex)

Aggregations

IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)38 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)23 Graph (org.opentripplanner.routing.graph.Graph)17 Coordinate (com.vividsolutions.jts.geom.Coordinate)16 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)14 Vertex (org.opentripplanner.routing.graph.Vertex)12 LineString (com.vividsolutions.jts.geom.LineString)10 Test (org.junit.Test)10 Edge (org.opentripplanner.routing.graph.Edge)10 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)8 HashSet (java.util.HashSet)8 FreeEdge (org.opentripplanner.routing.edgetype.FreeEdge)8 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)5 ArrayList (java.util.ArrayList)5 Point (com.vividsolutions.jts.geom.Point)4 P2 (org.opentripplanner.common.model.P2)4 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)4 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)3 State (org.opentripplanner.routing.core.State)3 AreaEdge (org.opentripplanner.routing.edgetype.AreaEdge)3