use of de.topobyte.osm4j.core.model.iface.EntityContainer in project osm4j-pbf by topobyte.
the class TestCountIterator method main.
public static void main(String[] args) throws IOException {
if (args.length != 1) {
System.out.println("usage: " + TestCountIterator.class.getSimpleName() + " <filename>");
System.exit(1);
}
File file = new File(args[0]);
FileInputStream input = new FileInputStream(file);
Iterator<EntityContainer> iterator = new PbfIterator(input, false);
long nc = 0, wc = 0, rc = 0;
while (iterator.hasNext()) {
EntityContainer entityContainer = iterator.next();
switch(entityContainer.getType()) {
case Node:
nc++;
break;
case Way:
wc++;
break;
case Relation:
rc++;
break;
}
}
System.out.println("nodes: " + nc);
System.out.println("ways: " + wc);
System.out.println("relations: " + rc);
}
use of de.topobyte.osm4j.core.model.iface.EntityContainer 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 de.topobyte.osm4j.core.model.iface.EntityContainer in project osm4j-core by topobyte.
the class ListDataSetLoader method read.
public static InMemoryListDataSet read(OsmIterator iterator, boolean keepNodeTags, boolean keepWayTags, boolean keepRelationTags) throws IOException {
InMemoryListDataSet dataSet = new InMemoryListDataSet();
List<OsmNode> nodes = dataSet.getNodes();
List<OsmWay> ways = dataSet.getWays();
List<OsmRelation> relations = dataSet.getRelations();
if (iterator.hasBounds()) {
dataSet.setBounds(iterator.getBounds());
}
while (iterator.hasNext()) {
EntityContainer container = iterator.next();
switch(container.getType()) {
case Node:
OsmNode node = (OsmNode) container.getEntity();
if (!keepNodeTags) {
node = new Node(node.getId(), node.getLongitude(), node.getLatitude());
}
nodes.add(node);
break;
case Way:
OsmWay way = (OsmWay) container.getEntity();
if (!keepWayTags) {
TLongArrayList ids = new TLongArrayList();
for (int i = 0; i < way.getNumberOfNodes(); i++) {
ids.add(way.getNodeId(i));
}
way = new Way(way.getId(), ids);
}
ways.add(way);
break;
case Relation:
OsmRelation relation = (OsmRelation) container.getEntity();
if (!keepRelationTags) {
List<OsmRelationMember> members = new ArrayList<>();
for (int i = 0; i < relation.getNumberOfMembers(); i++) {
members.add(relation.getMember(i));
}
relation = new Relation(relation.getId(), members);
}
relations.add(relation);
break;
}
}
return dataSet;
}
use of de.topobyte.osm4j.core.model.iface.EntityContainer in project osm4j-core by topobyte.
the class MapDataSetLoader method read.
public static InMemoryMapDataSet read(OsmIterator iterator, boolean keepNodeTags, boolean keepWayTags, boolean keepRelationTags) throws IOException {
InMemoryMapDataSet dataSet = new InMemoryMapDataSet();
TLongObjectMap<OsmNode> nodes = dataSet.getNodes();
TLongObjectMap<OsmWay> ways = dataSet.getWays();
TLongObjectMap<OsmRelation> relations = dataSet.getRelations();
if (iterator.hasBounds()) {
dataSet.setBounds(iterator.getBounds());
}
while (iterator.hasNext()) {
EntityContainer container = iterator.next();
switch(container.getType()) {
case Node:
OsmNode node = (OsmNode) container.getEntity();
if (!keepNodeTags) {
node = new Node(node.getId(), node.getLongitude(), node.getLatitude());
}
nodes.put(node.getId(), node);
break;
case Way:
OsmWay way = (OsmWay) container.getEntity();
if (!keepWayTags) {
TLongArrayList ids = new TLongArrayList();
for (int i = 0; i < way.getNumberOfNodes(); i++) {
ids.add(way.getNodeId(i));
}
way = new Way(way.getId(), ids);
}
ways.put(way.getId(), way);
break;
case Relation:
OsmRelation relation = (OsmRelation) container.getEntity();
if (!keepRelationTags) {
List<OsmRelationMember> members = new ArrayList<>();
for (int i = 0; i < relation.getNumberOfMembers(); i++) {
members.add(relation.getMember(i));
}
relation = new Relation(relation.getId(), members);
}
relations.put(relation.getId(), relation);
break;
}
}
return dataSet;
}
use of de.topobyte.osm4j.core.model.iface.EntityContainer in project osm4j-core by topobyte.
the class EntityIterator method advance.
private void advance() {
while (iterator.hasNext()) {
EntityContainer container = iterator.next();
if (container.getType() != type) {
continue;
}
valid = true;
hasNext = true;
next = (T) container.getEntity();
return;
}
valid = true;
hasNext = false;
next = null;
}
Aggregations