Search in sources :

Example 6 with OSMNode

use of org.opentripplanner.openstreetmap.model.OSMNode in project OpenTripPlanner by opentripplanner.

the class WalkableAreaBuilder method accumulateRingNodes.

private void accumulateRingNodes(Ring ring, List<OSMNode> nodes, List<VLPoint> vertices) {
    for (OSMNode node : ring.nodes) {
        if (nodes.contains(node)) {
            // close polygons
            continue;
        }
        VLPoint point = new VLPoint(node.lon, node.lat);
        nodes.add(node);
        vertices.add(point);
    }
}
Also used : VLPoint(org.opentripplanner.visibility.VLPoint) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode)

Example 7 with OSMNode

use of org.opentripplanner.openstreetmap.model.OSMNode in project OpenTripPlanner by opentripplanner.

the class WalkableAreaBuilder method buildWithoutVisibility.

/**
 * For all areas just use outermost rings as edges so that areas can be routable without visibility calculations
 * @param group
 */
public void buildWithoutVisibility(AreaGroup group) {
    Set<Edge> edges = new HashSet<Edge>();
    // create polygon and accumulate nodes for area
    for (Ring ring : group.outermostRings) {
        AreaEdgeList edgeList = new AreaEdgeList();
        // the points corresponding to concave or hole vertices
        // or those linked to ways
        HashSet<P2<OSMNode>> alreadyAddedEdges = new HashSet<P2<OSMNode>>();
        // and to avoid the numerical problems that they tend to cause
        for (Area area : group.areas) {
            if (!ring.toJtsPolygon().contains(area.toJTSMultiPolygon())) {
                continue;
            }
            for (Ring outerRing : area.outermostRings) {
                for (int i = 0; i < outerRing.nodes.size(); ++i) {
                    createEdgesForRingSegment(edges, edgeList, area, outerRing, i, alreadyAddedEdges);
                }
                // TODO: is this actually needed?
                for (Ring innerRing : outerRing.holes) {
                    for (int j = 0; j < innerRing.nodes.size(); ++j) {
                        createEdgesForRingSegment(edges, edgeList, area, innerRing, j, alreadyAddedEdges);
                    }
                }
            }
        }
    }
}
Also used : P2(org.opentripplanner.common.model.P2) NamedArea(org.opentripplanner.routing.edgetype.NamedArea) LinearRing(com.vividsolutions.jts.geom.LinearRing) AreaEdgeList(org.opentripplanner.routing.edgetype.AreaEdgeList) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) AreaEdge(org.opentripplanner.routing.edgetype.AreaEdge) Edge(org.opentripplanner.routing.graph.Edge) Point(com.vividsolutions.jts.geom.Point) VLPoint(org.opentripplanner.visibility.VLPoint) HashSet(java.util.HashSet)

Example 8 with OSMNode

use of org.opentripplanner.openstreetmap.model.OSMNode in project OpenTripPlanner by opentripplanner.

the class WalkableAreaBuilder method buildWithVisibility.

