use of de.topobyte.osm4j.pbf.util.BlockData in project osm4j-pbf by topobyte.
the class PbfFile method getHeaderBlock.
/*
* Data access
*/
public Osmformat.HeaderBlock getHeaderBlock() throws IOException {
Fileformat.Blob blob = getBlockBlob(headerBlockInfo);
BlockData blockData = PbfUtil.getBlockData(blob);
return Osmformat.HeaderBlock.parseFrom(blockData.getBlobData());
}
use of de.topobyte.osm4j.pbf.util.BlockData in project osm4j-pbf by topobyte.
the class PbfFile method getDataBlock.
public Osmformat.PrimitiveBlock getDataBlock(int i) throws IOException {
BlockInfo info = dataBlockInfos.get(i);
Fileformat.Blob blob = getBlockBlob(info);
BlockData blockData = PbfUtil.getBlockData(blob);
Osmformat.PrimitiveBlock primBlock = Osmformat.PrimitiveBlock.parseFrom(blockData.getBlobData());
return primBlock;
}
use of de.topobyte.osm4j.pbf.util.BlockData 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());
}
use of de.topobyte.osm4j.pbf.util.BlockData 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.BlockData in project osm4j-pbf by topobyte.
the class BlockParser method parse.
@Override
protected void parse(BlobHeader header, Fileformat.Blob blob) throws IOException {
BlockData blockData = PbfUtil.getBlockData(blob);
String type = header.getType();
if (type.equals(Constants.BLOCK_TYPE_DATA)) {
Osmformat.PrimitiveBlock primBlock = Osmformat.PrimitiveBlock.parseFrom(blockData.getBlobData());
parse(primBlock);
} else if (type.equals(Constants.BLOCK_TYPE_HEADER)) {
Osmformat.HeaderBlock headerBlock = Osmformat.HeaderBlock.parseFrom(blockData.getBlobData());
parse(headerBlock);
} else {
throw new IOException("invalid PBF block");
}
}
Aggregations