Search in sources :

Example 1 with OsmosisSerializer

use of crosby.binary.osmosis.OsmosisSerializer in project GeoGig by boundlessgeo.

the class OSMExport method runInternal.

/**
     * Executes the export command using the provided options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    if (args.size() < 1 || args.size() > 2) {
        printUsage(cli);
        throw new CommandFailedException();
    }
    checkParameter(bbox == null || bbox.size() == 4, "The specified bounding box is not correct");
    geogig = cli.getGeogig();
    String osmfile = args.get(0);
    String ref = "WORK_HEAD";
    if (args.size() == 2) {
        ref = args.get(1);
        Optional<ObjectId> tree = geogig.command(ResolveTreeish.class).setTreeish(ref).call();
        checkParameter(tree.isPresent(), "Invalid commit or reference: %s", ref);
    }
    File file = new File(osmfile);
    checkParameter(!file.exists() || overwrite, "The selected file already exists. Use -o to overwrite");
    Iterator<EntityContainer> nodes = getFeatures(ref + ":node");
    Iterator<EntityContainer> ways = getFeatures(ref + ":way");
    Iterator<EntityContainer> iterator = Iterators.concat(nodes, ways);
    if (file.getName().endsWith(".pbf")) {
        BlockOutputStream output = new BlockOutputStream(new FileOutputStream(file));
        OsmosisSerializer serializer = new OsmosisSerializer(output);
        while (iterator.hasNext()) {
            EntityContainer entity = iterator.next();
            serializer.process(entity);
        }
        serializer.complete();
    } else {
        XmlWriter writer = new XmlWriter(file, CompressionMethod.None);
        while (iterator.hasNext()) {
            EntityContainer entity = iterator.next();
            writer.process(entity);
        }
        writer.complete();
    }
}
Also used : OsmosisSerializer(crosby.binary.osmosis.OsmosisSerializer) ObjectId(org.locationtech.geogig.api.ObjectId) FileOutputStream(java.io.FileOutputStream) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) BlockOutputStream(org.openstreetmap.osmosis.osmbinary.file.BlockOutputStream) File(java.io.File) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) XmlWriter(org.openstreetmap.osmosis.xml.v0_6.XmlWriter)

Aggregations

OsmosisSerializer (crosby.binary.osmosis.OsmosisSerializer)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ObjectId (org.locationtech.geogig.api.ObjectId)1 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)1 EntityContainer (org.openstreetmap.osmosis.core.container.v0_6.EntityContainer)1 BlockOutputStream (org.openstreetmap.osmosis.osmbinary.file.BlockOutputStream)1 XmlWriter (org.openstreetmap.osmosis.xml.v0_6.XmlWriter)1