Search in sources :

Example 1 with OSMNode

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

the class OpenStreetMapParser method processDocument.

private void processDocument(Document doc, OpenStreetMapContentHandler map, int phase) {
    Node osm = doc.getFirstChild();
    Node node = osm.getFirstChild();
    while (node != null) {
        if (!(node instanceof Element)) {
            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);
        } else if (phase == 2 && element.getTagName().equals("way")) {
            OSMWay osmWay = new OSMWay();
            osmWay.setId(Long.parseLong(element.getAttribute("id")));
            processTags(osmWay, element);
            Node node2 = element.getFirstChild();
            while (node2 != null) {
                if (!(node2 instanceof Element)) {
                    node2 = node2.getNextSibling();
                    continue;
                }
                Element element2 = (Element) node2;
                if (element2.getNodeName().equals("nd")) {
                    OSMNodeRef nodeRef = new OSMNodeRef();
                    nodeRef.setRef(Long.parseLong(element2.getAttribute("ref")));
                    osmWay.addNodeRef(nodeRef);
                }
                node2 = node2.getNextSibling();
            }
            map.addWay(osmWay);
        } else if (phase == 1 && element.getTagName().equals("relation")) {
            OSMRelation osmRelation = new OSMRelation();
            osmRelation.setId(Long.parseLong(element.getAttribute("id")));
            processTags(osmRelation, element);
            Node node2 = element.getFirstChild();
            while (node2 != null) {
                if (!(node2 instanceof Element)) {
                    node2 = node2.getNextSibling();
                    continue;
                }
                Element element2 = (Element) node2;
                if (element2.getNodeName().equals("member")) {
                    OSMRelationMember member = new OSMRelationMember();
                    member.setRole(element2.getAttribute("role"));
                    member.setType(element2.getAttribute("type"));
                    member.setRef(Long.parseLong(element2.getAttribute("ref")));
                    osmRelation.addMember(member);
                }
                node2 = node2.getNextSibling();
            }
            map.addRelation(osmRelation);
        }
        node = node.getNextSibling();
    }
}
Also used : OSMWay(org.opentripplanner.openstreetmap.model.OSMWay) OSMRelation(org.opentripplanner.openstreetmap.model.OSMRelation) OSMRelationMember(org.opentripplanner.openstreetmap.model.OSMRelationMember) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode) OSMNodeRef(org.opentripplanner.openstreetmap.model.OSMNodeRef)

Example 2 with OSMNode

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

the class BarrierVertexTest method testBarrierPermissions.

@Test
public void testBarrierPermissions() throws Exception {
    OSMNode simpleBarier = new OSMNode();
    assertFalse(simpleBarier.isBollard());
    simpleBarier.addTag("barrier", "bollard");
    assertTrue(simpleBarier.isBollard());
    Graph graph = new Graph();
    String label = "simpleBarrier";
    BarrierVertex bv = new BarrierVertex(graph, label, simpleBarier.lon, simpleBarier.lat, 0);
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(simpleBarier, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE, bv.getBarrierPermissions());
    simpleBarier.addTag("foot", "yes");
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(simpleBarier, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE, bv.getBarrierPermissions());
    simpleBarier.addTag("bicycle", "yes");
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(simpleBarier, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE, bv.getBarrierPermissions());
    simpleBarier.addTag("access", "no");
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(simpleBarier, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE, bv.getBarrierPermissions());
    simpleBarier.addTag("motor_vehicle", "no");
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(simpleBarier, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE, bv.getBarrierPermissions());
    simpleBarier.addTag("bicycle", "no");
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(simpleBarier, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.PEDESTRIAN, bv.getBarrierPermissions());
    OSMNode complexBarrier = new OSMNode();
    complexBarrier.addTag("barrier", "bollard");
    complexBarrier.addTag("access", "no");
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(complexBarrier, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.NONE, bv.getBarrierPermissions());
    OSMNode noBikeBollard = new OSMNode();
    noBikeBollard.addTag("barrier", "bollard");
    noBikeBollard.addTag("bicycle", "no");
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(noBikeBollard, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.PEDESTRIAN, bv.getBarrierPermissions());
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode) LineString(com.vividsolutions.jts.geom.LineString) Test(org.junit.Test)

Example 3 with OSMNode

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

the class AreaGroup method groupAreas.

public static List<AreaGroup> groupAreas(Map<Area, OSMLevel> areasLevels) {
    DisjointSet<Area> groups = new DisjointSet<Area>();
    Multimap<OSMNode, Area> areasForNode = LinkedListMultimap.create();
    for (Area area : areasLevels.keySet()) {
        for (Ring ring : area.outermostRings) {
            for (Ring inner : ring.holes) {
                for (OSMNode node : inner.nodes) {
                    areasForNode.put(node, area);
                }
            }
            for (OSMNode node : ring.nodes) {
                areasForNode.put(node, area);
            }
        }
    }
    // areas that can be joined must share nodes and levels
    for (OSMNode osmNode : areasForNode.keySet()) {
        for (Area area1 : areasForNode.get(osmNode)) {
            OSMLevel level1 = areasLevels.get(area1);
            for (Area area2 : areasForNode.get(osmNode)) {
                OSMLevel level2 = areasLevels.get(area2);
                if ((level1 == null && level2 == null) || (level1 != null && level1.equals(level2))) {
                    groups.union(area1, area2);
                }
            }
        }
    }
    List<AreaGroup> out = new ArrayList<AreaGroup>();
    for (Set<Area> areaSet : groups.sets()) {
        try {
            out.add(new AreaGroup(areaSet));
        } catch (RingConstructionException e) {
            for (Area area : areaSet) {
                LOG.debug("Failed to create merged area for " + area + ".  This area might not be at fault; it might be one of the other areas in this list.");
                out.add(new AreaGroup(Arrays.asList(area)));
            }
        }
    }
    return out;
}
Also used : RingConstructionException(org.opentripplanner.graph_builder.module.osm.Ring.RingConstructionException) ArrayList(java.util.ArrayList) DisjointSet(org.opentripplanner.common.DisjointSet) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode) OSMLevel(org.opentripplanner.openstreetmap.model.OSMLevel)

Example 4 with OSMNode

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

the class AreaGroup method toRing.

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);
        }
        ring.holes.add(new Ring(hole, true));
    }
    return ring;
}
Also used : RingConstructionException(org.opentripplanner.graph_builder.module.osm.Ring.RingConstructionException) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) ArrayList(java.util.ArrayList) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode)

Example 5 with OSMNode

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

the class WalkableAreaBuilder method createEdgesForRingSegment.

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);
    IntersectionVertex startEndpoint = __handler.getVertexForOsmNode(node, area.parent);
    IntersectionVertex endEndpoint = __handler.getVertexForOsmNode(nextNode, area.parent);
    createSegments(node, nextNode, startEndpoint, endEndpoint, Arrays.asList(area), edgeList, edges);
}
Also used : P2(org.opentripplanner.common.model.P2) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode)

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