use of de.topobyte.osm4j.pbf.util.BlobHeader in project osm4j-pbf by topobyte.
the class BlobParser method parseBlob.
private void parseBlob(DataInput data) throws IOException {
BlobHeader header = PbfUtil.parseHeader(data);
Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
parse(header, blob);
}
use of de.topobyte.osm4j.pbf.util.BlobHeader in project osm4j-pbf by topobyte.
the class CountBlocks method main.
public static void main(String[] args) throws IOException {
if (args.length != 1) {
System.out.println("usage: " + CountBlocks.class.getSimpleName() + " <filename>");
System.exit(1);
}
InputStream input = new FileInputStream(args[0]);
DataInputStream data = new DataInputStream(input);
long nBlocks = 0;
while (true) {
try {
BlobHeader blockHeader = PbfUtil.parseHeader(data);
input.skip(blockHeader.getDataLength());
nBlocks++;
} catch (EOFException eof) {
break;
}
}
System.out.println("Number of blocks: " + nBlocks);
}
use of de.topobyte.osm4j.pbf.util.BlobHeader in project osm4j-pbf by topobyte.
the class EntitySplit method execute.
public void execute() throws IOException {
while (true) {
try {
BlobHeader header = PbfUtil.parseHeader(input);
Fileformat.Blob blob = PbfUtil.parseBlock(input, header.getDataLength());
String type = header.getType();
// requested types
if (type.equals(Constants.BLOCK_TYPE_DATA)) {
data(blob);
} else if (type.equals(Constants.BLOCK_TYPE_HEADER)) {
if (copyNodes) {
blockWriterNodes.write(header.getType(), null, blob);
}
if (copyWays) {
blockWriterWays.write(header.getType(), null, blob);
}
if (copyRelations) {
blockWriterRelations.write(header.getType(), null, blob);
}
}
} catch (EOFException eof) {
break;
}
}
if (copyNodes) {
outNodes.close();
}
if (copyWays) {
outWays.close();
}
if (copyRelations) {
outRelations.close();
}
}
use of de.topobyte.osm4j.pbf.util.BlobHeader in project osm4j-pbf by topobyte.
the class HeaderInfo method main.
public static void main(String[] args) throws IOException {
if (args.length != 1) {
System.out.println("usage: " + HeaderInfo.class.getSimpleName() + " <filename>");
System.exit(1);
}
InputStream input = new FileInputStream(args[0]);
DataInputStream data = new DataInputStream(input);
boolean passedFirst = false;
boolean warningShown = false;
while (true) {
if (passedFirst && !warningShown) {
System.out.println("Warning: first block is not a header!");
System.out.println("... will continue reading until I find one.");
warningShown = true;
}
try {
BlobHeader header = PbfUtil.parseHeader(data);
Fileformat.Blob blob = PbfUtil.parseBlock(data, header.getDataLength());
BlockData blockData = PbfUtil.getBlockData(blob);
String type = header.getType();
passedFirst = true;
if (type.equals(Constants.BLOCK_TYPE_HEADER)) {
Osmformat.HeaderBlock headerBlock = Osmformat.HeaderBlock.parseFrom(blockData.getBlobData());
printHeaderInfo(headerBlock);
return;
}
} catch (EOFException eof) {
if (!passedFirst) {
System.out.println("End of file before header");
}
break;
}
}
}
use of de.topobyte.osm4j.pbf.util.BlobHeader in project osm4j-pbf by topobyte.
the class PbfIterator method advanceBlock.
private void advanceBlock() throws IOException {
BlobHeader header = PbfUtil.parseHeader(input);
Fileformat.Blob blob = PbfUtil.parseBlock(input, header.getDataLength());
BlockData blockData = PbfUtil.getBlockData(blob);
String type = header.getType();
if (type.equals(Constants.BLOCK_TYPE_DATA)) {
beyondBounds = true;
Osmformat.PrimitiveBlock block = Osmformat.PrimitiveBlock.parseFrom(blockData.getBlobData());
PrimParser primParser = new PrimParser(block, fetchMetadata);
for (Osmformat.PrimitiveGroup group : block.getPrimitivegroupList()) {
if (group.getNodesCount() > 0) {
pushNodes(primParser, group.getNodesList());
}
if (group.hasDense()) {
pushNodes(primParser, group.getDense());
}
if (group.getWaysCount() > 0) {
pushWays(primParser, group.getWaysList());
}
if (group.getRelationsCount() > 0) {
pushRelations(primParser, group.getRelationsList());
}
}
} else if (type.equals(Constants.BLOCK_TYPE_HEADER)) {
Osmformat.HeaderBlock block = Osmformat.HeaderBlock.parseFrom(blockData.getBlobData());
HeaderBBox bbox = block.getBbox();
if (bbox != null && !beyondBounds) {
this.bounds = PbfUtil.bounds(bbox);
}
beyondBounds = true;
} else {
throw new IOException("invalid PBF block");
}
}
Aggregations