use of org.opentripplanner.openstreetmap.model.OSMRelation 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();
}
}
Aggregations