Search in sources :

Example 1 with HeaderBBox

use of de.topobyte.osm4j.pbf.protobuf.Osmformat.HeaderBBox in project osm4j-pbf by topobyte.

the class PbfParser method parse.

@Override
protected void parse(Osmformat.HeaderBlock block) throws IOException {
    HeaderBBox bbox = block.getBbox();
    handler.handle(PbfUtil.bounds(bbox));
}
Also used : HeaderBBox(de.topobyte.osm4j.pbf.protobuf.Osmformat.HeaderBBox)

Example 2 with HeaderBBox

use of de.topobyte.osm4j.pbf.protobuf.Osmformat.HeaderBBox 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

HeaderBBox (de.topobyte.osm4j.pbf.protobuf.Osmformat.HeaderBBox)2 Fileformat (de.topobyte.osm4j.pbf.protobuf.Fileformat)1 Osmformat (de.topobyte.osm4j.pbf.protobuf.Osmformat)1 BlobHeader (de.topobyte.osm4j.pbf.util.BlobHeader)1 BlockData (de.topobyte.osm4j.pbf.util.BlockData)1 IOException (java.io.IOException)1