use of org.locationtech.geogig.osm.internal.OSMReport in project GeoGig by boundlessgeo.
the class OSMReportRepresentation method writeResultBody.
@Override
protected void writeResultBody(XMLStreamWriter w, Optional<OSMReport> result) throws XMLStreamException {
if (result.isPresent()) {
OSMReport report = result.get();
long latestChangeset = report.getLatestChangeset();
long latestTimestamp = report.getLatestTimestamp();
long processedEntities = report.getCount();
long nodeCount = report.getNodeCount();
long wayCount = report.getWayCount();
long unpprocessedCount = report.getUnpprocessedCount();
w.writeStartElement("OSMReport");
element(w, "latestChangeset", latestChangeset);
element(w, "latestTimestamp", latestTimestamp);
element(w, "processedEntities", processedEntities);
element(w, "nodeCount", nodeCount);
element(w, "wayCount", wayCount);
element(w, "unpprocessedCount", unpprocessedCount);
w.writeEndElement();
}
}
use of org.locationtech.geogig.osm.internal.OSMReport in project GeoGig by boundlessgeo.
the class OSMApplyDiff method runInternal.
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
checkParameter(diffFilepath != null && diffFilepath.size() == 1, "One file must be specified");
File diffFile = new File(diffFilepath.get(0));
checkParameter(diffFile.exists(), "The specified OSM diff file does not exist");
try {
Optional<OSMReport> report = cli.getGeogig().command(OSMApplyDiffOp.class).setDiffFile(diffFile).setProgressListener(cli.getProgressListener()).call();
if (report.isPresent()) {
OSMReport rep = report.get();
String msg;
if (rep.getUnpprocessedCount() > 0) {
msg = String.format("\nSome diffs from the specified file were not applied.\n" + "Processed entities: %,d.\n %,d.\nNodes: %,d.\nWays: %,d.\n Elements not applied:", rep.getCount(), rep.getUnpprocessedCount(), rep.getNodeCount(), rep.getWayCount());
} else {
msg = String.format("\nProcessed entities: %,d.\n Nodes: %,d.\n Ways: %,d\n", rep.getCount(), rep.getNodeCount(), rep.getWayCount());
}
cli.getConsole().println(msg);
}
} catch (RuntimeException e) {
throw new CommandFailedException("Error importing OSM data: " + e.getMessage(), e);
}
}
use of org.locationtech.geogig.osm.internal.OSMReport in project GeoGig by boundlessgeo.
the class OSMImport method runInternal.
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
checkParameter(apiUrl != null && apiUrl.size() == 1, "One file must be specified");
File importFile = new File(apiUrl.get(0));
checkParameter(importFile.exists(), "The specified OSM data file does not exist");
checkParameter(!(message != null && noRaw), "cannot use --message if using --no-raw");
checkParameter(message == null || mappingFile != null, "Cannot use --message if not using --mapping");
Mapping mapping = null;
if (mappingFile != null) {
mapping = Mapping.fromFile(mappingFile);
}
try {
message = message == null ? "Updated OSM data" : message;
Optional<OSMReport> report = cli.getGeogig().command(OSMImportOp.class).setDataSource(importFile.getAbsolutePath()).setMapping(mapping).setMessage(message).setNoRaw(noRaw).setAdd(add).setProgressListener(cli.getProgressListener()).call();
if (report.isPresent()) {
OSMReport rep = report.get();
String msg;
if (rep.getUnpprocessedCount() > 0) {
msg = String.format("\nSome elements returned by the specified filter could not be processed.\n" + "Processed entities: %,d.\nWrong or uncomplete elements: %,d.\nNodes: %,d.\nWays: %,d.\n", rep.getCount(), rep.getUnpprocessedCount(), rep.getNodeCount(), rep.getWayCount());
} else {
msg = String.format("\nProcessed entities: %,d.\n Nodes: %,d.\n Ways: %,d\n", rep.getCount(), rep.getNodeCount(), rep.getWayCount());
}
cli.getConsole().println(msg);
}
} catch (EmptyOSMDownloadException e) {
throw new IllegalArgumentException("The specified filter did not contain any valid element.\n" + "No changes were made to the repository.\n");
} catch (RuntimeException e) {
throw new CommandFailedException("Error importing OSM data: " + e.getMessage(), e);
}
}
use of org.locationtech.geogig.osm.internal.OSMReport in project GeoGig by boundlessgeo.
the class OSMDownload method runInternal.
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
checkParameter(filterFile != null ^ bbox != null || update, "You must specify a filter file or a bounding box");
checkParameter((filterFile != null || bbox != null) ^ update, "Filters cannot be used when updating");
GeoGIG geogig = cli.getGeogig();
checkState(geogig.getRepository().index().isClean() && geogig.getRepository().workingTree().isClean(), "Working tree and index are not clean");
checkParameter(!rebase || update, "--rebase switch can only be used when updating");
checkParameter(filterFile == null || filterFile.exists(), "The specified filter file does not exist");
checkParameter(bbox == null || bbox.size() == 4, "The specified bounding box is not correct");
osmAPIUrl = resolveAPIURL();
Optional<OSMReport> report;
GeogigTransaction tx = geogig.command(TransactionBegin.class).call();
try {
AbstractGeoGigOp<Optional<OSMReport>> cmd;
if (update) {
cmd = tx.command(OSMUpdateOp.class).setAPIUrl(osmAPIUrl).setRebase(rebase).setMessage(message).setProgressListener(cli.getProgressListener());
} else {
cmd = tx.command(OSMDownloadOp.class).setBbox(bbox).setFilterFile(filterFile).setKeepFiles(keepFiles).setMessage(message).setMappingFile(mappingFile).setOsmAPIUrl(osmAPIUrl).setSaveFile(saveFile).setProgressListener(cli.getProgressListener());
}
report = cmd.call();
tx.commit();
} catch (RuntimeException e) {
tx.abort();
if (e instanceof NothingToCommitException) {
throw new CommandFailedException(e.getMessage(), e);
}
throw e;
}
if (report.isPresent()) {
OSMReport rep = report.get();
String msg;
if (rep.getUnpprocessedCount() > 0) {
msg = String.format("\nSome elements returned by the specified filter could not be processed.\n" + "Processed entities: %,d.\nWrong or uncomplete elements: %,d.\nNodes: %,d.\nWays: %,d.\n", rep.getCount(), rep.getUnpprocessedCount(), rep.getNodeCount(), rep.getWayCount());
} else {
msg = String.format("\nProcessed entities: %,d.\n Nodes: %,d.\n Ways: %,d\n", rep.getCount(), rep.getNodeCount(), rep.getWayCount());
}
cli.getConsole().println(msg);
}
}
Aggregations