Search in sources :

Example 1 with BlockWriter

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

the class CopyGroupwise method main.

public static void main(String[] args) throws IOException {
    if (args.length != 2) {
        System.out.println("usage: " + CopyGroupwise.class.getSimpleName() + " <input> <output>");
        System.exit(1);
    }
    InputStream input = new FileInputStream(args[0]);
    OutputStream output = new FileOutputStream(args[1]);
    DataInputStream data = new DataInputStream(input);
    BlockWriter blockWriter = new BlockWriter(output);
    while (true) {
        try {
            BlobHeader header = PbfUtil.parseHeader(data);
            Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
            String type = header.getType();
            if (type.equals(Constants.BLOCK_TYPE_DATA)) {
                BlockData blockData = PbfUtil.getBlockData(blob);
                Osmformat.PrimitiveBlock primBlock = Osmformat.PrimitiveBlock.parseFrom(blockData.getBlobData());
                Osmformat.PrimitiveBlock.Builder builder = Osmformat.PrimitiveBlock.newBuilder();
                for (int i = 0; i < primBlock.getPrimitivegroupCount(); i++) {
                    Osmformat.PrimitiveGroup.Builder groupBuilder = Osmformat.PrimitiveGroup.newBuilder();
                    Osmformat.PrimitiveGroup group = primBlock.getPrimitivegroup(i);
                    List<Osmformat.Node> nodes = group.getNodesList();
                    Osmformat.DenseNodes dense = group.getDense();
                    List<Osmformat.Way> ways = group.getWaysList();
                    List<Osmformat.Relation> relations = group.getRelationsList();
                    groupBuilder.addAllNodes(nodes);
                    if (group.hasDense()) {
                        groupBuilder.setDense(dense);
                    }
                    groupBuilder.addAllWays(ways);
                    groupBuilder.addAllRelations(relations);
                    builder.addPrimitivegroup(groupBuilder.build());
                }
                builder.setGranularity(primBlock.getGranularity());
                builder.setDateGranularity(primBlock.getDateGranularity());
                builder.setStringtable(primBlock.getStringtable());
                Osmformat.PrimitiveBlock block = builder.build();
                ByteString message = block.toByteString();
                blockWriter.write(header.getType(), null, blockData.getCompression(), message);
            } else if (type.equals(Constants.BLOCK_TYPE_HEADER)) {
                blockWriter.write(header.getType(), null, blob);
            }
        } catch (EOFException eof) {
            break;
        }
    }
    output.close();
}
Also used : BlobHeader(de.topobyte.osm4j.pbf.util.BlobHeader) ByteString(com.google.protobuf.ByteString) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Fileformat(de.topobyte.osm4j.pbf.protobuf.Fileformat) ByteString(com.google.protobuf.ByteString) Osmformat(de.topobyte.osm4j.pbf.protobuf.Osmformat) EOFException(java.io.EOFException) BlockWriter(de.topobyte.osm4j.pbf.seq.BlockWriter) BlockData(de.topobyte.osm4j.pbf.util.BlockData) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream)

Example 2 with BlockWriter

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

the class Uncompress method main.

public static void main(String[] args) throws IOException {
    if (args.length != 2) {
        System.out.println("usage: " + Uncompress.class.getSimpleName() + " <input> <output>");
        System.exit(1);
    }
    InputStream input = new FileInputStream(args[0]);
    OutputStream output = new FileOutputStream(args[1]);
    DataInputStream data = new DataInputStream(input);
    BlockWriter blockWriter = new BlockWriter(output);
    while (true) {
        try {
            BlobHeader header = PbfUtil.parseHeader(data);
            Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
            BlockData blockData = PbfUtil.getBlockData(blob);
            blockWriter.write(header.getType(), null, Compression.NONE, blockData.getBlobData());
        } catch (EOFException eof) {
            break;
        }
    }
    output.close();
}
Also used : DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BlobHeader(de.topobyte.osm4j.pbf.util.BlobHeader) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) EOFException(java.io.EOFException) Fileformat(de.topobyte.osm4j.pbf.protobuf.Fileformat) BlockWriter(de.topobyte.osm4j.pbf.seq.BlockWriter) DataInputStream(java.io.DataInputStream) BlockData(de.topobyte.osm4j.pbf.util.BlockData) FileInputStream(java.io.FileInputStream)

