use of org.locationtech.geogig.osm.internal.history.Changeset in project GeoGig by boundlessgeo.
the class OSMHistoryImport method importOsmHistory.
private void importOsmHistory(GeogigCLI cli, ConsoleReader console, HistoryDownloader downloader, @Nullable Envelope featureFilter) throws IOException {
Iterator<Changeset> changesets = downloader.fetchChangesets();
GeoGIG geogig = cli.getGeogig();
WorkingTree workingTree = geogig.getContext().workingTree();
while (changesets.hasNext()) {
Changeset changeset = changesets.next();
if (changeset.isOpen()) {
throw new CommandFailedException("Can't import past changeset " + changeset.getId() + " as it is still open.");
}
String desc = String.format("obtaining osm changeset %,d...", changeset.getId());
console.print(desc);
console.flush();
Optional<Iterator<Change>> opchanges = changeset.getChanges().get();
if (!opchanges.isPresent()) {
updateBranchChangeset(geogig, changeset.getId());
console.println(" does not apply.");
console.flush();
continue;
}
Iterator<Change> changes = opchanges.get();
console.print("applying...");
console.flush();
ObjectId workTreeId = workingTree.getTree().getId();
long changeCount = insertChanges(cli, changes, featureFilter);
console.print(String.format("Applied %,d changes, staging...", changeCount));
console.flush();
ObjectId afterTreeId = workingTree.getTree().getId();
DiffObjectCount diffCount = geogig.command(DiffCount.class).setOldVersion(workTreeId.toString()).setNewVersion(afterTreeId.toString()).call();
geogig.command(AddOp.class).call();
console.println(String.format("done. %,d changes actually applied.", diffCount.featureCount()));
console.flush();
commit(cli, changeset);
}
}
use of org.locationtech.geogig.osm.internal.history.Changeset in project GeoGig by boundlessgeo.
the class OSMHistoryImport method runInternal.
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
checkParameter(args.numThreads > 0 && args.numThreads < 7, "numthreads must be between 1 and 6");
ConsoleReader console = cli.getConsole();
final String osmAPIUrl = resolveAPIURL();
final long startIndex;
final long endIndex = args.endIndex;
if (args.resume) {
GeoGIG geogig = cli.getGeogig();
long lastChangeset = getCurrentBranchChangeset(geogig);
startIndex = 1 + lastChangeset;
} else {
startIndex = args.startIndex;
}
console.println(String.format("Obtaining OSM changesets %,d to %,d from %s", startIndex, args.endIndex, osmAPIUrl));
final ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("osm-history-fetch-thread-%d").build();
final ExecutorService executor = Executors.newFixedThreadPool(args.numThreads, threadFactory);
final File targetDir = resolveTargetDir();
console.println("Downloading to " + targetDir.getAbsolutePath());
console.flush();
HistoryDownloader downloader;
downloader = new HistoryDownloader(osmAPIUrl, targetDir, startIndex, endIndex, executor);
Envelope env = parseBbox();
Predicate<Changeset> filter = parseFilter(env);
downloader.setChangesetFilter(filter);
try {
importOsmHistory(cli, console, downloader, env);
} finally {
executor.shutdownNow();
try {
executor.awaitTermination(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new CommandFailedException(e);
}
}
}
Aggregations