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;
}
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;
}
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;
}
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));
}
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
}
}
}
}
Aggregations