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);
}
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());
}
}
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"));
}
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();
}
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);
}
}
Aggregations