Search in sources :

Example 1 with Blob

use of de.topobyte.osm4j.pbf.protobuf.Fileformat.Blob in project osm4j-pbf by topobyte.

the class EntitySplitBlockwise method copyWays.

private void copyWays(Interval ways, boolean firstWayBlockMixed, boolean lastWayBlockMixed) throws IOException {
    int firstWayOnlyBlock = ways.getStart();
    if (firstWayBlockMixed) {
        firstWayOnlyBlock += 1;
    }
    int lastWayOnlyBlock = ways.getEnd();
    if (lastWayBlockMixed) {
        lastWayOnlyBlock -= 1;
    }
    if (firstWayBlockMixed) {
        // First copy all ways from the first partial block
        copyPartial(ways.getStart(), EntityType.Way, blockWriterWays);
    }
    // Then copy all blocks that contain only ways block-wise
    for (int i = firstWayOnlyBlock; i <= lastWayOnlyBlock; i++) {
        Fileformat.Blob blob = pbfFile.getDataBlob(i);
        blockWriterWays.write(Constants.BLOCK_TYPE_DATA, null, blob);
    }
    // If the last block contains data other than ways, continue
    if (!lastWayBlockMixed) {
        return;
    }
    // But not if we copied the partial block in the beginning already
    if (ways.getStart() == ways.getEnd()) {
        return;
    }
    // Copy the remaining ways group-wise
    copyPartial(ways.getEnd(), EntityType.Way, blockWriterWays);
}
Also used : Blob(de.topobyte.osm4j.pbf.protobuf.Fileformat.Blob) Fileformat(de.topobyte.osm4j.pbf.protobuf.Fileformat)

Example 2 with Blob

use of de.topobyte.osm4j.pbf.protobuf.Fileformat.Blob in project osm4j-pbf by topobyte.

the class EntitySplitBlockwise method copyRelations.

private void copyRelations(Interval relations, boolean firstRelationBlockMixed) throws IOException {
    int firstRelationOnlyBlock = relations.getStart();
    if (firstRelationBlockMixed) {
        firstRelationOnlyBlock += 1;
    }
    if (firstRelationBlockMixed) {
        // First copy all relations from the first partial block
        copyPartial(relations.getStart(), EntityType.Relation, blockWriterRelations);
    }
    // Then copy all blocks that contain only relations block-wise
    for (int i = firstRelationOnlyBlock; i <= relations.getEnd(); i++) {
        Fileformat.Blob blob = pbfFile.getDataBlob(i);
        blockWriterRelations.write(Constants.BLOCK_TYPE_DATA, null, blob);
    }
}
Also used : Blob(de.topobyte.osm4j.pbf.protobuf.Fileformat.Blob) Fileformat(de.topobyte.osm4j.pbf.protobuf.Fileformat)

Example 3 with Blob

use of de.topobyte.osm4j.pbf.protobuf.Fileformat.Blob in project osm4j-pbf by topobyte.

the class EntitySplitBlockwise method copyNodes.

private void copyNodes(Interval nodes, boolean lastNodeBlockDirty) throws IOException {
    int lastNodeOnlyBlock = nodes.getEnd();
    if (lastNodeBlockDirty) {
        lastNodeOnlyBlock -= 1;
    }
    // First copy all blocks that contain only nodes block-wise
    for (int i = nodes.getStart(); i <= lastNodeOnlyBlock; i++) {
        Fileformat.Blob blob = pbfFile.getDataBlob(i);
        blockWriterNodes.write(Constants.BLOCK_TYPE_DATA, null, blob);
    }
    // If the last block contains data other than nodes, continue
    if (!lastNodeBlockDirty) {
        return;
    }
    // Copy the remaining nodes group-wise
    copyPartial(nodes.getEnd(), EntityType.Node, blockWriterNodes);
}
Also used : Blob(de.topobyte.osm4j.pbf.protobuf.Fileformat.Blob) Fileformat(de.topobyte.osm4j.pbf.protobuf.Fileformat)

Example 4 with Blob

use of de.topobyte.osm4j.pbf.protobuf.Fileformat.Blob 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)

Aggregations

Blob (de.topobyte.osm4j.pbf.protobuf.Fileformat.Blob)4 Fileformat (de.topobyte.osm4j.pbf.protobuf.Fileformat)3 PrimitiveBlock (de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock)1 BlockData (de.topobyte.osm4j.pbf.util.BlockData)1 EntityGroups (de.topobyte.osm4j.pbf.util.copy.EntityGroups)1