Search in sources :

Example 1 with PrimitiveBlock

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

the class PbfWriter method writeBatch.

private void writeBatch() throws IOException {
    ensureHeader();
    Osmformat.PrimitiveBlock.Builder builder = Osmformat.PrimitiveBlock.newBuilder();
    // First add all strings to the string table
    addTagsToStringTable(bufNodes);
    addTagsToStringTable(bufWays);
    addTagsToStringTable(bufRelations);
    addMemberRolesToStringTable(bufRelations);
    if (writeMetadata) {
        addUsersToStringTable(bufNodes);
        addUsersToStringTable(bufWays);
        addUsersToStringTable(bufRelations);
    }
    // And build indices
    stringTable.finish();
    if (bufNodes.size() > 0) {
        if (useDense) {
            PrimitiveGroup group = serializeDense(bufNodes);
            builder.addPrimitivegroup(group);
        } else {
            PrimitiveGroup group = serializeNonDense(bufNodes);
            builder.addPrimitivegroup(group);
        }
        bufNodes.clear();
    }
    if (bufWays.size() > 0) {
        PrimitiveGroup group = serializeWays(bufWays);
        builder.addPrimitivegroup(group);
        bufWays.clear();
    }
    if (bufRelations.size() > 0) {
        PrimitiveGroup group = serializeRelations(bufRelations);
        builder.addPrimitivegroup(group);
        bufRelations.clear();
    }
    builder.setDateGranularity(dateGranularity);
    builder.setGranularity(granularity);
    builder.setStringtable(stringTable.serialize());
    PrimitiveBlock block = builder.build();
    ByteString data = block.toByteString();
    // Reset counter and string table
    counter = 0;
    stringTable.clear();
    write(Constants.BLOCK_TYPE_DATA, null, compression, data);
}
Also used : PrimitiveGroup(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveGroup) ByteString(com.google.protobuf.ByteString) PrimitiveBlock(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock)

Example 2 with PrimitiveBlock

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

PrimitiveBlock (de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock)2 ByteString (com.google.protobuf.ByteString)1 Blob (de.topobyte.osm4j.pbf.protobuf.Fileformat.Blob)1 PrimitiveGroup (de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveGroup)1 BlockData (de.topobyte.osm4j.pbf.util.BlockData)1 EntityGroups (de.topobyte.osm4j.pbf.util.copy.EntityGroups)1