Search in sources :

Example 1 with FileStructure

use of de.topobyte.osm4j.pbf.raf.FileStructure in project osm4j-pbf by topobyte.

the class EntitySplitBlockwise method execute.

public void execute() throws IOException {
    FileStructure structure = FileStructureAnalyzer.analyze(pbfFile);
    Interval nodes = structure.getBlocksNodes();
    Interval ways = structure.getBlocksWays();
    Interval relations = structure.getBlocksRelations();
    print("nodes", nodes);
    print("ways", ways);
    print("relations", relations);
    // Flag whether the last node block contains also ways or relations
    boolean lastNodeBlockMixed = false;
    // Flag whether the last way block contains also relations
    boolean lastWayBlockMixed = false;
    // Flag whether the first way block contains also nodes
    boolean firstWayBlockMixed = false;
    // Flag whether the first relation block contains also nodes or ways
    boolean firstRelationBlockMixed = false;
    if (nodes != null && ways != null) {
        lastNodeBlockMixed |= nodes.getEnd() == ways.getStart();
        firstWayBlockMixed |= nodes.getEnd() == ways.getStart();
    }
    if (nodes != null && relations != null) {
        lastNodeBlockMixed |= nodes.getEnd() == relations.getStart();
        firstRelationBlockMixed |= nodes.getEnd() == relations.getStart();
    }
    if (ways != null && relations != null) {
        lastWayBlockMixed |= ways.getEnd() == relations.getStart();
        firstRelationBlockMixed |= ways.getEnd() == relations.getStart();
    }
    System.out.println("Last node block mixed? " + lastNodeBlockMixed);
    System.out.println("First way block mixed? " + firstWayBlockMixed);
    System.out.println("Last way block mixed? " + lastWayBlockMixed);
    System.out.println("First relation block mixed? " + firstRelationBlockMixed);
    if (copyNodes) {
        writeHeader(blockWriterNodes);
        copyNodes(nodes, lastNodeBlockMixed);
        outNodes.close();
    }
    if (copyWays) {
        writeHeader(blockWriterWays);
        copyWays(ways, firstWayBlockMixed, lastWayBlockMixed);
        outWays.close();
    }
    if (copyRelations) {
        writeHeader(blockWriterRelations);
        copyRelations(relations, firstRelationBlockMixed);
        outRelations.close();
    }
}
Also used : FileStructure(de.topobyte.osm4j.pbf.raf.FileStructure) Interval(de.topobyte.osm4j.pbf.raf.Interval)

Example 2 with FileStructure

use of de.topobyte.osm4j.pbf.raf.FileStructure in project osm4j-pbf by topobyte.

the class FindEntityBlockIntervals method main.

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        System.out.println("usage: " + FindEntityBlockIntervals.class.getSimpleName() + " <filename>");
        System.exit(1);
    }
    File file = new File(args[0]);
    PbfFile pbfFile = new PbfFile(file);
    pbfFile.buildBlockIndex();
    FileStructure fileStructure = FileStructureAnalyzer.analyze(pbfFile);
    for (EntityType type : EntityType.values()) {
        if (!fileStructure.hasType(type)) {
            System.out.println(type + ": none");
        } else {
            Interval blocks = fileStructure.getBlocks(type);
            System.out.println(String.format(type + ": [%d, %d]", blocks.getStart(), blocks.getEnd()));
        }
    }
}
Also used : EntityType(de.topobyte.osm4j.core.model.iface.EntityType) FileStructure(de.topobyte.osm4j.pbf.raf.FileStructure) PbfFile(de.topobyte.osm4j.pbf.raf.PbfFile) PbfFile(de.topobyte.osm4j.pbf.raf.PbfFile) File(java.io.File) Interval(de.topobyte.osm4j.pbf.raf.Interval)

Aggregations

FileStructure (de.topobyte.osm4j.pbf.raf.FileStructure)2 Interval (de.topobyte.osm4j.pbf.raf.Interval)2 EntityType (de.topobyte.osm4j.core.model.iface.EntityType)1 PbfFile (de.topobyte.osm4j.pbf.raf.PbfFile)1 File (java.io.File)1