Example 3 with BlockWriter

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

the class CompressDeflate method main.

public static void main(String[] args) throws IOException {
    if (args.length != 2) {
        System.out.println("usage: " + CompressDeflate.class.getSimpleName() + " <input> <output>");
        System.exit(1);
    }
    InputStream input = new FileInputStream(args[0]);
    OutputStream output = new FileOutputStream(args[1]);
    DataInputStream data = new DataInputStream(input);
    BlockWriter blockWriter = new BlockWriter(output);
    while (true) {
        try {
            BlobHeader header = PbfUtil.parseHeader(data);
            Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
            BlockData blockData = PbfUtil.getBlockData(blob);
            blockWriter.write(header.getType(), null, Compression.DEFLATE, blockData.getBlobData());
        } catch (EOFException eof) {
            break;
        }
    }
    output.close();
}
Also used : DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BlobHeader(de.topobyte.osm4j.pbf.util.BlobHeader) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) EOFException(java.io.EOFException) Fileformat(de.topobyte.osm4j.pbf.protobuf.Fileformat) BlockWriter(de.topobyte.osm4j.pbf.seq.BlockWriter) DataInputStream(java.io.DataInputStream) BlockData(de.topobyte.osm4j.pbf.util.BlockData) FileInputStream(java.io.FileInputStream)

Example 4 with BlockWriter

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

the class CompressLz4 method main.

public static void main(String[] args) throws IOException {
    if (args.length != 2) {
        System.out.println("usage: " + CompressLz4.class.getSimpleName() + " <input> <output>");
        System.exit(1);
    }
    InputStream input = new FileInputStream(args[0]);
    OutputStream output = new FileOutputStream(args[1]);
    DataInputStream data = new DataInputStream(input);
    BlockWriter blockWriter = new BlockWriter(output);
    while (true) {
        try {
            BlobHeader header = PbfUtil.parseHeader(data);
            Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
            BlockData blockData = PbfUtil.getBlockData(blob);
            blockWriter.write(header.getType(), null, Compression.LZ4, blockData.getBlobData());
        } catch (EOFException eof) {
            break;
        }
    }
    output.close();
}
Also used : DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BlobHeader(de.topobyte.osm4j.pbf.util.BlobHeader) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) EOFException(java.io.EOFException) Fileformat(de.topobyte.osm4j.pbf.protobuf.Fileformat) BlockWriter(de.topobyte.osm4j.pbf.seq.BlockWriter) DataInputStream(java.io.DataInputStream) BlockData(de.topobyte.osm4j.pbf.util.BlockData) FileInputStream(java.io.FileInputStream)

Example 5 with BlockWriter

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

the class CopyBlockwise method main.

public static void main(String[] args) throws IOException {
    if (args.length != 2 && args.length != 3) {
        System.out.println("usage: " + CopyBlockwise.class.getSimpleName() + " <input> <output> [<num blocks>]");
        System.exit(1);
    }
    InputStream input = new FileInputStream(args[0]);
    OutputStream output = new FileOutputStream(args[1]);
    boolean nBlocksSpecified = false;
    int nBlocks = 0;
    if (args.length == 3) {
        nBlocksSpecified = true;
        nBlocks = Integer.parseInt(args[2]);
    }
    data = new DataInputStream(input);
    blockWriter = new BlockWriter(output);
    if (nBlocksSpecified) {
        copyBlocks(nBlocks);
    } else {
        copyAllBlocks();
    }
    output.close();
}
Also used : DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) BlockWriter(de.topobyte.osm4j.pbf.seq.BlockWriter) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream)

Aggregations

BlockWriter (de.topobyte.osm4j.pbf.seq.BlockWriter)5 DataInputStream (java.io.DataInputStream)5 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)5 InputStream (java.io.InputStream)5 OutputStream (java.io.OutputStream)5 Fileformat (de.topobyte.osm4j.pbf.protobuf.Fileformat)4 BlobHeader (de.topobyte.osm4j.pbf.util.BlobHeader)4 BlockData (de.topobyte.osm4j.pbf.util.BlockData)4 EOFException (java.io.EOFException)4 ByteString (com.google.protobuf.ByteString)1 Osmformat (de.topobyte.osm4j.pbf.protobuf.Osmformat)1