Search in sources :

Example 1 with TLongSet

use of com.slimjars.dist.gnu.trove.set.TLongSet in project osm4j-core by topobyte.

the class IdDataSetReader method read.

public static InMemorySetIdDataSet read(OsmReader reader) throws OsmInputException {
    final InMemorySetIdDataSet dataSet = new InMemorySetIdDataSet();
    final TLongSet nodeIds = dataSet.getNodeIds();
    final TLongSet wayIds = dataSet.getWayIds();
    final TLongSet relationIds = dataSet.getRelationIds();
    reader.setHandler(new OsmHandler() {

        @Override
        public void handle(OsmBounds bounds) throws IOException {
            dataSet.setBounds(bounds);
        }

        @Override
        public void handle(OsmNode node) throws IOException {
            nodeIds.add(node.getId());
        }

        @Override
        public void handle(OsmWay way) throws IOException {
            wayIds.add(way.getId());
        }

        @Override
        public void handle(OsmRelation relation) throws IOException {
            relationIds.add(relation.getId());
        }

        @Override
        public void complete() throws IOException {
        // nothing to do here
        }
    });
    reader.read();
    return dataSet;
}
Also used : OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) OsmBounds(de.topobyte.osm4j.core.model.iface.OsmBounds) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) TLongSet(com.slimjars.dist.gnu.trove.set.TLongSet) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmHandler(de.topobyte.osm4j.core.access.OsmHandler) IOException(java.io.IOException)

Example 2 with TLongSet

use of com.slimjars.dist.gnu.trove.set.TLongSet in project osm4j-core by topobyte.

the class IdDataSetReader method read.

public static InMemorySetIdDataSet read(OsmIterator iterator) throws IOException {
    InMemorySetIdDataSet dataSet = new InMemorySetIdDataSet();
    TLongSet nodeIds = dataSet.getNodeIds();
    TLongSet wayIds = dataSet.getWayIds();
    TLongSet relationIds = dataSet.getRelationIds();
    if (iterator.hasBounds()) {
        dataSet.setBounds(iterator.getBounds());
    }
    while (iterator.hasNext()) {
        EntityContainer container = iterator.next();
        switch(container.getType()) {
            case Node:
                nodeIds.add(container.getEntity().getId());
                break;
            case Way:
                wayIds.add(container.getEntity().getId());
                break;
            case Relation:
                relationIds.add(container.getEntity().getId());
                break;
        }
    }
    return dataSet;
}
Also used : TLongSet(com.slimjars.dist.gnu.trove.set.TLongSet) EntityContainer(de.topobyte.osm4j.core.model.iface.EntityContainer)

Example 3 with TLongSet

use of com.slimjars.dist.gnu.trove.set.TLongSet in project osm4j-core by topobyte.

the class IdDataSetReader method read.

public static InMemorySetIdDataSet read(OsmIdIterator iterator) throws IOException {
    InMemorySetIdDataSet dataSet = new InMemorySetIdDataSet();
    TLongSet nodeIds = dataSet.getNodeIds();
    TLongSet wayIds = dataSet.getWayIds();
    TLongSet relationIds = dataSet.getRelationIds();
    if (iterator.hasBounds()) {
        dataSet.setBounds(iterator.getBounds());
    }
    while (iterator.hasNext()) {
        IdContainer container = iterator.next();
        switch(container.getType()) {
            case Node:
                nodeIds.add(container.getId());
                break;
            case Way:
                wayIds.add(container.getId());
                break;
            case Relation:
                relationIds.add(container.getId());
                break;
        }
    }
    return dataSet;
}
Also used : TLongSet(com.slimjars.dist.gnu.trove.set.TLongSet) IdContainer(de.topobyte.osm4j.core.model.iface.IdContainer)

Example 4 with TLongSet

use of com.slimjars.dist.gnu.trove.set.TLongSet in project osm4j-geometry by topobyte.

the class ChainOfNodes method hasNodeIntersections.

/**
 * Return whether this ring has intersections in terms of node ids appearing
 * multiple times.
 */
public boolean hasNodeIntersections() {
    int size = nodeIds.size();
    // Keep a set of already encountered ids
    TLongSet before = new TLongHashSet();
    // The first id can't be there already because the set is empty
    before.add(nodeIds.get(0));
    // Check all nodes except the last one which gets special care
    for (int i = 1; i < size - 1; i++) {
        long id = nodeIds.get(i);
        // Is it already on the set -> there is an intersection
        if (before.contains(id)) {
            return true;
        }
        // Add to the set of encountered ids
        before.add(id);
    }
    // that is okay
    if (isClosed()) {
        return false;
    }
    // with one of the others
    return before.contains(nodeIds.get(size - 1));
}
Also used : TLongSet(com.slimjars.dist.gnu.trove.set.TLongSet) TLongHashSet(com.slimjars.dist.gnu.trove.set.hash.TLongHashSet)

Example 5 with TLongSet

use of com.slimjars.dist.gnu.trove.set.TLongSet in project osm4j-core by topobyte.

the class EntityFinderIgnoreMissing method findMemberRelationsRecursively.

private void findMemberRelationsRecursively(Deque<OsmRelation> queue, Set<OsmRelation> outRelations) {
    TLongSet ids = new TLongHashSet();
    while (!queue.isEmpty()) {
        OsmRelation relation = queue.remove();
        for (OsmRelationMember member : OsmModelUtil.membersAsList(relation)) {
            if (member.getType() != EntityType.Relation) {
                continue;
            }
            long id = member.getId();
            if (ids.contains(id)) {
                continue;
            }
            ids.add(id);
            try {
                OsmRelation child = entityProvider.getRelation(id);
                outRelations.add(child);
                queue.add(child);
            } catch (EntityNotFoundException e) {
            // ignore silently
            }
        }
    }
}
Also used : TLongSet(com.slimjars.dist.gnu.trove.set.TLongSet) TLongHashSet(com.slimjars.dist.gnu.trove.set.hash.TLongHashSet) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember)

Aggregations

TLongSet (com.slimjars.dist.gnu.trove.set.TLongSet)8 TLongHashSet (com.slimjars.dist.gnu.trove.set.hash.TLongHashSet)4 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)4 OsmRelationMember (de.topobyte.osm4j.core.model.iface.OsmRelationMember)3 OsmBounds (de.topobyte.osm4j.core.model.iface.OsmBounds)2 IOException (java.io.IOException)2 OsmHandler (de.topobyte.osm4j.core.access.OsmHandler)1 OsmIdHandler (de.topobyte.osm4j.core.access.OsmIdHandler)1 EntityContainer (de.topobyte.osm4j.core.model.iface.EntityContainer)1 IdContainer (de.topobyte.osm4j.core.model.iface.IdContainer)1 OsmNode (de.topobyte.osm4j.core.model.iface.OsmNode)1 OsmWay (de.topobyte.osm4j.core.model.iface.OsmWay)1