Search in sources :

Example 1 with PbfFile

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

the class EntitySplitBlockwise method main.

public static void main(String[] args) throws IOException {
    // @formatter:off
    Options options = new Options();
    OptionHelper.addL(options, OPTION_INPUT, true, true, "input file");
    OptionHelper.addL(options, OPTION_OUTPUT_NODES, true, false, "the file to write nodes to");
    OptionHelper.addL(options, OPTION_OUTPUT_WAYS, true, false, "the file to write ways to");
    OptionHelper.addL(options, OPTION_OUTPUT_RELATIONS, true, false, "the file to write relations to");
    // @formatter:on
    CommandLine line = null;
    try {
        line = new DefaultParser().parse(options, args);
    } catch (ParseException e) {
        System.out.println("unable to parse command line: " + e.getMessage());
        new HelpFormatter().printHelp(HELP_MESSAGE, options);
        System.exit(1);
    }
    if (line == null) {
        return;
    }
    String inputPath = line.getOptionValue(OPTION_INPUT);
    File file = new File(inputPath);
    PbfFile pbfFile = new PbfFile(file);
    OutputStream outNodes = null, outWays = null, outRelations = null;
    if (line.hasOption(OPTION_OUTPUT_NODES)) {
        String path = line.getOptionValue(OPTION_OUTPUT_NODES);
        FileOutputStream fos = new FileOutputStream(path);
        outNodes = new BufferedOutputStream(fos);
    }
    if (line.hasOption(OPTION_OUTPUT_WAYS)) {
        String path = line.getOptionValue(OPTION_OUTPUT_WAYS);
        FileOutputStream fos = new FileOutputStream(path);
        outWays = new BufferedOutputStream(fos);
    }
    if (line.hasOption(OPTION_OUTPUT_RELATIONS)) {
        String path = line.getOptionValue(OPTION_OUTPUT_RELATIONS);
        FileOutputStream fos = new FileOutputStream(path);
        outRelations = new BufferedOutputStream(fos);
    }
    if (outNodes == null && outWays == null && outRelations == null) {
        System.out.println("You should specify an output for at least one entity");
        System.exit(1);
    }
    EntitySplitBlockwise task = new EntitySplitBlockwise(pbfFile, outNodes, outWays, outRelations);
    task.execute();
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ParseException(org.apache.commons.cli.ParseException) ByteString(com.google.protobuf.ByteString) PbfFile(de.topobyte.osm4j.pbf.raf.PbfFile) PbfFile(de.topobyte.osm4j.pbf.raf.PbfFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 2 with PbfFile

use of de.topobyte.osm4j.pbf.raf.PbfFile 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

PbfFile (de.topobyte.osm4j.pbf.raf.PbfFile)2 File (java.io.File)2 ByteString (com.google.protobuf.ByteString)1 EntityType (de.topobyte.osm4j.core.model.iface.EntityType)1 FileStructure (de.topobyte.osm4j.pbf.raf.FileStructure)1 Interval (de.topobyte.osm4j.pbf.raf.Interval)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 CommandLine (org.apache.commons.cli.CommandLine)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1