Search in sources :

Example 6 with StreetTraversalPermission

use of org.opentripplanner.routing.edgetype.StreetTraversalPermission in project OpenTripPlanner by opentripplanner.

the class WalkableAreaBuilder method createSegments.

private void createSegments(OSMNode fromNode, OSMNode toNode, IntersectionVertex startEndpoint, IntersectionVertex endEndpoint, Collection<Area> areas, AreaEdgeList edgeList, Set<Edge> edges) {
    List<Area> intersects = new ArrayList<Area>();
    Coordinate[] coordinates = new Coordinate[] { startEndpoint.getCoordinate(), endEndpoint.getCoordinate() };
    GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
    LineString line = geometryFactory.createLineString(coordinates);
    for (Area area : areas) {
        MultiPolygon polygon = area.toJTSMultiPolygon();
        Geometry intersection = polygon.intersection(line);
        if (intersection.getLength() > 0.000001) {
            intersects.add(area);
        }
    }
    if (intersects.size() == 0) {
        // apparently our intersection here was bogus
        return;
    }
    // do we need to recurse?
    if (intersects.size() == 1) {
        Area area = intersects.get(0);
        OSMWithTags areaEntity = area.parent;
        StreetTraversalPermission areaPermissions = OSMFilter.getPermissionsForEntity(areaEntity, StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE);
        float carSpeed = wayPropertySet.getCarSpeedForWay(areaEntity, false);
        double length = SphericalDistanceLibrary.distance(startEndpoint.getCoordinate(), endEndpoint.getCoordinate());
        int cls = StreetEdge.CLASS_OTHERPATH;
        cls |= OSMFilter.getStreetClasses(areaEntity);
        String label = "way (area) " + areaEntity.getId() + " from " + startEndpoint.getLabel() + " to " + endEndpoint.getLabel();
        I18NString name = __handler.getNameForWay(areaEntity, label);
        AreaEdge street = edgeFactory.createAreaEdge(startEndpoint, endEndpoint, line, name, length, areaPermissions, false, edgeList);
        street.setCarSpeed(carSpeed);
        if (!areaEntity.hasTag("name") && !areaEntity.hasTag("ref")) {
            street.setHasBogusName(true);
        }
        if (areaEntity.isTagFalse("wheelchair")) {
            street.setWheelchairAccessible(false);
        }
        street.setStreetClass(cls);
        edges.add(street);
        label = "way (area) " + areaEntity.getId() + " from " + endEndpoint.getLabel() + " to " + startEndpoint.getLabel();
        name = __handler.getNameForWay(areaEntity, label);
        AreaEdge backStreet = edgeFactory.createAreaEdge(endEndpoint, startEndpoint, (LineString) line.reverse(), name, length, areaPermissions, true, edgeList);
        backStreet.setCarSpeed(carSpeed);
        if (!areaEntity.hasTag("name") && !areaEntity.hasTag("ref")) {
            backStreet.setHasBogusName(true);
        }
        if (areaEntity.isTagFalse("wheelchair")) {
            backStreet.setWheelchairAccessible(false);
        }
        backStreet.setStreetClass(cls);
        edges.add(backStreet);
        WayProperties wayData = wayPropertySet.getDataForWay(areaEntity);
        __handler.applyWayProperties(street, backStreet, wayData, areaEntity);
    } else {
        // take the part that intersects with the start vertex
        Coordinate startCoordinate = startEndpoint.getCoordinate();
        Point startPoint = geometryFactory.createPoint(startCoordinate);
        for (Area area : intersects) {
            MultiPolygon polygon = area.toJTSMultiPolygon();
            if (!(polygon.intersects(startPoint) || polygon.getBoundary().intersects(startPoint)))
                continue;
            Geometry lineParts = line.intersection(polygon);
            if (lineParts.getLength() > 0.000001) {
                Coordinate edgeCoordinate = null;
                // this is either a LineString or a MultiLineString (we hope)
                if (lineParts instanceof MultiLineString) {
                    MultiLineString mls = (MultiLineString) lineParts;
                    boolean found = false;
                    for (int i = 0; i < mls.getNumGeometries(); ++i) {
                        LineString segment = (LineString) mls.getGeometryN(i);
                        if (found) {
                            edgeCoordinate = segment.getEndPoint().getCoordinate();
                            break;
                        }
                        if (segment.contains(startPoint) || segment.getBoundary().contains(startPoint)) {
                            found = true;
                            if (segment.getLength() > 0.000001) {
                                edgeCoordinate = segment.getEndPoint().getCoordinate();
                                break;
                            }
                        }
                    }
                } else if (lineParts instanceof LineString) {
                    edgeCoordinate = ((LineString) lineParts).getEndPoint().getCoordinate();
                } else {
                    continue;
                }
                IntersectionVertex newEndpoint = areaBoundaryVertexForCoordinate.get(edgeCoordinate);
                if (newEndpoint == null) {
                    newEndpoint = new IntersectionVertex(graph, "area splitter at " + edgeCoordinate, edgeCoordinate.x, edgeCoordinate.y);
                    areaBoundaryVertexForCoordinate.put(edgeCoordinate, newEndpoint);
                }
                createSegments(fromNode, toNode, startEndpoint, newEndpoint, Arrays.asList(area), edgeList, edges);
                createSegments(fromNode, toNode, newEndpoint, endEndpoint, intersects, edgeList, edges);
                break;
            }
        }
    }
}
Also used : MultiLineString(com.vividsolutions.jts.geom.MultiLineString) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) I18NString(org.opentripplanner.util.I18NString) ArrayList(java.util.ArrayList) OSMWithTags(org.opentripplanner.openstreetmap.model.OSMWithTags) LineString(com.vividsolutions.jts.geom.LineString) I18NString(org.opentripplanner.util.I18NString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) Point(com.vividsolutions.jts.geom.Point) VLPoint(org.opentripplanner.visibility.VLPoint) Point(com.vividsolutions.jts.geom.Point) VLPoint(org.opentripplanner.visibility.VLPoint) AreaEdge(org.opentripplanner.routing.edgetype.AreaEdge) Geometry(com.vividsolutions.jts.geom.Geometry) NamedArea(org.opentripplanner.routing.edgetype.NamedArea) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission)

