Search in sources :

Example 1 with XmlChangeReader

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;
}
Also used : SubProgressListener(org.locationtech.geogig.api.SubProgressListener) LineString(com.vividsolutions.jts.geom.LineString) Feature(org.opengis.feature.Feature) Point(com.vividsolutions.jts.geom.Point) WorkingTree(org.locationtech.geogig.repository.WorkingTree) Function(com.google.common.base.Function) ProgressListener(org.locationtech.geogig.api.ProgressListener) SubProgressListener(org.locationtech.geogig.api.SubProgressListener) XmlChangeReader(org.openstreetmap.osmosis.xml.v0_6.XmlChangeReader) TimeUnit(java.util.concurrent.TimeUnit)

Aggregations

Function (com.google.common.base.Function)1 LineString (com.vividsolutions.jts.geom.LineString)1 Point (com.vividsolutions.jts.geom.Point)1 TimeUnit (java.util.concurrent.TimeUnit)1 ProgressListener (org.locationtech.geogig.api.ProgressListener)1 SubProgressListener (org.locationtech.geogig.api.SubProgressListener)1 WorkingTree (org.locationtech.geogig.repository.WorkingTree)1 Feature (org.opengis.feature.Feature)1 XmlChangeReader (org.openstreetmap.osmosis.xml.v0_6.XmlChangeReader)1