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();
}
}
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());
}
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;
}
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;
}
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);
}
Aggregations