Search in sources :

Example 6 with TLongArrayList

use of com.slimjars.dist.gnu.trove.list.array.TLongArrayList in project osm4j-geometry by topobyte.

the class ChainOfNodes method resolveNodeIntersections.

/**
 * Build a new set of rings by splitting at node intersections.
 */
public List<ChainOfNodes> resolveNodeIntersections() {
    List<ChainOfNodes> results = new ArrayList<>();
    // Walk along the nodes in the ring and put them on the stack. Once an
    // id is encountered that is already on the stack somewhere, we found an
    // intersection. We track back by popping elements off the stack until
    // we reach the previous occurrence of the id, building a ring on the
    // way.
    LongSetStack stack = new LongSetStack();
    int size = nodeIds.size();
    for (int i = 0; i < size; i++) {
        long id = nodeIds.get(i);
        if (!stack.contains(id)) {
            // No intersection, just put on the stack
            stack.push(id);
        } else {
            // Intersection, track back
            TLongList list = new TLongArrayList();
            list.add(id);
            while (true) {
                long popped = stack.pop();
                list.add(popped);
                if (popped == id) {
                    break;
                }
            }
            results.add(new ChainOfNodes(list));
            // We need to push the current id to restore the state of the
            // structures as if the ring we just created had not existed at
            // all.
            stack.push(id);
        }
    }
    // element on the stack. In that case, add a last non-closed ring.
    if (stack.size() > 1) {
        TLongList list = new TLongArrayList();
        while (!stack.isEmpty()) {
            list.add(stack.pop());
        }
        results.add(new ChainOfNodes(list));
    }
    return results;
}
Also used : TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) ArrayList(java.util.ArrayList) TLongList(com.slimjars.dist.gnu.trove.list.TLongList)

Example 7 with TLongArrayList

use of com.slimjars.dist.gnu.trove.list.array.TLongArrayList in project osm4j-core by topobyte.

the class ImplUtil method clone.

public static Way clone(OsmWay way) {
    List<? extends OsmTag> tags = cloneTags(way);
    OsmMetadata metadata = cloneMetadata(way);
    TLongList nodes = new TLongArrayList(way.getNumberOfNodes());
    for (int i = 0; i < way.getNumberOfNodes(); i++) {
        nodes.add(way.getNodeId(i));
    }
    return new Way(way.getId(), nodes, tags, metadata);
}
Also used : OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) TLongList(com.slimjars.dist.gnu.trove.list.TLongList) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) Way(de.topobyte.osm4j.core.model.impl.Way)

Example 8 with TLongArrayList

use of com.slimjars.dist.gnu.trove.list.array.TLongArrayList in project osm4j-geometry by topobyte.

the class ChainOfWays method toSegmentRing.

public ChainOfNodes toSegmentRing() {
    if (segments.isEmpty()) {
        return new ChainOfNodes(new TLongArrayList());
    }
    int len = getLengthNonEmpty();
    TLongList ids = new TLongArrayList(len);
    for (int i = 0; i < segments.size(); i++) {
        WaySegment segment = segments.get(i);
        OsmWay way = segment.getWay();
        for (int k = 0; k < way.getNumberOfNodes(); k++) {
            if (k > 0 || i == 0) {
                ids.add(segment.getNodeId(k));
            }
        }
    }
    return new ChainOfNodes(ids);
}
Also used : OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) TLongList(com.slimjars.dist.gnu.trove.list.TLongList)

Example 9 with TLongArrayList

use of com.slimjars.dist.gnu.trove.list.array.TLongArrayList in project osm4j-geometry by topobyte.

the class RelationUtil method closeUnclosedRingWithStraightLine.

public static void closeUnclosedRingWithStraightLine(Collection<ChainOfWays> rings) {
    for (ChainOfWays ring : rings) {
        if (!ring.isClosed()) {
            logger.debug("unclosed ring with " + ring.getSegments().size() + " segments");
            List<WaySegment> segments = ring.getSegments();
            WaySegment rs1 = segments.get(0);
            WaySegment rs2 = segments.get(segments.size() - 1);
            long n1 = rs1.getNodeId(0);
            long n2 = rs2.getNodeId(rs2.getNumberOfNodes() - 1);
            TLongArrayList ids = new TLongArrayList();
            ids.add(n1);
            ids.add(n2);
            OsmWay filler = new Way(0L, ids);
            ring.addWay(filler);
        }
    }
}
Also used : OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) Way(de.topobyte.osm4j.core.model.impl.Way)

Aggregations

TLongArrayList (com.slimjars.dist.gnu.trove.list.array.TLongArrayList)9 OsmWay (de.topobyte.osm4j.core.model.iface.OsmWay)8 Way (de.topobyte.osm4j.core.model.impl.Way)7 ArrayList (java.util.ArrayList)6 OsmNode (de.topobyte.osm4j.core.model.iface.OsmNode)4 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)4 Node (de.topobyte.osm4j.core.model.impl.Node)4 Relation (de.topobyte.osm4j.core.model.impl.Relation)4 TLongList (com.slimjars.dist.gnu.trove.list.TLongList)3 OsmHandler (de.topobyte.osm4j.core.access.OsmHandler)2 EntityContainer (de.topobyte.osm4j.core.model.iface.EntityContainer)2 OsmBounds (de.topobyte.osm4j.core.model.iface.OsmBounds)2 OsmMetadata (de.topobyte.osm4j.core.model.iface.OsmMetadata)2 OsmRelationMember (de.topobyte.osm4j.core.model.iface.OsmRelationMember)2 IOException (java.io.IOException)2 List (java.util.List)2 OsmTag (de.topobyte.osm4j.core.model.iface.OsmTag)1 Tag (de.topobyte.osm4j.core.model.impl.Tag)1 Osmformat (de.topobyte.osm4j.pbf.protobuf.Osmformat)1