Search in sources :

Example 1 with OSMLevel

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

Aggregations

ArrayList (java.util.ArrayList)1 DisjointSet (org.opentripplanner.common.DisjointSet)1 RingConstructionException (org.opentripplanner.graph_builder.module.osm.Ring.RingConstructionException)1 OSMLevel (org.opentripplanner.openstreetmap.model.OSMLevel)1 OSMNode (org.opentripplanner.openstreetmap.model.OSMNode)1