use of org.openstreetmap.osmosis.xml.v0_6.XmlChangeReader in project GeoGig by boundlessgeo.
the class OSMApplyDiffOp method parseDiffFileAndInsert.
public OSMReport parseDiffFileAndInsert() {
final WorkingTree workTree = workingTree();
final int queueCapacity = 100 * 1000;
final int timeout = 1;
final TimeUnit timeoutUnit = TimeUnit.SECONDS;
// With this iterator and the osm parsing happening on a separate thread, we follow a
// producer/consumer approach so that the osm parse thread produces features into the
// iterator's queue, and WorkingTree.insert consumes them on this thread
QueueIterator<Feature> target = new QueueIterator<Feature>(queueCapacity, timeout, timeoutUnit);
XmlChangeReader reader = new XmlChangeReader(file, true, resolveCompressionMethod(file));
ProgressListener progressListener = getProgressListener();
ConvertAndImportSink sink = new ConvertAndImportSink(target, context, workingTree(), platform(), new SubProgressListener(progressListener, 100));
reader.setChangeSink(sink);
Thread readerThread = new Thread(reader, "osm-diff-reader-thread");
readerThread.start();
// used to set the task status name, but report no progress so it does not interfere
// with the progress reported by the reader thread
SubProgressListener noProgressReportingListener = new SubProgressListener(progressListener, 0) {
@Override
public void setProgress(float progress) {
// no-op
}
};
Function<Feature, String> parentTreePathResolver = new Function<Feature, String>() {
@Override
public String apply(Feature input) {
return input.getType().getName().getLocalPart();
}
};
workTree.insert(parentTreePathResolver, target, noProgressReportingListener, null, null);
OSMReport report = new OSMReport(sink.getCount(), sink.getNodeCount(), sink.getWayCount(), sink.getUnprocessedCount(), sink.getLatestChangeset(), sink.getLatestTimestamp());
return report;
}
Aggregations