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);
}
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());
}
Aggregations