Search in sources :

Example 6 with BinaryOpenStreetMapProvider

use of org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider in project OpenTripPlanner by opentripplanner.

the class TestOpenStreetMapGraphBuilder method testBuildingAreas.

/**
 * This reads test file with area
 * and tests if it can be routed if visibility is used and if it isn't
 *
 * Routing needs to be successful in both options since without visibility calculation
 * area rings are used.
 * @param skipVisibility if true visibility calculations are skipped
 * @throws UnsupportedEncodingException
 */
private void testBuildingAreas(boolean skipVisibility) throws UnsupportedEncodingException {
    Graph graph = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.skipVisibility = skipVisibility;
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    File file = new File(URLDecoder.decode(getClass().getResource("usf_area.osm.pbf").getFile(), "UTF-8"));
    BinaryOpenStreetMapProvider provider = new BinaryOpenStreetMapProvider(file, false);
    loader.setProvider(provider);
    loader.buildGraph(graph, extra);
    new StreetVertexIndex(graph);
    Router router = new Router(graph, RouterConfig.DEFAULT);
    router.startup();
    RoutingRequest request = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK));
    // This are vertices that can be connected only over edges on area (with correct permissions)
    // It tests if it is possible to route over area without visibility calculations
    Vertex bottomV = graph.getVertex("osm:node:580290955");
    Vertex topV = graph.getVertex("osm:node:559271124");
    request.setRoutingContext(router.graph, bottomV, topV);
    GraphPathFinder graphPathFinder = new GraphPathFinder(router);
    List<GraphPath> pathList = graphPathFinder.graphPathFinderEntryPoint(request);
    assertNotNull(pathList);
    assertFalse(pathList.isEmpty());
    for (GraphPath path : pathList) {
        assertFalse(path.states.isEmpty());
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) GraphPath(org.opentripplanner.routing.spt.GraphPath) Router(org.opentripplanner.standalone.server.Router) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) BinaryOpenStreetMapProvider(org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider) Graph(org.opentripplanner.routing.graph.Graph) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) File(java.io.File) GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder) StreetVertexIndex(org.opentripplanner.routing.impl.StreetVertexIndex)

Example 7 with BinaryOpenStreetMapProvider

use of org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider in project OpenTripPlanner by opentripplanner.

the class TriangleInequalityTest method onlyOnce.

@BeforeClass
public static void onlyOnce() {
    extra = new HashMap<>();
    graph = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    File file = new File(URLDecoder.decode(TriangleInequalityTest.class.getResource("NYC_small.osm.pbf").getFile(), StandardCharsets.UTF_8));
    DataSource source = new FileDataSource(file, FileType.OSM);
    BinaryOpenStreetMapProvider provider = new BinaryOpenStreetMapProvider(source, true);
    loader.setProvider(provider);
    loader.buildGraph(graph, extra);
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) FileDataSource(org.opentripplanner.datastore.file.FileDataSource) BinaryOpenStreetMapProvider(org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider) File(java.io.File) FileDataSource(org.opentripplanner.datastore.file.FileDataSource) DataSource(org.opentripplanner.datastore.DataSource) BeforeClass(org.junit.BeforeClass)

Example 8 with BinaryOpenStreetMapProvider

use of org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider in project OpenTripPlanner by opentripplanner.

the class OpenStreetMapParserTest method testBinaryParser.

@Test
public void testBinaryParser() throws Exception {
    File osmFile = new File(URLDecoder.decode(getClass().getResource("map.osm.pbf").getPath(), "UTF-8"));
    BinaryOpenStreetMapProvider pr = new BinaryOpenStreetMapProvider(osmFile, true);
    OSMDatabase osmdb = new OSMDatabase(new DataImportIssueStore(false));
    pr.readOSM(osmdb);
    assertEquals(2297, osmdb.nodeCount());
    OSMNode nodeA = osmdb.getNode(314192918L);
    assertEquals(314192918, nodeA.getId());
    assertEquals(52.3750447, nodeA.lat, 0.0000001);
    assertEquals(16.8431974, nodeA.lon, 0.0000001);
    assertTrue(nodeA.hasTag("railway"));
    assertEquals("level_crossing", nodeA.getTag("railway"));
    assertEquals(545, osmdb.wayCount());
    OSMWay wayA = osmdb.getWay(13490353L);
    assertEquals(13490353, wayA.getId());
    TLongList nodeRefsA = wayA.getNodeRefs();
    assertEquals(2, nodeRefsA.size());
    assertEquals(123978834, nodeRefsA.get(0));
    assertEquals(123980465, nodeRefsA.get(1));
    assertTrue(wayA.hasTag("highway"));
    assertEquals("Potlatch 0.9a", wayA.getTag("created_by"));
    assertEquals("secondary", wayA.getTag("highway"));
}
Also used : OSMWay(org.opentripplanner.openstreetmap.model.OSMWay) TLongList(gnu.trove.list.TLongList) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) BinaryOpenStreetMapProvider(org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode) File(java.io.File) Test(org.junit.Test)

