Search in sources :

Example 11 with P2

use of org.opentripplanner.common.model.P2 in project OpenTripPlanner by opentripplanner.

the class TestOpenStreetMapGraphBuilder method testBuildGraphDetailed.

/**
 * Detailed testing of OSM graph building using a very small chunk of NYC (SOHO-ish).
 * @throws Exception
 */
@Test
public void testBuildGraphDetailed() throws Exception {
    Graph gg = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
    File file = new File(URLDecoder.decode(getClass().getResource("NYC_small.osm.gz").getFile(), "UTF-8"));
    provider.setPath(file);
    loader.setProvider(provider);
    loader.buildGraph(gg, extra);
    // These vertices are labeled in the OSM file as having traffic lights.
    IntersectionVertex iv1 = (IntersectionVertex) gg.getVertex("osm:node:1919595918");
    IntersectionVertex iv2 = (IntersectionVertex) gg.getVertex("osm:node:42442273");
    IntersectionVertex iv3 = (IntersectionVertex) gg.getVertex("osm:node:1919595927");
    IntersectionVertex iv4 = (IntersectionVertex) gg.getVertex("osm:node:42452026");
    assertTrue(iv1.trafficLight);
    assertTrue(iv2.trafficLight);
    assertTrue(iv3.trafficLight);
    assertTrue(iv4.trafficLight);
    // These are not.
    IntersectionVertex iv5 = (IntersectionVertex) gg.getVertex("osm:node:42435485");
    IntersectionVertex iv6 = (IntersectionVertex) gg.getVertex("osm:node:42439335");
    IntersectionVertex iv7 = (IntersectionVertex) gg.getVertex("osm:node:42436761");
    IntersectionVertex iv8 = (IntersectionVertex) gg.getVertex("osm:node:42442291");
    assertFalse(iv5.trafficLight);
    assertFalse(iv6.trafficLight);
    assertFalse(iv7.trafficLight);
    assertFalse(iv8.trafficLight);
    Set<P2<Integer>> edgeEndpoints = new HashSet<P2<Integer>>();
    for (StreetEdge se : gg.getStreetEdges()) {
        P2<Integer> endpoints = new P2<Integer>(se.getFromVertex().getIndex(), se.getToVertex().getIndex());
        // Check that we don't get any duplicate edges on this small graph.
        if (edgeEndpoints.contains(endpoints)) {
            assertFalse(true);
        }
        edgeEndpoints.add(endpoints);
    }
}
Also used : P2(org.opentripplanner.common.model.P2) Graph(org.opentripplanner.routing.graph.Graph) FileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) File(java.io.File) Test(org.junit.Test)

Example 12 with P2

use of org.opentripplanner.common.model.P2 in project OpenTripPlanner by opentripplanner.

the class DegreeGridNEDTileSource method getNEDTiles.

@Override
public List<File> getNEDTiles() {
    HashSet<P2<Integer>> tiles = new HashSet<P2<Integer>>();
    for (Vertex v : graph.getVertices()) {
        Coordinate coord = v.getCoordinate();
        tiles.add(new P2<Integer>((int) coord.x, (int) coord.y));
    }
    List<File> paths = new ArrayList<File>();
    for (P2<Integer> tile : tiles) {
        int x = tile.first - 1;
        int y = tile.second + 1;
        paths.add(getPathToTile(x, y));
    }
    return paths;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) P2(org.opentripplanner.common.model.P2) Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList) File(java.io.File) HashSet(java.util.HashSet)

Example 13 with P2

use of org.opentripplanner.common.model.P2 in project OpenTripPlanner by opentripplanner.

the class OSMFilter method getPermissions.

/**
 * Check OSM tags for various one-way and one-way-by-mode tags and return a pair of permissions
 * for travel along and against the way.
 */
public static P2<StreetTraversalPermission> getPermissions(StreetTraversalPermission permissions, OSMWay way) {
    StreetTraversalPermission permissionsFront = permissions;
    StreetTraversalPermission permissionsBack = permissions;
    // Check driving direction restrictions.
    if (way.isOneWayForwardDriving() || way.isRoundabout()) {
        permissionsBack = permissionsBack.remove(StreetTraversalPermission.BICYCLE_AND_CAR);
    }
    if (way.isOneWayReverseDriving()) {
        permissionsFront = permissionsFront.remove(StreetTraversalPermission.BICYCLE_AND_CAR);
    }
    // Check bike direction restrictions.
    if (way.isOneWayForwardBicycle()) {
        permissionsBack = permissionsBack.remove(StreetTraversalPermission.BICYCLE);
    }
    if (way.isOneWayReverseBicycle()) {
        permissionsFront = permissionsFront.remove(StreetTraversalPermission.BICYCLE);
    }
    // TODO(flamholz): figure out what this is for.
    String oneWayBicycle = way.getTag("oneway:bicycle");
    if (OSMWithTags.isFalse(oneWayBicycle) || way.isTagTrue("bicycle:backwards")) {
        if (permissions.allows(StreetTraversalPermission.BICYCLE)) {
            permissionsFront = permissionsFront.add(StreetTraversalPermission.BICYCLE);
            permissionsBack = permissionsBack.add(StreetTraversalPermission.BICYCLE);
        }
    }
    // TAG: bicycle:forward=use_sidepath
    if (way.isForwardDirectionSidepath()) {
        permissionsFront = permissionsFront.remove(StreetTraversalPermission.BICYCLE);
    }
    // TAG bicycle:backward=use_sidepath
    if (way.isReverseDirectionSidepath()) {
        permissionsBack = permissionsBack.remove(StreetTraversalPermission.BICYCLE);
    }
    if (way.isOpposableCycleway()) {
        permissionsBack = permissionsBack.add(StreetTraversalPermission.BICYCLE);
    }
    return new P2<StreetTraversalPermission>(permissionsFront, permissionsBack);
}
Also used : P2(org.opentripplanner.common.model.P2) StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission)

Aggregations

P2 (org.opentripplanner.common.model.P2)13 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)4 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 LineString (com.vividsolutions.jts.geom.LineString)3 OSMNode (org.opentripplanner.openstreetmap.model.OSMNode)3 StreetTraversalPermission (org.opentripplanner.routing.edgetype.StreetTraversalPermission)3 Edge (org.opentripplanner.routing.graph.Edge)3 Vertex (org.opentripplanner.routing.graph.Vertex)3 LinearRing (com.vividsolutions.jts.geom.LinearRing)2 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)2 Point (com.vividsolutions.jts.geom.Point)2 LinearLocation (com.vividsolutions.jts.linearref.LinearLocation)2 LocationIndexedLine (com.vividsolutions.jts.linearref.LocationIndexedLine)2 File (java.io.File)2 Stop (org.onebusaway.gtfs.model.Stop)2 AreaEdge (org.opentripplanner.routing.edgetype.AreaEdge)2 AreaEdgeList (org.opentripplanner.routing.edgetype.AreaEdgeList)2