Search in sources :

Example 1 with PrimitiveGroup

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

the class EntitySplitBlockwise method copy.

private void copy(BlockWriter blockWriter, List<PrimitiveGroup> gs, Osmformat.PrimitiveBlock primBlock, Compression compression) throws IOException {
    Osmformat.PrimitiveBlock.Builder builder = Osmformat.PrimitiveBlock.newBuilder();
    for (Osmformat.PrimitiveGroup group : gs) {
        builder.addPrimitivegroup(group);
    }
    copyExtraData(builder, primBlock);
    Osmformat.PrimitiveBlock block = builder.build();
    blockWriter.write(Constants.BLOCK_TYPE_DATA, null, compression, block.toByteString());
}
Also used : Builder(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock.Builder) PrimitiveBlock(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock) PrimitiveBlock(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock) Osmformat(de.topobyte.osm4j.pbf.protobuf.Osmformat) PrimitiveGroup(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveGroup)

Example 2 with PrimitiveGroup

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

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

the class EntitySplit method copy.

private void copy(BlockWriter blockWriter, List<PrimitiveGroup> gs, Osmformat.PrimitiveBlock primBlock, Compression compression) throws IOException {
    Osmformat.PrimitiveBlock.Builder builder = Osmformat.PrimitiveBlock.newBuilder();
    for (Osmformat.PrimitiveGroup group : gs) {
        builder.addPrimitivegroup(group);
    }
    copyExtraData(builder, primBlock);
    Osmformat.PrimitiveBlock block = builder.build();
    blockWriter.write(Constants.BLOCK_TYPE_DATA, null, compression, block.toByteString());
}
Also used : Builder(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock.Builder) PrimitiveBlock(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock) PrimitiveBlock(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock) Osmformat(de.topobyte.osm4j.pbf.protobuf.Osmformat) PrimitiveGroup(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveGroup)

Example 4 with PrimitiveGroup

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

the class BlockElementCountInfo method parse.

@Override
protected void parse(Osmformat.PrimitiveBlock block) {
    int elements = 0;
    for (int i = 0; i < block.getPrimitivegroupCount(); i++) {
        PrimitiveGroup group = block.getPrimitivegroup(i);
        elements += group.getNodesCount();
        elements += group.getWaysCount();
        elements += group.getRelationsCount();
        if (group.hasDense()) {
            elements += group.getDense().getIdCount();
        }
    }
    System.out.println(String.format("Block %d: %d", nBlocks, elements));
    nBlocks++;
}
Also used : PrimitiveGroup(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveGroup)

Aggregations

PrimitiveGroup (de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveGroup)4 PrimitiveBlock (de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock)3 Osmformat (de.topobyte.osm4j.pbf.protobuf.Osmformat)2 Builder (de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock.Builder)2 ByteString (com.google.protobuf.ByteString)1