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