Search in sources :

Example 11 with BlockData

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

the class PbfIterator method advanceBlock.

private void advanceBlock() throws IOException {
    BlobHeader header = PbfUtil.parseHeader(input);
    Fileformat.Blob blob = PbfUtil.parseBlock(input, header.getDataLength());
    BlockData blockData = PbfUtil.getBlockData(blob);
    String type = header.getType();
    if (type.equals(Constants.BLOCK_TYPE_DATA)) {
        beyondBounds = true;
        Osmformat.PrimitiveBlock block = Osmformat.PrimitiveBlock.parseFrom(blockData.getBlobData());
        PrimParser primParser = new PrimParser(block, fetchMetadata);
        for (Osmformat.PrimitiveGroup group : block.getPrimitivegroupList()) {
            if (group.getNodesCount() > 0) {
                pushNodes(primParser, group.getNodesList());
            }
            if (group.hasDense()) {
                pushNodes(primParser, group.getDense());
            }
            if (group.getWaysCount() > 0) {
                pushWays(primParser, group.getWaysList());
            }
            if (group.getRelationsCount() > 0) {
                pushRelations(primParser, group.getRelationsList());
            }
        }
    } else if (type.equals(Constants.BLOCK_TYPE_HEADER)) {
        Osmformat.HeaderBlock block = Osmformat.HeaderBlock.parseFrom(blockData.getBlobData());
        HeaderBBox bbox = block.getBbox();
        if (bbox != null && !beyondBounds) {
            this.bounds = PbfUtil.bounds(bbox);
        }
        beyondBounds = true;
    } else {
        throw new IOException("invalid PBF block");
    }
}
Also used : HeaderBBox(de.topobyte.osm4j.pbf.protobuf.Osmformat.HeaderBBox) BlobHeader(de.topobyte.osm4j.pbf.util.BlobHeader) Fileformat(de.topobyte.osm4j.pbf.protobuf.Fileformat) 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