Search in sources :

Example 1 with PbfWriter

use of de.topobyte.osm4j.pbf.seq.PbfWriter in project osm4j-pbf by topobyte.

the class CopyElementwise method main.

public static void main(String[] args) throws IOException, OsmInputException {
    if (args.length != 2) {
        System.out.println("usage: " + CopyElementwise.class.getSimpleName() + " <input> <output>");
        System.exit(1);
    }
    InputStream input = new FileInputStream(args[0]);
    OutputStream output = new FileOutputStream(args[1]);
    final PbfWriter writer = new PbfWriter(output, true);
    PbfParser parser = new PbfParser(new OsmHandler() {

        @Override
        public void handle(OsmBounds bounds) throws IOException {
            writer.write(bounds);
        }

        @Override
        public void handle(OsmNode node) throws IOException {
            writer.write(node);
        }

        @Override
        public void handle(OsmWay way) throws IOException {
            writer.write(way);
        }

        @Override
        public void handle(OsmRelation relation) throws IOException {
            writer.write(relation);
        }

        @Override
        public void complete() throws IOException {
            writer.complete();
        }
    }, true);
    parser.parse(input);
    output.close();
}
Also used : OsmBounds(de.topobyte.osm4j.core.model.iface.OsmBounds) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmHandler(de.topobyte.osm4j.core.access.OsmHandler) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) PbfParser(de.topobyte.osm4j.pbf.seq.PbfParser) FileOutputStream(java.io.FileOutputStream) PbfWriter(de.topobyte.osm4j.pbf.seq.PbfWriter)

Example 2 with PbfWriter

use of de.topobyte.osm4j.pbf.seq.PbfWriter 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)

Aggregations

PbfWriter (de.topobyte.osm4j.pbf.seq.PbfWriter)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 OsmHandler (de.topobyte.osm4j.core.access.OsmHandler)1 OsmIterator (de.topobyte.osm4j.core.access.OsmIterator)1 OsmOutputStream (de.topobyte.osm4j.core.access.OsmOutputStream)1 EntityContainer (de.topobyte.osm4j.core.model.iface.EntityContainer)1 OsmBounds (de.topobyte.osm4j.core.model.iface.OsmBounds)1 OsmNode (de.topobyte.osm4j.core.model.iface.OsmNode)1 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)1 OsmWay (de.topobyte.osm4j.core.model.iface.OsmWay)1 PbfIterator (de.topobyte.osm4j.pbf.seq.PbfIterator)1 PbfParser (de.topobyte.osm4j.pbf.seq.PbfParser)1 File (java.io.File)1 IOException (java.io.IOException)1