use of org.opentripplanner.common.model.P2 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);
}
}
use of org.opentripplanner.common.model.P2 in project OpenTripPlanner by opentripplanner.
the class DegreeGridNEDTileSource method getNEDTiles.
@Override
public List<File> getNEDTiles() {
HashSet<P2<Integer>> tiles = new HashSet<P2<Integer>>();
for (Vertex v : graph.getVertices()) {
Coordinate coord = v.getCoordinate();
tiles.add(new P2<Integer>((int) coord.x, (int) coord.y));
}
List<File> paths = new ArrayList<File>();
for (P2<Integer> tile : tiles) {
int x = tile.first - 1;
int y = tile.second + 1;
paths.add(getPathToTile(x, y));
}
return paths;
}
use of org.opentripplanner.common.model.P2 in project OpenTripPlanner by opentripplanner.
the class OSMFilter method getPermissions.
/**
* Check OSM tags for various one-way and one-way-by-mode tags and return a pair of permissions
* for travel along and against the way.
*/
public static P2<StreetTraversalPermission> getPermissions(StreetTraversalPermission permissions, OSMWay way) {
StreetTraversalPermission permissionsFront = permissions;
StreetTraversalPermission permissionsBack = permissions;
// Check driving direction restrictions.
if (way.isOneWayForwardDriving() || way.isRoundabout()) {
permissionsBack = permissionsBack.remove(StreetTraversalPermission.BICYCLE_AND_CAR);
}
if (way.isOneWayReverseDriving()) {
permissionsFront = permissionsFront.remove(StreetTraversalPermission.BICYCLE_AND_CAR);
}
// Check bike direction restrictions.
if (way.isOneWayForwardBicycle()) {
permissionsBack = permissionsBack.remove(StreetTraversalPermission.BICYCLE);
}
if (way.isOneWayReverseBicycle()) {
permissionsFront = permissionsFront.remove(StreetTraversalPermission.BICYCLE);
}
// TODO(flamholz): figure out what this is for.
String oneWayBicycle = way.getTag("oneway:bicycle");
if (OSMWithTags.isFalse(oneWayBicycle) || way.isTagTrue("bicycle:backwards")) {
if (permissions.allows(StreetTraversalPermission.BICYCLE)) {
permissionsFront = permissionsFront.add(StreetTraversalPermission.BICYCLE);
permissionsBack = permissionsBack.add(StreetTraversalPermission.BICYCLE);
}
}
// TAG: bicycle:forward=use_sidepath
if (way.isForwardDirectionSidepath()) {
permissionsFront = permissionsFront.remove(StreetTraversalPermission.BICYCLE);
}
// TAG bicycle:backward=use_sidepath
if (way.isReverseDirectionSidepath()) {
permissionsBack = permissionsBack.remove(StreetTraversalPermission.BICYCLE);
}
if (way.isOpposableCycleway()) {
permissionsBack = permissionsBack.add(StreetTraversalPermission.BICYCLE);
}
return new P2<StreetTraversalPermission>(permissionsFront, permissionsBack);
}
Aggregations