use of org.opentripplanner.graph_builder.module.osm.Ring.RingConstructionException 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.graph_builder.module.osm.Ring.RingConstructionException 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;
}
Aggregations