use of org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl 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();
OpenStreetMapModule loader = new OpenStreetMapModule();
loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
File file = new File(getClass().getResource("P+R.osm.gz").getFile());
provider.setPath(file);
loader.setProvider(provider);
loader.buildGraph(gg, new HashMap<Class<?>, Object>());
assertEquals(1, gg.getBuilderAnnotations().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);
}
use of org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl in project OpenTripPlanner by opentripplanner.
the class TestUnconnectedAreas method testGeometricGraphWithClasspathFile.
/**
* We've written several OSM files that exhibit different situations but should show the same results. Test with this code.
*/
public List<String> testGeometricGraphWithClasspathFile(String fn, int prCount, int prlCount) {
Graph g = new Graph();
OpenStreetMapModule loader = new OpenStreetMapModule();
loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
File file = new File(getClass().getResource(fn).getFile());
provider.setPath(file);
loader.setProvider(provider);
loader.buildGraph(g, new HashMap<Class<?>, Object>());
Vertex pr = null;
int nParkAndRide = 0;
int nParkAndRideLink = 0;
for (Vertex v : g.getVertices()) {
if (v instanceof ParkAndRideVertex) {
nParkAndRide++;
pr = v;
}
}
for (Edge e : g.getEdges()) {
if (e instanceof ParkAndRideLinkEdge) {
nParkAndRideLink++;
}
}
assertEquals(prCount, nParkAndRide);
assertEquals(prlCount, nParkAndRideLink);
assertNotNull(pr);
// make sure it is connected
List<String> connections = new ArrayList<String>();
for (Edge e : pr.getOutgoing()) {
if (e instanceof ParkAndRideEdge)
continue;
assertTrue(e instanceof ParkAndRideLinkEdge);
connections.add(e.getToVertex().getLabel());
}
// symmetry
for (Edge e : pr.getIncoming()) {
if (e instanceof ParkAndRideEdge)
continue;
assertTrue(e instanceof ParkAndRideLinkEdge);
assertTrue(connections.contains(e.getFromVertex().getLabel()));
}
return connections;
}
use of org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl in project OpenTripPlanner by opentripplanner.
the class TestUnconnectedAreas method testCoincidentNodeUnconnectedParkAndRide.
/**
* This test ensures that if a Park and Ride has a node that is exactly atop a node on a way, the graph
* builder will not loop forever trying to split it. The hackett-pr.osm.gz file contains a park-and-ride lot in
* Hackettstown, NJ, which demonstrates this behavior. See discussion in ticket 1605.
*/
@Test
public void testCoincidentNodeUnconnectedParkAndRide() throws Exception {
Graph g = new Graph();
OpenStreetMapModule loader = new OpenStreetMapModule();
loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
File file = new File(getClass().getResource("hackett_pr.osm.gz").getFile());
provider.setPath(file);
loader.setProvider(provider);
loader.buildGraph(g, new HashMap<Class<?>, Object>());
Vertex washTwp = null;
int nParkAndRide = 0;
int nParkAndRideLink = 0;
for (Vertex v : g.getVertices()) {
if (v instanceof ParkAndRideVertex) {
nParkAndRide++;
washTwp = v;
}
}
for (Edge e : g.getEdges()) {
if (e instanceof ParkAndRideLinkEdge) {
nParkAndRideLink++;
}
}
assertEquals(1, nParkAndRide);
// the P+R should get four connections, since the entrance road is duplicated as well, and crosses twice
// since there are in and out edges, that brings the total to 8 per P+R.
// Even though the park and rides get merged, duplicate edges remain from when they were separate.
// FIXME: we shouldn't have duplicate edges.
assertEquals(16, nParkAndRideLink);
assertNotNull(washTwp);
List<String> connections = new ArrayList<String>();
for (Edge e : washTwp.getOutgoing()) {
if (e instanceof ParkAndRideEdge)
continue;
assertTrue(e instanceof ParkAndRideLinkEdge);
connections.add(e.getToVertex().getLabel());
}
// symmetry
for (Edge e : washTwp.getIncoming()) {
if (e instanceof ParkAndRideEdge)
continue;
assertTrue(e instanceof ParkAndRideLinkEdge);
assertTrue(connections.contains(e.getFromVertex().getLabel()));
}
assertTrue(connections.contains("osm:node:3096570222"));
assertTrue(connections.contains("osm:node:3094264704"));
assertTrue(connections.contains("osm:node:3094264709"));
assertTrue(connections.contains("osm:node:3096570227"));
}
Aggregations