Example 7 with StreetTraversalPermission

use of org.opentripplanner.routing.edgetype.StreetTraversalPermission in project OpenTripPlanner by opentripplanner.

the class CompositeStreetTraversalPermissionConverter method convert.

/**
 * use the permission combination strategy to combine the results of the list of converters
 */
@Override
public P2<StreetTraversalPermission> convert(SimpleFeature feature) {
    P2<StreetTraversalPermission> result = null;
    for (SimpleFeatureConverter<P2<StreetTraversalPermission>> converter : converters) {
        P2<StreetTraversalPermission> value = converter.convert(feature);
        if (result == null) {
            result = value;
        } else {
            StreetTraversalPermission first, second;
            if (orPermissions) {
                first = result.first.add(value.first);
                second = result.second.add(value.second);
            } else {
                first = StreetTraversalPermission.get(result.first.code & value.first.code);
                second = StreetTraversalPermission.get(result.second.code & value.second.code);
            }
            result = new P2<StreetTraversalPermission>(first, second);
        }
    }
    return result;
}
Also used : P2(org.opentripplanner.common.model.P2) StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission)

Example 8 with StreetTraversalPermission

use of org.opentripplanner.routing.edgetype.StreetTraversalPermission in project OpenTripPlanner by opentripplanner.

the class ShowGraph method drawGraphPath.

private void drawGraphPath(GraphPath gp) {
    // draw edges in different colors according to mode
    for (State s : gp.states) {
        TraverseMode mode = s.getBackMode();
        Edge e = s.getBackEdge();
        if (e == null)
            continue;
        if (mode != null && mode.isTransit()) {
            stroke(200, 050, 000);
            strokeWeight(6);
            drawEdge(e);
        }
        if (e instanceof StreetEdge) {
            StreetTraversalPermission stp = ((StreetEdge) e).getPermission();
            if (stp == StreetTraversalPermission.PEDESTRIAN) {
                stroke(000, 200, 000);
                strokeWeight(6);
                drawEdge(e);
            } else if (stp == StreetTraversalPermission.BICYCLE) {
                stroke(000, 000, 200);
                strokeWeight(6);
                drawEdge(e);
            } else if (stp == StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE) {
                stroke(000, 200, 200);
                strokeWeight(6);
                drawEdge(e);
            } else if (stp == StreetTraversalPermission.ALL) {
                stroke(200, 200, 200);
                strokeWeight(6);
                drawEdge(e);
            } else {
                stroke(64, 64, 64);
                strokeWeight(6);
                drawEdge(e);
            }
        }
    }
    // mark key vertices
    lastLabelY = -999;
    labelState(gp.states.getFirst(), "begin");
    for (State s : gp.states) {
        Edge e = s.getBackEdge();
        if (e instanceof TransitBoardAlight) {
            if (((TransitBoardAlight) e).boarding) {
                labelState(s, "board");
            } else {
                labelState(s, "alight");
            }
        }
    }
    labelState(gp.states.getLast(), "end");
    if (VIDEO) {
        // freeze on final path for a few frames
        for (int i = 0; i < 10; i++) saveVideoFrame();
        resetVideoFrameNumber();
    }
}
Also used : TransitBoardAlight(org.opentripplanner.routing.edgetype.TransitBoardAlight) State(org.opentripplanner.routing.core.State) TraverseMode(org.opentripplanner.routing.core.TraverseMode) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) PatternEdge(org.opentripplanner.routing.edgetype.PatternEdge) Edge(org.opentripplanner.routing.graph.Edge) Point(java.awt.Point)

