use of de.topobyte.osm4j.pbf.util.BlockData in project osm4j-pbf by topobyte.
the class CopyGroupwise method main.
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.out.println("usage: " + CopyGroupwise.class.getSimpleName() + " <input> <output>");
System.exit(1);
}
InputStream input = new FileInputStream(args[0]);
OutputStream output = new FileOutputStream(args[1]);
DataInputStream data = new DataInputStream(input);
BlockWriter blockWriter = new BlockWriter(output);
while (true) {
try {
BlobHeader header = PbfUtil.parseHeader(data);
Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
String type = header.getType();
if (type.equals(Constants.BLOCK_TYPE_DATA)) {
BlockData blockData = PbfUtil.getBlockData(blob);
Osmformat.PrimitiveBlock primBlock = Osmformat.PrimitiveBlock.parseFrom(blockData.getBlobData());
Osmformat.PrimitiveBlock.Builder builder = Osmformat.PrimitiveBlock.newBuilder();
for (int i = 0; i < primBlock.getPrimitivegroupCount(); i++) {
Osmformat.PrimitiveGroup.Builder groupBuilder = Osmformat.PrimitiveGroup.newBuilder();
Osmformat.PrimitiveGroup group = primBlock.getPrimitivegroup(i);
List<Osmformat.Node> nodes = group.getNodesList();
Osmformat.DenseNodes dense = group.getDense();
List<Osmformat.Way> ways = group.getWaysList();
List<Osmformat.Relation> relations = group.getRelationsList();
groupBuilder.addAllNodes(nodes);
if (group.hasDense()) {
groupBuilder.setDense(dense);
}
groupBuilder.addAllWays(ways);
groupBuilder.addAllRelations(relations);
builder.addPrimitivegroup(groupBuilder.build());
}
builder.setGranularity(primBlock.getGranularity());
builder.setDateGranularity(primBlock.getDateGranularity());
builder.setStringtable(primBlock.getStringtable());
Osmformat.PrimitiveBlock block = builder.build();
ByteString message = block.toByteString();
blockWriter.write(header.getType(), null, blockData.getCompression(), message);
} else if (type.equals(Constants.BLOCK_TYPE_HEADER)) {
blockWriter.write(header.getType(), null, blob);
}
} catch (EOFException eof) {
break;
}
}
output.close();
}
use of de.topobyte.osm4j.pbf.util.BlockData in project osm4j-pbf by topobyte.
the class EntitySplit method data.
private void data(Fileformat.Blob blob) throws IOException {
BlockData blockData = PbfUtil.getBlockData(blob);
Osmformat.PrimitiveBlock primBlock = Osmformat.PrimitiveBlock.parseFrom(blockData.getBlobData());
if (!PbfMeta.hasMixedContent(primBlock)) {
// If the block does not contain multiple entity types, we can copy
// the blob without have to recreate the message.
EntityType type = PbfMeta.getContentTypes(primBlock).iterator().next();
if (type == EntityType.Node && copyNodes) {
blockWriterNodes.write(Constants.BLOCK_TYPE_DATA, null, blob);
} else if (type == EntityType.Way && copyWays) {
blockWriterWays.write(Constants.BLOCK_TYPE_DATA, null, blob);
} else if (type == EntityType.Relation && copyRelations) {
blockWriterRelations.write(Constants.BLOCK_TYPE_DATA, null, blob);
}
} else {
// Multiple entity types in the block. Extract types and write to
// appropriate output.
EntityGroups groups = EntityGroups.splitEntities(primBlock);
Compression compression = blockData.getCompression();
if (copyNodes && groups.getNodeGroups().size() > 0) {
copy(blockWriterNodes, groups.getNodeGroups(), primBlock, compression);
}
if (copyWays && groups.getWayGroups().size() > 0) {
copy(blockWriterWays, groups.getWayGroups(), primBlock, compression);
}
if (copyRelations && groups.getRelationGroups().size() > 0) {
copy(blockWriterRelations, groups.getRelationGroups(), primBlock, compression);
}
}
}
use of de.topobyte.osm4j.pbf.util.BlockData in project osm4j-pbf by topobyte.
the class Uncompress method main.
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.out.println("usage: " + Uncompress.class.getSimpleName() + " <input> <output>");
System.exit(1);
}
InputStream input = new FileInputStream(args[0]);
OutputStream output = new FileOutputStream(args[1]);
DataInputStream data = new DataInputStream(input);
BlockWriter blockWriter = new BlockWriter(output);
while (true) {
try {
BlobHeader header = PbfUtil.parseHeader(data);
Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
BlockData blockData = PbfUtil.getBlockData(blob);
blockWriter.write(header.getType(), null, Compression.NONE, blockData.getBlobData());
} catch (EOFException eof) {
break;
}
}
output.close();
}
use of de.topobyte.osm4j.pbf.util.BlockData in project osm4j-pbf by topobyte.
the class CompressDeflate method main.
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.out.println("usage: " + CompressDeflate.class.getSimpleName() + " <input> <output>");
System.exit(1);
}
InputStream input = new FileInputStream(args[0]);
OutputStream output = new FileOutputStream(args[1]);
DataInputStream data = new DataInputStream(input);
BlockWriter blockWriter = new BlockWriter(output);
while (true) {
try {
BlobHeader header = PbfUtil.parseHeader(data);
Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
BlockData blockData = PbfUtil.getBlockData(blob);
blockWriter.write(header.getType(), null, Compression.DEFLATE, blockData.getBlobData());
} catch (EOFException eof) {
break;
}
}
output.close();
}
use of de.topobyte.osm4j.pbf.util.BlockData in project osm4j-pbf by topobyte.
the class CompressLz4 method main.
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.out.println("usage: " + CompressLz4.class.getSimpleName() + " <input> <output>");
System.exit(1);
}
InputStream input = new FileInputStream(args[0]);
OutputStream output = new FileOutputStream(args[1]);
DataInputStream data = new DataInputStream(input);
BlockWriter blockWriter = new BlockWriter(output);
while (true) {
try {
BlobHeader header = PbfUtil.parseHeader(data);
Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
BlockData blockData = PbfUtil.getBlockData(blob);
blockWriter.write(header.getType(), null, Compression.LZ4, blockData.getBlobData());
} catch (EOFException eof) {
break;
}
}
output.close();
}
Aggregations