use of de.topobyte.osm4j.pbf.seq.PbfIterator 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.pbf.seq.PbfIterator in project osm4j-pbf by topobyte.
the class Util method iterate.
public static void iterate(File file, boolean fetchMetadata) throws IOException {
InputStream input = new FileInputStream(file);
OsmIterator iterator = new PbfIterator(input, fetchMetadata);
while (iterator.hasNext()) {
iterator.next();
}
input.close();
}
use of de.topobyte.osm4j.pbf.seq.PbfIterator in project osm4j-pbf by topobyte.
the class Util method copyAndRead.
public static void copyAndRead(String resource, boolean readMetadata, boolean writeMetadata) throws IOException {
InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
OsmIterator iterator = new PbfIterator(input, readMetadata);
File file = File.createTempFile("osm4j-test", "pbf");
OutputStream output = new FileOutputStream(file);
OsmOutputStream osmOutput = new PbfWriter(output, writeMetadata);
for (EntityContainer container : iterator) {
switch(container.getType()) {
default:
case Node:
osmOutput.write((OsmNode) container.getEntity());
break;
case Way:
osmOutput.write((OsmWay) container.getEntity());
break;
case Relation:
osmOutput.write((OsmRelation) container.getEntity());
break;
}
}
osmOutput.complete();
output.close();
Util.iterate(file, true);
Util.iterate(file, false);
file.delete();
}
use of de.topobyte.osm4j.pbf.seq.PbfIterator in project osm4j-pbf by topobyte.
the class Util method iterate.
public static void iterate(String resource, boolean fetchMetadata) throws IOException {
InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
OsmIterator iterator = new PbfIterator(input, fetchMetadata);
while (iterator.hasNext()) {
iterator.next();
}
input.close();
}
Aggregations