Search in sources :

Example 1 with OSMRelationMember

use of org.opentripplanner.openstreetmap.model.OSMRelationMember 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)

Aggregations

OSMNode (org.opentripplanner.openstreetmap.model.OSMNode)1 OSMNodeRef (org.opentripplanner.openstreetmap.model.OSMNodeRef)1 OSMRelation (org.opentripplanner.openstreetmap.model.OSMRelation)1 OSMRelationMember (org.opentripplanner.openstreetmap.model.OSMRelationMember)1 OSMWay (org.opentripplanner.openstreetmap.model.OSMWay)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1