use of org.openstreetmap.osmosis.xml.v0_6.XmlWriter 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();
}
}
Aggregations