Package org.opentripplanner.openstreetmap.model

Examples of org.opentripplanner.openstreetmap.model.OSMNode


                node = node.getNextSibling();
                continue;
            }
            Element element = (Element) node;
            if (phase == 3 && element.getTagName().equals("node")) {
                OSMNode osmNode = new OSMNode();

                osmNode.setId(Long.parseLong(element.getAttribute("id")));
                osmNode.lat = Double.parseDouble(element.getAttribute("lat"));
                osmNode.lon = Double.parseDouble(element.getAttribute("lon"));

                processTags(osmNode, element);
                map.addNode(osmNode);
View Full Code Here


    public Ring(List<Long> osmNodes, Map<Long, OSMNode> _nodes) {
        ArrayList<VLPoint> vertices = new ArrayList<VLPoint>();
        nodes = new ArrayList<OSMNode>(osmNodes.size());
        for (long nodeId : osmNodes) {
            OSMNode node = _nodes.get(nodeId);
            if (nodes.contains(node)) {
                // hopefully, this only happens in order to
                // close polygons
                continue;
            }
View Full Code Here

                    }
                }

                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);
            // FIXME: temporary hard limit on size of
            // 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,
View Full Code Here

        return poly;
    }

    private void createEdgesForRingSegment(Set<Edge> edges, AreaEdgeList edgeList, Area area,
            Ring ring, int i, HashSet<P2<OSMNode>> alreadyAddedEdges) {
        OSMNode node = ring.nodes.get(i);
        OSMNode nextNode = ring.nodes.get((i + 1) % ring.nodes.size());
        P2<OSMNode> nodePair = new P2<OSMNode>(node, nextNode);
        if (alreadyAddedEdges.contains(nodePair)) {
            return;
        }
        alreadyAddedEdges.add(nodePair);
View Full Code Here

    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) {
View Full Code Here

        }
    }

    private void reversePolygonOfOSMNodes(List<OSMNode> nodes) {
        for (int i = 1; i < (nodes.size() + 1) / 2; ++i) {
            OSMNode tmp = nodes.get(i);
            int opposite = nodes.size() - i;
            nodes.set(i, nodes.get(opposite));
            nodes.set(opposite, tmp);
        }
    }
