Search in sources :

Example 6 with BlockData

use of de.topobyte.osm4j.pbf.util.BlockData in project osm4j-pbf by topobyte.

the class PbfFile method getHeaderBlock.

/*
	 * Data access
	 */
public Osmformat.HeaderBlock getHeaderBlock() throws IOException {
    Fileformat.Blob blob = getBlockBlob(headerBlockInfo);
    BlockData blockData = PbfUtil.getBlockData(blob);
    return Osmformat.HeaderBlock.parseFrom(blockData.getBlobData());
}
Also used : Fileformat(de.topobyte.osm4j.pbf.protobuf.Fileformat) BlockData(de.topobyte.osm4j.pbf.util.BlockData)

Example 7 with BlockData

use of de.topobyte.osm4j.pbf.util.BlockData in project osm4j-pbf by topobyte.

the class PbfFile method getDataBlock.

public Osmformat.PrimitiveBlock getDataBlock(int i) throws IOException {
    BlockInfo info = dataBlockInfos.get(i);
    Fileformat.Blob blob = getBlockBlob(info);
    BlockData blockData = PbfUtil.getBlockData(blob);
    Osmformat.PrimitiveBlock primBlock = Osmformat.PrimitiveBlock.parseFrom(blockData.getBlobData());
    return primBlock;
}
Also used : Fileformat(de.topobyte.osm4j.pbf.protobuf.Fileformat) BlockData(de.topobyte.osm4j.pbf.util.BlockData) Osmformat(de.topobyte.osm4j.pbf.protobuf.Osmformat)

Example 8 with BlockData

use of de.topobyte.osm4j.pbf.util.BlockData in project osm4j-pbf by topobyte.

the class EntitySplitBlockwise method copyPartial.

private void copyPartial(int blockIndex, EntityType type, BlockWriter blockWriter) throws IOException {
    Blob blob = pbfFile.getDataBlob(blockIndex);
    BlockData blockData = PbfUtil.getBlockData(blob);
    PrimitiveBlock block = PrimitiveBlock.parseFrom(blockData.getBlobData());
    EntityGroups groups = EntityGroups.splitEntities(block);
    copy(blockWriter, groups.getGroups(type), block, blockData.getCompression());
}
Also used : Blob(de.topobyte.osm4j.pbf.protobuf.Fileformat.Blob) PrimitiveBlock(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock) EntityGroups(de.topobyte.osm4j.pbf.util.copy.EntityGroups) BlockData(de.topobyte.osm4j.pbf.util.BlockData)

Example 9 with BlockData

use of de.topobyte.osm4j.pbf.util.BlockData in project osm4j-pbf by topobyte.

the class HeaderInfo method main.

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        System.out.println("usage: " + HeaderInfo.class.getSimpleName() + " <filename>");
        System.exit(1);
    }
    InputStream input = new FileInputStream(args[0]);
    DataInputStream data = new DataInputStream(input);
    boolean passedFirst = false;
    boolean warningShown = false;
    while (true) {
        if (passedFirst && !warningShown) {
            System.out.println("Warning: first block is not a header!");
            System.out.println("... will continue reading until I find one.");
            warningShown = true;
        }
        try {
            BlobHeader header = PbfUtil.parseHeader(data);
            Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
            BlockData blockData = PbfUtil.getBlockData(blob);
            String type = header.getType();
            passedFirst = true;
            if (type.equals(Constants.BLOCK_TYPE_HEADER)) {
                Osmformat.HeaderBlock headerBlock = Osmformat.HeaderBlock.parseFrom(blockData.getBlobData());
                printHeaderInfo(headerBlock);
                return;
            }
        } catch (EOFException eof) {
            if (!passedFirst) {
                System.out.println("End of file before header");
            }
            break;
        }
    }
}
Also used : DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BlobHeader(de.topobyte.osm4j.pbf.util.BlobHeader) Fileformat(de.topobyte.osm4j.pbf.protobuf.Fileformat) DataInputStream(java.io.DataInputStream) Osmformat(de.topobyte.osm4j.pbf.protobuf.Osmformat) FileInputStream(java.io.FileInputStream) EOFException(java.io.EOFException) BlockData(de.topobyte.osm4j.pbf.util.BlockData)

Example 10 with BlockData

use of de.topobyte.osm4j.pbf.util.BlockData in project osm4j-pbf by topobyte.

the class BlockParser method parse.

@Override
protected void parse(BlobHeader header, Fileformat.Blob blob) throws IOException {
    BlockData blockData = PbfUtil.getBlockData(blob);
    String type = header.getType();
    if (type.equals(Constants.BLOCK_TYPE_DATA)) {
        Osmformat.PrimitiveBlock primBlock = Osmformat.PrimitiveBlock.parseFrom(blockData.getBlobData());
        parse(primBlock);
    } else if (type.equals(Constants.BLOCK_TYPE_HEADER)) {
        Osmformat.HeaderBlock headerBlock = Osmformat.HeaderBlock.parseFrom(blockData.getBlobData());
        parse(headerBlock);
    } else {
        throw new IOException("invalid PBF block");
    }
}
Also used : IOException(java.io.IOException) BlockData(de.topobyte.osm4j.pbf.util.BlockData) Osmformat(de.topobyte.osm4j.pbf.protobuf.Osmformat)

Aggregations

BlockData (de.topobyte.osm4j.pbf.util.BlockData)11 Fileformat (de.topobyte.osm4j.pbf.protobuf.Fileformat)8 Osmformat (de.topobyte.osm4j.pbf.protobuf.Osmformat)6 BlobHeader (de.topobyte.osm4j.pbf.util.BlobHeader)6 DataInputStream (java.io.DataInputStream)5 EOFException (java.io.EOFException)5 FileInputStream (java.io.FileInputStream)5 InputStream (java.io.InputStream)5 BlockWriter (de.topobyte.osm4j.pbf.seq.BlockWriter)4 FileOutputStream (java.io.FileOutputStream)4 OutputStream (java.io.OutputStream)4 PrimitiveBlock (de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock)2 EntityGroups (de.topobyte.osm4j.pbf.util.copy.EntityGroups)2 IOException (java.io.IOException)2 ByteString (com.google.protobuf.ByteString)1 EntityType (de.topobyte.osm4j.core.model.iface.EntityType)1 Compression (de.topobyte.osm4j.pbf.Compression)1 Blob (de.topobyte.osm4j.pbf.protobuf.Fileformat.Blob)1 HeaderBBox (de.topobyte.osm4j.pbf.protobuf.Osmformat.HeaderBBox)1