use of de.topobyte.osm4j.pbf.seq.BlockWriter 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.seq.BlockWriter 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.seq.BlockWriter 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.seq.BlockWriter 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();
}
use of de.topobyte.osm4j.pbf.seq.BlockWriter in project osm4j-pbf by topobyte.
the class CopyBlockwise method main.
public static void main(String[] args) throws IOException {
if (args.length != 2 && args.length != 3) {
System.out.println("usage: " + CopyBlockwise.class.getSimpleName() + " <input> <output> [<num blocks>]");
System.exit(1);
}
InputStream input = new FileInputStream(args[0]);
OutputStream output = new FileOutputStream(args[1]);
boolean nBlocksSpecified = false;
int nBlocks = 0;
if (args.length == 3) {
nBlocksSpecified = true;
nBlocks = Integer.parseInt(args[2]);
}
data = new DataInputStream(input);
blockWriter = new BlockWriter(output);
if (nBlocksSpecified) {
copyBlocks(nBlocks);
} else {
copyAllBlocks();
}
output.close();
}
Aggregations