public void buildWithVisibility(AreaGroup group, boolean platformEntriesLinking) {
    Set<OSMNode> startingNodes = new HashSet<OSMNode>();
    Set<Vertex> startingVertices = new HashSet<Vertex>();
    Set<Edge> edges = new HashSet<Edge>();
    // create polygon and accumulate nodes for area
    for (Ring ring : group.outermostRings) {
        AreaEdgeList edgeList = new AreaEdgeList();
        // the points corresponding to concave or hole vertices
        // or those linked to ways
        ArrayList<VLPoint> visibilityPoints = new ArrayList<VLPoint>();
        ArrayList<OSMNode> visibilityNodes = new ArrayList<OSMNode>();
        HashSet<P2<OSMNode>> alreadyAddedEdges = new HashSet<P2<OSMNode>>();
        // and to avoid the numerical problems that they tend to cause
        for (Area area : group.areas) {
            // parameter is true
            if (platformEntriesLinking && "platform".equals(area.parent.getTag("public_transport"))) {
                continue;
            }
            if (!ring.toJtsPolygon().contains(area.toJTSMultiPolygon())) {
                continue;
            }
            // Add stops from public transit relations into the area
            Collection<OSMNode> nodes = osmdb.getStopsInArea(area.parent);
            if (nodes != null) {
                for (OSMNode node : nodes) {
                    addtoVisibilityAndStartSets(startingNodes, visibilityPoints, visibilityNodes, node);
                }
            }
            for (Ring outerRing : area.outermostRings) {
                for (int i = 0; i < outerRing.nodes.size(); ++i) {
                    OSMNode node = outerRing.nodes.get(i);
                    createEdgesForRingSegment(edges, edgeList, area, outerRing, i, alreadyAddedEdges);
                    addtoVisibilityAndStartSets(startingNodes, visibilityPoints, visibilityNodes, node);
                }
                for (Ring innerRing : outerRing.holes) {
                    for (int j = 0; j < innerRing.nodes.size(); ++j) {
                        OSMNode node = innerRing.nodes.get(j);
                        createEdgesForRingSegment(edges, edgeList, area, innerRing, j, alreadyAddedEdges);
                        addtoVisibilityAndStartSets(startingNodes, visibilityPoints, visibilityNodes, node);
                    }
                }
            }
        }
        List<OSMNode> nodes = new ArrayList<OSMNode>();
        List<VLPoint> vertices = new ArrayList<VLPoint>();
        accumulateRingNodes(ring, nodes, vertices);
        VLPolygon polygon = makeStandardizedVLPolygon(vertices, nodes, false);
        accumulateVisibilityPoints(ring.nodes, polygon, visibilityPoints, visibilityNodes, false);
        ArrayList<VLPolygon> polygons = new ArrayList<VLPolygon>();
        polygons.add(polygon);
        // holes
        for (Ring innerRing : ring.holes) {
            ArrayList<OSMNode> holeNodes = new ArrayList<OSMNode>();
            vertices = new ArrayList<VLPoint>();
            accumulateRingNodes(innerRing, holeNodes, vertices);
            VLPolygon hole = makeStandardizedVLPolygon(vertices, holeNodes, true);
            accumulateVisibilityPoints(innerRing.nodes, hole, visibilityPoints, visibilityNodes, true);
            nodes.addAll(holeNodes);
            polygons.add(hole);
        }
        Environment areaEnv = new Environment(polygons);
        // areas to prevent way explosion
        if (visibilityPoints.size() > MAX_AREA_NODES) {
            LOG.warn("Area " + group.getSomeOSMObject() + " is too complicated (" + visibilityPoints.size() + " > " + MAX_AREA_NODES);
            continue;
        }
        if (!areaEnv.is_valid(VISIBILITY_EPSILON)) {
            LOG.warn("Area " + group.getSomeOSMObject() + " is not epsilon-valid (epsilon = " + VISIBILITY_EPSILON + ")");
            continue;
        }
        edgeList.setOriginalEdges(ring.toJtsPolygon());
        createNamedAreas(edgeList, ring, group.areas);
        OSMWithTags areaEntity = group.getSomeOSMObject();
        for (int i = 0; i < visibilityNodes.size(); ++i) {
            OSMNode nodeI = visibilityNodes.get(i);
            VisibilityPolygon visibilityPolygon = new VisibilityPolygon(visibilityPoints.get(i), areaEnv, VISIBILITY_EPSILON);
            Polygon poly = toJTSPolygon(visibilityPolygon);
            for (int j = 0; j < visibilityNodes.size(); ++j) {
                OSMNode nodeJ = visibilityNodes.get(j);
                P2<OSMNode> nodePair = new P2<OSMNode>(nodeI, nodeJ);
                if (alreadyAddedEdges.contains(nodePair))
                    continue;
                IntersectionVertex startEndpoint = __handler.getVertexForOsmNode(nodeI, areaEntity);
                IntersectionVertex endEndpoint = __handler.getVertexForOsmNode(nodeJ, areaEntity);
                Coordinate[] coordinates = new Coordinate[] { startEndpoint.getCoordinate(), endEndpoint.getCoordinate() };
                GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
                LineString line = geometryFactory.createLineString(coordinates);
                if (poly != null && poly.contains(line)) {
                    createSegments(nodeI, nodeJ, startEndpoint, endEndpoint, group.areas, edgeList, edges);
                    if (startingNodes.contains(nodeI)) {
                        startingVertices.add(startEndpoint);
                    }
                    if (startingNodes.contains(nodeJ)) {
                        startingVertices.add(endEndpoint);
                    }
                }
            }
        }
    }
    pruneAreaEdges(startingVertices, edges);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ArrayList(java.util.ArrayList) OSMWithTags(org.opentripplanner.openstreetmap.model.OSMWithTags) VLPoint(org.opentripplanner.visibility.VLPoint) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode) VLPolygon(org.opentripplanner.visibility.VLPolygon) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) VisibilityPolygon(org.opentripplanner.visibility.VisibilityPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) HashSet(java.util.HashSet) P2(org.opentripplanner.common.model.P2) VisibilityPolygon(org.opentripplanner.visibility.VisibilityPolygon) Point(com.vividsolutions.jts.geom.Point) VLPoint(org.opentripplanner.visibility.VLPoint) NamedArea(org.opentripplanner.routing.edgetype.NamedArea) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LinearRing(com.vividsolutions.jts.geom.LinearRing) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) AreaEdgeList(org.opentripplanner.routing.edgetype.AreaEdgeList) VLPolygon(org.opentripplanner.visibility.VLPolygon) Environment(org.opentripplanner.visibility.Environment) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) AreaEdge(org.opentripplanner.routing.edgetype.AreaEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 9 with OSMNode

use of org.opentripplanner.openstreetmap.model.OSMNode in project OpenTripPlanner by opentripplanner.

the class WalkableAreaBuilder method standardize.

private void standardize(ArrayList<VLPoint> vertices, List<OSMNode> nodes) {
    // based on code from VisiLibity
    int point_count = vertices.size();
    if (point_count > 1) {
        // if more than one point in the polygon.
        ArrayList<VLPoint> vertices_temp = new ArrayList<VLPoint>(point_count);
        ArrayList<OSMNode> nodes_temp = new ArrayList<OSMNode>(point_count);
        // Find index of lexicographically smallest point.
        int index_of_smallest = 0;
        for (int i = 1; i < point_count; i++) if (vertices.get(i).compareTo(vertices.get(index_of_smallest)) < 0)
            index_of_smallest = i;
        // minor optimization for already-standardized polygons
        if (index_of_smallest == 0)
            return;
        // Fill vertices_temp starting with lex. smallest.
        for (int i = index_of_smallest; i < point_count; i++) {
            vertices_temp.add(vertices.get(i));
            nodes_temp.add(nodes.get(i));
        }
        for (int i = 0; i < index_of_smallest; i++) {
            vertices_temp.add(vertices.get(i));
            nodes_temp.add(nodes.get(i));
        }
        for (int i = 0; i < point_count; ++i) {
            vertices.set(i, vertices_temp.get(i));
            nodes.set(i, nodes_temp.get(i));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) VLPoint(org.opentripplanner.visibility.VLPoint) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode) Point(com.vividsolutions.jts.geom.Point) VLPoint(org.opentripplanner.visibility.VLPoint)

Example 10 with OSMNode

use of org.opentripplanner.openstreetmap.model.OSMNode in project OpenTripPlanner by opentripplanner.

the class WalkableAreaBuilder method accumulateVisibilityPoints.

private void accumulateVisibilityPoints(List<OSMNode> nodes, VLPolygon polygon, List<VLPoint> visibilityPoints, List<OSMNode> visibilityNodes, boolean hole) {
    int n = polygon.vertices.size();
    for (int i = 0; i < n; ++i) {
        OSMNode curNode = nodes.get(i);
        VLPoint cur = polygon.vertices.get(i);
        VLPoint prev = polygon.vertices.get((i + n - 1) % n);
        VLPoint next = polygon.vertices.get((i + 1) % n);
        if (hole || (cur.x - prev.x) * (next.y - cur.y) - (cur.y - prev.y) * (next.x - cur.x) > 0) {
            if (!visibilityNodes.contains(curNode)) {
                visibilityPoints.add(cur);
                visibilityNodes.add(curNode);
            }
        }
    }
}
Also used : VLPoint(org.opentripplanner.visibility.VLPoint) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode) Point(com.vividsolutions.jts.geom.Point) VLPoint(org.opentripplanner.visibility.VLPoint)

Aggregations

OSMNode (org.opentripplanner.openstreetmap.model.OSMNode)13 VLPoint (org.opentripplanner.visibility.VLPoint)6 Point (com.vividsolutions.jts.geom.Point)5 ArrayList (java.util.ArrayList)5 LineString (com.vividsolutions.jts.geom.LineString)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 P2 (org.opentripplanner.common.model.P2)3 AreaEdge (org.opentripplanner.routing.edgetype.AreaEdge)3 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)3 Edge (org.opentripplanner.routing.graph.Edge)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 LinearRing (com.vividsolutions.jts.geom.LinearRing)2 HashSet (java.util.HashSet)2 RingConstructionException (org.opentripplanner.graph_builder.module.osm.Ring.RingConstructionException)2 OSMWay (org.opentripplanner.openstreetmap.model.OSMWay)2 OSMWithTags (org.opentripplanner.openstreetmap.model.OSMWithTags)2 AreaEdgeList (org.opentripplanner.routing.edgetype.AreaEdgeList)2 NamedArea (org.opentripplanner.routing.edgetype.NamedArea)2 Graph (org.opentripplanner.routing.graph.Graph)2 Vertex (org.opentripplanner.routing.graph.Vertex)2