Search in sources :

Example 1 with PbfIterator

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);
}
Also used : EntityContainer(de.topobyte.osm4j.core.model.iface.EntityContainer) File(java.io.File) PbfIterator(de.topobyte.osm4j.pbf.seq.PbfIterator) FileInputStream(java.io.FileInputStream)

Example 2 with PbfIterator

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();
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OsmIterator(de.topobyte.osm4j.core.access.OsmIterator) PbfIterator(de.topobyte.osm4j.pbf.seq.PbfIterator) FileInputStream(java.io.FileInputStream)

Example 3 with PbfIterator

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();
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) OsmOutputStream(de.topobyte.osm4j.core.access.OsmOutputStream) FileOutputStream(java.io.FileOutputStream) PbfWriter(de.topobyte.osm4j.pbf.seq.PbfWriter) EntityContainer(de.topobyte.osm4j.core.model.iface.EntityContainer) OsmIterator(de.topobyte.osm4j.core.access.OsmIterator) PbfIterator(de.topobyte.osm4j.pbf.seq.PbfIterator) File(java.io.File) OsmOutputStream(de.topobyte.osm4j.core.access.OsmOutputStream)

Example 4 with PbfIterator

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();
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OsmIterator(de.topobyte.osm4j.core.access.OsmIterator) PbfIterator(de.topobyte.osm4j.pbf.seq.PbfIterator)

Aggregations

PbfIterator (de.topobyte.osm4j.pbf.seq.PbfIterator)4 FileInputStream (java.io.FileInputStream)4 OsmIterator (de.topobyte.osm4j.core.access.OsmIterator)3 InputStream (java.io.InputStream)3 EntityContainer (de.topobyte.osm4j.core.model.iface.EntityContainer)2 File (java.io.File)2 OsmOutputStream (de.topobyte.osm4j.core.access.OsmOutputStream)1 PbfWriter (de.topobyte.osm4j.pbf.seq.PbfWriter)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1