View Full Code Here

    }

    private Ring toRing(Polygon polygon, HashMap<Coordinate, OSMNode> nodeMap) {
        List<OSMNode> shell = new ArrayList<OSMNode>();
        for (Coordinate coord : polygon.getExteriorRing().getCoordinates()) {
            OSMNode node = nodeMap.get(coord);
            if (node == null) {
                throw new RingConstructionException();
            }
            shell.add(node);
        }
        Ring ring = new Ring(shell, true);
        // now the holes
        for (int i = 0; i < polygon.getNumInteriorRing(); ++i) {
            LineString interior = polygon.getInteriorRingN(i);
            List<OSMNode> hole = new ArrayList<OSMNode>();
            for (Coordinate coord : interior.getCoordinates()) {
                OSMNode node = nodeMap.get(coord);
                if (node == null) {
                    throw new RingConstructionException();
                }
                hole.add(node);
            }
View Full Code Here

                ArrayList<Long> nodes = new ArrayList<Long>(way.getNodeRefs().size());
                long last = -1;
                double lastLat = -1, lastLon = -1;
                String lastLevel = null;
                for (long nodeId : way.getNodeRefs()) {
                    OSMNode node = osmdb.getNode(nodeId);
                    if (node == null)
                        continue WAY;
                    boolean levelsDiffer = false;
                    String level = node.getTag("level");
                    if (lastLevel == null) {
                        if (level != null) {
                            levelsDiffer = true;
                        }
                    } else {
                        if (!lastLevel.equals(level)) {
                            levelsDiffer = true;
                        }
                    }
                    if (nodeId != last
                            && (node.lat != lastLat || node.lon != lastLon || levelsDiffer))
                        nodes.add(nodeId);
                    last = nodeId;
                    lastLon = node.lon;
                    lastLat = node.lat;
                    lastLevel = level;
                }

                IntersectionVertex startEndpoint = null, endEndpoint = null;

                ArrayList<Coordinate> segmentCoordinates = new ArrayList<Coordinate>();

                /*
                 * Traverse through all the nodes of this edge. For nodes which are not shared with any other edge, do not create endpoints -- just
                 * accumulate them for geometry and ele tags. For nodes which are shared, create endpoints and StreetVertex instances. One exception:
                 * if the next vertex also appears earlier in the way, we need to split the way, because otherwise we have a way that loops from a
                 * vertex to itself, which could cause issues with splitting.
                 */
                Long startNode = null;
                // where the current edge should start
                OSMNode osmStartNode = null;

                for (int i = 0; i < nodes.size() - 1; i++) {
                    OSMNode segmentStartOSMNode = osmdb.getNode(nodes.get(i));
                    if (segmentStartOSMNode == null) {
                        continue;
                    }
                    Long endNode = nodes.get(i + 1);
                    if (osmStartNode == null) {
                        startNode = nodes.get(i);
                        osmStartNode = segmentStartOSMNode;
                    }
                    // where the current edge might end
                    OSMNode osmEndNode = osmdb.getNode(endNode);

                    if (osmStartNode == null || osmEndNode == null)
                        continue;

                    LineString geometry;

                    /*
                     * We split segments at intersections, self-intersections, nodes with ele tags, and transit stops;
                     * the only processing we do on other nodes is to accumulate their geometry
                     */
                    if (segmentCoordinates.size() == 0) {
                        segmentCoordinates.add(getCoordinate(osmStartNode));
                    }

                    if (intersectionNodes.containsKey(endNode) || i == nodes.size() - 2
                            || nodes.subList(0, i).contains(nodes.get(i))
                            || osmEndNode.hasTag("ele")
                            || osmEndNode.isStop()) {
                        segmentCoordinates.add(getCoordinate(osmEndNode));

                        geometry = GeometryUtils.getGeometryFactory().createLineString(
                                segmentCoordinates.toArray(new Coordinate[0]));
                        segmentCoordinates.clear();
                    } else {
                        segmentCoordinates.add(getCoordinate(osmEndNode));
                        continue;
                    }

                    /* generate endpoints */
                    if (startEndpoint == null) { // first iteration on this way
                        // make or get a shared vertex for flat intersections,
                        // one vertex per level for multilevel nodes like elevators
                        startEndpoint = getVertexForOsmNode(osmStartNode, way);
                        String ele = segmentStartOSMNode.getTag("ele");
                        if (ele != null) {
                            Double elevation = ElevationUtils.parseEleTag(ele);
                            if (elevation != null) {
                                elevationData.put(startEndpoint, elevation);
                            }
                        }
                    } else { // subsequent iterations
                        startEndpoint = endEndpoint;
                    }

                    endEndpoint = getVertexForOsmNode(osmEndNode, way);
                    String ele = osmEndNode.getTag("ele");
                    if (ele != null) {
                        Double elevation = ElevationUtils.parseEleTag(ele);
                        if (elevation != null) {
                            elevationData.put(endEndpoint, elevation);
                        }
                    }
                    P2<StreetEdge> streets = getEdgesForStreet(startEndpoint, endEndpoint,
                            way, i, osmStartNode.getId(), osmEndNode.getId(), permissions, geometry);

                    StreetEdge street = streets.first;
                    StreetEdge backStreet = streets.second;
                    applyWayProperties(street, backStreet, wayData, way);

View Full Code Here

        }

        private void buildElevatorEdges(Graph graph) {
            /* build elevator edges */
            for (Long nodeId : multiLevelNodes.keySet()) {
                OSMNode node = osmdb.getNode(nodeId);
                // this allows skipping levels, e.g., an elevator that stops
                // at floor 0, 2, 3, and 5.
                // Converting to an Array allows us to
                // subscript it so we can loop over it in twos. Assumedly, it will stay
                // sorted when we convert it to an Array.
                // The objects are Integers, but toArray returns Object[]
                HashMap<OSMLevel, IntersectionVertex> vertices = multiLevelNodes.get(nodeId);

                /*
                 * first, build FreeEdges to disconnect from the graph, GenericVertices to serve as attachment points, and ElevatorBoard and
                 * ElevatorAlight edges to connect future ElevatorHop edges to. After this iteration, graph will look like (side view): +==+~~X
                 *
                 * +==+~~X
                 *
                 * +==+~~X
                 *
                 * + GenericVertex, X EndpointVertex, ~~ FreeEdge, == ElevatorBoardEdge/ElevatorAlightEdge Another loop will fill in the
                 * ElevatorHopEdges.
                 */

                OSMLevel[] levels = vertices.keySet().toArray(new OSMLevel[0]);
                Arrays.sort(levels);
                ArrayList<Vertex> onboardVertices = new ArrayList<Vertex>();
                for (OSMLevel level : levels) {
                    // get the node to build the elevator out from
                    IntersectionVertex sourceVertex = vertices.get(level);
                    String sourceVertexLabel = sourceVertex.getLabel();
                    String levelName = level.longName;

                    ElevatorOffboardVertex offboardVertex = new ElevatorOffboardVertex(graph,
                            sourceVertexLabel + "_offboard", sourceVertex.getX(),
                            sourceVertex.getY(), levelName);

                    new FreeEdge(sourceVertex, offboardVertex);
                    new FreeEdge(offboardVertex, sourceVertex);

                    ElevatorOnboardVertex onboardVertex = new ElevatorOnboardVertex(graph,
                            sourceVertexLabel + "_onboard", sourceVertex.getX(),
                            sourceVertex.getY(), levelName);

                    new ElevatorBoardEdge(offboardVertex, onboardVertex);
                    new ElevatorAlightEdge(onboardVertex, offboardVertex, level.longName);

                    // accumulate onboard vertices to so they can be connected by hop edges later
                    onboardVertices.add(onboardVertex);
                }

                // -1 because we loop over onboardVertices two at a time
                for (Integer i = 0, vSize = onboardVertices.size() - 1; i < vSize; i++) {
                    Vertex from = onboardVertices.get(i);
                    Vertex to = onboardVertices.get(i + 1);

                    // default permissions: pedestrian, wheelchair, and bicycle
                    boolean wheelchairAccessible = true;
                    StreetTraversalPermission permission = StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE;
                    // check for bicycle=no, otherwise assume it's OK to take a bike
                    if (node.isTagFalse("bicycle")) {
                        permission = StreetTraversalPermission.PEDESTRIAN;
                    }
                    // check for wheelchair=no
                    if (node.isTagFalse("wheelchair")) {
                        wheelchairAccessible = false;
                    }

                    // The narrative won't be strictly correct, as it will show the elevator as part
                    // of the cycling leg, but I think most cyclists will figure out that they
View Full Code Here

            OSMLevel wayLevel = getLevelForWay(way);

            // For each segment of the way
            for (int i = 0; i < way.getNodeRefs().size() - 1; i++) {

                OSMNode nA = nodesById.get(way.getNodeRefs().get(i));
                OSMNode nB = nodesById.get(way.getNodeRefs().get(i + 1));
                if (nA == null || nB == null) {
                    continue;
                }

                Envelope env = new Envelope(nA.lon, nB.lon, nA.lat, nB.lat);
                List<RingSegment> ringSegments = spndx.query(env);
                if (ringSegments.size() == 0)
                    continue;
                LineString seg = GeometryUtils.makeLineString(nA.lon, nA.lat, nB.lon, nB.lat);

                for (RingSegment ringSegment : ringSegments) {

                    // Skip if both segments share a common node
                    if (ringSegment.nA.getId() == nA.getId()
                            || ringSegment.nA.getId() == nB.getId()
                            || ringSegment.nB.getId() == nA.getId()
                            || ringSegment.nB.getId() == nB.getId())
                        continue;

                    // Check for real intersection
                    LineString seg2 = GeometryUtils.makeLineString(ringSegment.nA.lon,
                            ringSegment.nA.lat, ringSegment.nB.lon, ringSegment.nB.lat);
                    Geometry intersection = seg2.intersection(seg);
                    Point p = null;
                    if (intersection.isEmpty()) {
                        continue;
                    } else if (intersection instanceof Point) {
                        p = (Point) intersection;
                    } else {
                        /*
                         * This should never happen (intersection between two lines should be a
                         * point or a multi-point).
                         */
                        LOG.error("Alien intersection type between {} ({}--{}) and {} ({}--{}): ",
                                way, nA, nB, ringSegment.area.parent, ringSegment.nA,
                                ringSegment.nB, intersection);
                        continue;
                    }

                    // Skip if area and way are from "incompatible" levels
                    OSMLevel areaLevel = getLevelForWay(ringSegment.area.parent);
                    if (!wayLevel.equals(areaLevel))
                        continue;

                    // Create a virtual node and insert it in both the way and the ring
                    OSMNode virtualNode = createVirtualNode(p.getCoordinate());
                    nCreatedNodes++;
                    LOG.debug(
                            "Adding virtual {}, intersection of {} ({}--{}) and area {} ({}--{}) at {}.",
                            virtualNode, way, nA, nB, ringSegment.area.parent, ringSegment.nA,
                            ringSegment.nB, p);
                    way.addNodeRef(virtualNode.getId(), i + 1);
                    /*
                     * The line below is O(n^2) but we do not insert often and ring size should be
                     * rather small.
                     */
                    int j = ringSegment.ring.nodes.indexOf(ringSegment.nA);
View Full Code Here

TOP

Related Classes of org.opentripplanner.openstreetmap.model.OSMNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.