Search in sources :

Example 1 with CountingMultiValMap

use of de.topobyte.adt.multicollections.CountingMultiValMap in project osm4j-geometry by topobyte.

the class RelationUtil method buildWayTailMap.

/**
 * For all ways given, build a multivalmap from node-ids to ways. Head and
 * tail of each way are put as key and the way as value.
 */
public static CountingMultiValMap<Long, OsmWay> buildWayTailMap(MultiSet<OsmWay> ways) {
    CountingMultiValMap<Long, OsmWay> waysNodes = new CountingMultiValMap<>();
    for (OsmWay way : ways) {
        // add all of them to waysNodes. implement iterator correctly...
        int nnodes = way.getNumberOfNodes();
        if (nnodes < 2) {
            throw new IllegalArgumentException("Only ways with 2 or more nodes are allowed");
        }
        long node1 = way.getNodeId(0);
        long nodeN = way.getNodeId(nnodes - 1);
        waysNodes.add(node1, way);
        waysNodes.add(nodeN, way);
    }
    return waysNodes;
}
Also used : OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) CountingMultiValMap(de.topobyte.adt.multicollections.CountingMultiValMap)

Aggregations

CountingMultiValMap (de.topobyte.adt.multicollections.CountingMultiValMap)1 OsmWay (de.topobyte.osm4j.core.model.iface.OsmWay)1