Example 9 with StreetTraversalPermission

use of org.opentripplanner.routing.edgetype.StreetTraversalPermission in project OpenTripPlanner by opentripplanner.

the class WalkableAreaBuilder method createNamedAreas.

private void createNamedAreas(AreaEdgeList edgeList, Ring ring, Collection<Area> areas) {
    Polygon containingArea = ring.toJtsPolygon();
    for (Area area : areas) {
        Geometry intersection = containingArea.intersection(area.toJTSMultiPolygon());
        if (intersection.getArea() == 0) {
            continue;
        }
        NamedArea namedArea = new NamedArea();
        OSMWithTags areaEntity = area.parent;
        int cls = StreetEdge.CLASS_OTHERPATH;
        cls |= OSMFilter.getStreetClasses(areaEntity);
        namedArea.setStreetClass(cls);
        String id = "way (area) " + areaEntity.getId() + " (splitter linking)";
        I18NString name = __handler.getNameForWay(areaEntity, id);
        namedArea.setName(name);
        WayProperties wayData = wayPropertySet.getDataForWay(areaEntity);
        Double safety = wayData.getSafetyFeatures().first;
        namedArea.setBicycleSafetyMultiplier(safety);
        namedArea.setOriginalEdges(intersection);
        StreetTraversalPermission permission = OSMFilter.getPermissionsForEntity(areaEntity, StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE);
        namedArea.setPermission(permission);
        edgeList.addArea(namedArea);
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) NamedArea(org.opentripplanner.routing.edgetype.NamedArea) I18NString(org.opentripplanner.util.I18NString) OSMWithTags(org.opentripplanner.openstreetmap.model.OSMWithTags) NamedArea(org.opentripplanner.routing.edgetype.NamedArea) StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission) LineString(com.vividsolutions.jts.geom.LineString) I18NString(org.opentripplanner.util.I18NString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) VLPolygon(org.opentripplanner.visibility.VLPolygon) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) VisibilityPolygon(org.opentripplanner.visibility.VisibilityPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Point(com.vividsolutions.jts.geom.Point) VLPoint(org.opentripplanner.visibility.VLPoint)

Example 10 with StreetTraversalPermission

use of org.opentripplanner.routing.edgetype.StreetTraversalPermission in project OpenTripPlanner by opentripplanner.

the class CaseBasedTraversalPermissionConverter method setPermissions.

/**
 * The mapping from attribute values to permissions to use when determining a street's traversal
 * permission.
 */
public void setPermissions(Map<String, String> permissions) {
    for (Map.Entry<String, String> entry : permissions.entrySet()) {
        String attributeValue = entry.getKey();
        String perms = entry.getValue();
        String[] tokens = perms.split(",");
        if (tokens.length != 2)
            throw new IllegalArgumentException("invalid street traversal permissions: " + perms);
        StreetTraversalPermission forward = StreetTraversalPermission.valueOf(tokens[0]);
        StreetTraversalPermission reverse = StreetTraversalPermission.valueOf(tokens[1]);
        addPermission(attributeValue, forward, reverse);
    }
}
Also used : StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

StreetTraversalPermission (org.opentripplanner.routing.edgetype.StreetTraversalPermission)16 LineString (com.vividsolutions.jts.geom.LineString)10 Coordinate (com.vividsolutions.jts.geom.Coordinate)9 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)8 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)3 P2 (org.opentripplanner.common.model.P2)3 I18NString (org.opentripplanner.util.I18NString)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)2 Point (com.vividsolutions.jts.geom.Point)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 OSMWithTags (org.opentripplanner.openstreetmap.model.OSMWithTags)2 NamedArea (org.opentripplanner.routing.edgetype.NamedArea)2 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)2 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)2 VLPoint (org.opentripplanner.visibility.VLPoint)2 Polygon (com.vividsolutions.jts.geom.Polygon)1 Point (java.awt.Point)1