Search in sources :

Example 1 with FileBasedOpenStreetMapProviderImpl

use of org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl in project OpenTripPlanner by opentripplanner.

the class OpenStreetMapParserTest method testXMLParser.

@Test
public void testXMLParser() throws Exception {
    FileBasedOpenStreetMapProviderImpl pr = new FileBasedOpenStreetMapProviderImpl();
    OSMMap map = new OSMMap();
    pr.setPath(new File(URLDecoder.decode(getClass().getResource("map.osm.gz").getPath(), "UTF-8")));
    pr.readOSM(map);
    testParser(map);
}
Also used : StreamedFileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.StreamedFileBasedOpenStreetMapProviderImpl) AnyFileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.AnyFileBasedOpenStreetMapProviderImpl) BinaryFileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.BinaryFileBasedOpenStreetMapProviderImpl) FileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl) OSMMap(org.opentripplanner.openstreetmap.model.OSMMap) File(java.io.File) Test(org.junit.Test)

Example 2 with FileBasedOpenStreetMapProviderImpl

use of org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl 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 gg = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.skipVisibility = skipVisibility;
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
    File file = new File(URLDecoder.decode(getClass().getResource("usf_area.osm.gz").getFile(), "UTF-8"));
    provider.setPath(file);
    loader.setProvider(provider);
    loader.buildGraph(gg, extra);
    new StreetVertexIndexServiceImpl(gg);
    OTPServer otpServer = new OTPServer(new CommandLineParameters(), new GraphService());
    otpServer.getGraphService().registerGraph("A", new MemoryGraphSource("A", gg));
    Router a = otpServer.getGraphService().getRouter("A");
    RoutingRequest request = new RoutingRequest("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 = gg.getVertex("osm:node:580290955");
    Vertex topV = gg.getVertex("osm:node:559271124");
    request.setRoutingContext(a.graph, bottomV, topV);
    GraphPathFinder graphPathFinder = new GraphPathFinder(a);
    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) CommandLineParameters(org.opentripplanner.standalone.CommandLineParameters) FileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl) GraphPath(org.opentripplanner.routing.spt.GraphPath) Router(org.opentripplanner.standalone.Router) GraphService(org.opentripplanner.routing.services.GraphService) Graph(org.opentripplanner.routing.graph.Graph) OTPServer(org.opentripplanner.standalone.OTPServer) MemoryGraphSource(org.opentripplanner.routing.impl.MemoryGraphSource) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) File(java.io.File) GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder) StreetVertexIndexServiceImpl(org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl)

Example 3 with FileBasedOpenStreetMapProviderImpl

use of org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl in project OpenTripPlanner by opentripplanner.

the class TestOpenStreetMapGraphBuilder method testGraphBuilder.

@Test
public void testGraphBuilder() 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("map.osm.gz").getFile(), "UTF-8"));
    provider.setPath(file);
    loader.setProvider(provider);
    loader.buildGraph(gg, extra);
    // Kamiennogorska at south end of segment
    Vertex v1 = gg.getVertex("osm:node:280592578");
    // Kamiennogorska at Mariana Smoluchowskiego
    Vertex v2 = gg.getVertex("osm:node:288969929");
    // Mariana Smoluchowskiego, north end
    Vertex v3 = gg.getVertex("osm:node:280107802");
    // Mariana Smoluchowskiego, south end (of segment connected to v2)
    Vertex v4 = gg.getVertex("osm:node:288970952");
    assertNotNull(v1);
    assertNotNull(v2);
    assertNotNull(v3);
    assertNotNull(v4);
    Edge e1 = null, e2 = null, e3 = null;
    for (Edge e : v2.getOutgoing()) {
        if (e.getToVertex() == v1) {
            e1 = e;
        } else if (e.getToVertex() == v3) {
            e2 = e;
        } else if (e.getToVertex() == v4) {
            e3 = e;
        }
    }
    assertNotNull(e1);
    assertNotNull(e2);
    assertNotNull(e3);
    assertTrue("name of e1 must be like \"Kamiennog\u00F3rska\"; was " + e1.getName(), e1.getName().contains("Kamiennog\u00F3rska"));
    assertTrue("name of e2 must be like \"Mariana Smoluchowskiego\"; was " + e2.getName(), e2.getName().contains("Mariana Smoluchowskiego"));
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) Graph(org.opentripplanner.routing.graph.Graph) FileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl) File(java.io.File) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 4 with FileBasedOpenStreetMapProviderImpl

use of org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl in project OpenTripPlanner by opentripplanner.

the class TriangleInequalityTest method onlyOnce.

@BeforeClass
public static void onlyOnce() throws Exception {
    extra = new HashMap<Class<?>, Object>();
    _graph = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
    File file = new File(URLDecoder.decode(TriangleInequalityTest.class.getResource("NYC_small.osm.gz").getFile(), "UTF-8"));
    provider.setPath(file);
    loader.setProvider(provider);
    loader.buildGraph(_graph, extra);
    // Need to set up the index because buildGraph doesn't do it.
    _graph.rebuildVertexAndEdgeIndices();
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) FileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl) BeforeClass(org.junit.BeforeClass) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 5 with FileBasedOpenStreetMapProviderImpl

use of org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl 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)

Aggregations

File (java.io.File)8 FileBasedOpenStreetMapProviderImpl (org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl)8 Graph (org.opentripplanner.routing.graph.Graph)7 Test (org.junit.Test)5 Vertex (org.opentripplanner.routing.graph.Vertex)5 Edge (org.opentripplanner.routing.graph.Edge)4 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 ArrayList (java.util.ArrayList)2 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)2 BeforeClass (org.junit.BeforeClass)1 P2 (org.opentripplanner.common.model.P2)1 AnyFileBasedOpenStreetMapProviderImpl (org.opentripplanner.openstreetmap.impl.AnyFileBasedOpenStreetMapProviderImpl)1 BinaryFileBasedOpenStreetMapProviderImpl (org.opentripplanner.openstreetmap.impl.BinaryFileBasedOpenStreetMapProviderImpl)1 StreamedFileBasedOpenStreetMapProviderImpl (org.opentripplanner.openstreetmap.impl.StreamedFileBasedOpenStreetMapProviderImpl)1 OSMMap (org.opentripplanner.openstreetmap.model.OSMMap)1 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)1 GraphPathFinder (org.opentripplanner.routing.impl.GraphPathFinder)1