Example 9 with BinaryOpenStreetMapProvider

use of org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider 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());
    File file = new File(URLDecoder.decode(getClass().getResource("NYC_small.osm.pbf").getFile(), "UTF-8"));
    BinaryOpenStreetMapProvider provider = new BinaryOpenStreetMapProvider(file, true);
    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<Vertex>> edgeEndpoints = new HashSet<>();
    for (StreetEdge se : gg.getStreetEdges()) {
        P2<Vertex> endpoints = new P2<>(se.getFromVertex(), se.getToVertex());
        // Check that we don't get any duplicate edges on this small graph.
        if (edgeEndpoints.contains(endpoints)) {
            assertFalse(true);
        }
        edgeEndpoints.add(endpoints);
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) P2(org.opentripplanner.common.model.P2) Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) BinaryOpenStreetMapProvider(org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with BinaryOpenStreetMapProvider

use of org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider in project OpenTripPlanner by opentripplanner.

the class TestUnconnectedAreas method testUnconnectedParkAndRide.

/**
 * The P+R.osm.gz file contains 2 park and ride, one a single way area and the other a
 * multipolygon with a hole. Both are not linked to any street, apart from three roads that
 * crosses the P+R with w/o common nodes.
 *
 * This test just make sure we correctly link those P+R with the street network by creating
 * virtual nodes at the place where the street intersects the P+R areas. See ticket #1562.
 */
@Test
public void testUnconnectedParkAndRide() throws Exception {
    Graph gg = new Graph();
    DataImportIssueStore issueStore = new DataImportIssueStore(true);
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    File file = new File(getClass().getResource("P+R.osm.pbf").getFile());
    BinaryOpenStreetMapProvider provider = new BinaryOpenStreetMapProvider(file, false);
    loader.setProvider(provider);
    loader.buildGraph(gg, new HashMap<Class<?>, Object>(), issueStore);
    assertEquals(1, issueStore.getIssues().size());
    int nParkAndRide = 0;
    int nParkAndRideLink = 0;
    for (Vertex v : gg.getVertices()) {
        if (v instanceof ParkAndRideVertex) {
            nParkAndRide++;
        }
    }
    for (Edge e : gg.getEdges()) {
        if (e instanceof ParkAndRideLinkEdge) {
            nParkAndRideLink++;
        }
    }
    assertEquals(2, nParkAndRide);
    assertEquals(10, nParkAndRideLink);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ParkAndRideVertex(org.opentripplanner.routing.vertextype.ParkAndRideVertex) ParkAndRideLinkEdge(org.opentripplanner.routing.edgetype.ParkAndRideLinkEdge) BinaryOpenStreetMapProvider(org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider) Graph(org.opentripplanner.routing.graph.Graph) ParkAndRideVertex(org.opentripplanner.routing.vertextype.ParkAndRideVertex) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) File(java.io.File) ParkAndRideLinkEdge(org.opentripplanner.routing.edgetype.ParkAndRideLinkEdge) ParkAndRideEdge(org.opentripplanner.routing.edgetype.ParkAndRideEdge) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Aggregations

BinaryOpenStreetMapProvider (org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider)14 File (java.io.File)13 Graph (org.opentripplanner.routing.graph.Graph)10 Vertex (org.opentripplanner.routing.graph.Vertex)7 Test (org.junit.Test)6 Edge (org.opentripplanner.routing.graph.Edge)4 ArrayList (java.util.ArrayList)3 OpenStreetMapModule (org.opentripplanner.graph_builder.module.osm.OpenStreetMapModule)3 ParkAndRideEdge (org.opentripplanner.routing.edgetype.ParkAndRideEdge)3 ParkAndRideLinkEdge (org.opentripplanner.routing.edgetype.ParkAndRideLinkEdge)3 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)3 ParkAndRideVertex (org.opentripplanner.routing.vertextype.ParkAndRideVertex)3 HashMap (java.util.HashMap)2 DataSource (org.opentripplanner.datastore.DataSource)2 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)2 StreetLinkerModule (org.opentripplanner.graph_builder.module.StreetLinkerModule)2 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)2 TLongList (gnu.trove.list.TLongList)1 IOException (java.io.IOException)1 URL (java.net.URL)1