Search in sources :

Example 6 with BoundingBox

use of org.opengis.geometry.BoundingBox in project GeoGig by boundlessgeo.

the class DiffBoundsTest method testPathFiltering.

private void testPathFiltering(String oldVersion, String newVersion, @Nullable BoundingBox expected, @Nullable String... pathFilters) {
    List<String> filter = ImmutableList.<String>copyOf(pathFilters);
    CoordinateReferenceSystem crs = DEFAULT_CRS;
    if (expected != null) {
        crs = expected.getCoordinateReferenceSystem();
    }
    DiffSummary<BoundingBox, BoundingBox> result = //
    geogig.command(DiffBounds.class).setOldVersion(//
    oldVersion).setNewVersion(//
    newVersion).setPathFilters(//
    filter).setCRS(//
    crs).call();
    BoundingBox actual = result.getMergedResult().get();
    if (null == expected) {
        assertTrue(actual.isEmpty());
    } else {
        assertEquals(expected, actual);
    }
}
Also used : BoundingBox(org.opengis.geometry.BoundingBox) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 7 with BoundingBox

use of org.opengis.geometry.BoundingBox in project GeoGig by boundlessgeo.

the class RemoteRepositoryTestCase method boundsOf.

/**
     * Computes the aggregated bounds of {@code features} in the {@code targetCrs}
     */
protected ReferencedEnvelope boundsOf(CoordinateReferenceSystem targetCrs, Feature... features) throws Exception {
    ReferencedEnvelope bounds = new ReferencedEnvelope(targetCrs);
    for (int i = 0; i < features.length; i++) {
        Feature f = features[i];
        BoundingBox fbounds = f.getBounds();
        if (!CRS.equalsIgnoreMetadata(targetCrs, fbounds)) {
            fbounds = fbounds.toBounds(targetCrs);
        }
        bounds.include(fbounds);
    }
    return bounds;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) BoundingBox(org.opengis.geometry.BoundingBox) Feature(org.opengis.feature.Feature)

Example 8 with BoundingBox

use of org.opengis.geometry.BoundingBox in project GeoGig by boundlessgeo.

the class Diff method runInternal.

/**
     * Executes the diff command with the specified options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(refSpec.size() <= 2, "Commit list is too long :%s", refSpec);
    checkParameter(!(nogeom && summary), "Only one printing mode allowed");
    checkParameter(!(bounds && count), "Only one of --bounds or --count is allowed");
    checkParameter(!(cached && refSpec.size() > 1), "--cached allows zero or one ref specs to compare the index with.");
    GeoGIG geogig = cli.getGeogig();
    String oldVersion = resolveOldVersion();
    String newVersion = resolveNewVersion();
    List<String> paths = removeEmptyPaths();
    if (bounds) {
        DiffBounds diff = geogig.command(DiffBounds.class).setOldVersion(oldVersion).setNewVersion(newVersion).setCompareIndex(cached);
        diff.setPathFilters(paths);
        CoordinateReferenceSystem crs = parseCrs();
        if (crs != null) {
            diff.setCRS(crs);
        }
        DiffSummary<BoundingBox, BoundingBox> diffBounds = diff.call();
        BoundsDiffPrinter.print(geogig, cli.getConsole(), diffBounds);
        return;
    }
    if (count) {
        if (oldVersion == null) {
            oldVersion = Ref.HEAD;
        }
        if (newVersion == null) {
            newVersion = cached ? Ref.STAGE_HEAD : Ref.WORK_HEAD;
        }
        DiffCount cdiff = geogig.command(DiffCount.class).setOldVersion(oldVersion).setNewVersion(newVersion);
        cdiff.setFilter(paths);
        DiffObjectCount count = cdiff.call();
        ConsoleReader console = cli.getConsole();
        console.println(String.format("Trees changed: %d, features changed: %,d", count.treeCount(), count.featureCount()));
        console.flush();
        return;
    }
    DiffOp diff = geogig.command(DiffOp.class);
    diff.setOldVersion(oldVersion).setNewVersion(newVersion).setCompareIndex(cached);
    Iterator<DiffEntry> entries;
    if (paths.isEmpty()) {
        entries = diff.setProgressListener(cli.getProgressListener()).call();
    } else {
        entries = Iterators.emptyIterator();
        for (String path : paths) {
            Iterator<DiffEntry> moreEntries = diff.setFilter(path).setProgressListener(cli.getProgressListener()).call();
            entries = Iterators.concat(entries, moreEntries);
        }
    }
    if (!entries.hasNext()) {
        cli.getConsole().println("No differences found");
        return;
    }
    DiffPrinter printer;
    if (summary) {
        printer = new SummaryDiffPrinter();
    } else {
        printer = new FullDiffPrinter(nogeom, false);
    }
    DiffEntry entry;
    while (entries.hasNext()) {
        entry = entries.next();
        printer.print(geogig, cli.getConsole(), entry);
    }
}
Also used : DiffBounds(org.locationtech.geogig.api.plumbing.DiffBounds) ConsoleReader(jline.console.ConsoleReader) DiffOp(org.locationtech.geogig.api.porcelain.DiffOp) DiffObjectCount(org.locationtech.geogig.api.plumbing.diff.DiffObjectCount) BoundingBox(org.opengis.geometry.BoundingBox) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) DiffCount(org.locationtech.geogig.api.plumbing.DiffCount) GeoGIG(org.locationtech.geogig.api.GeoGIG) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 9 with BoundingBox

use of org.opengis.geometry.BoundingBox in project GeoGig by boundlessgeo.

the class RepositoryTestCase method boundsOf.

/**
     * Computes the aggregated bounds of {@code features} in the {@code targetCrs}
     */
public ReferencedEnvelope boundsOf(CoordinateReferenceSystem targetCrs, Feature... features) throws Exception {
    ReferencedEnvelope bounds = new ReferencedEnvelope(targetCrs);
    for (int i = 0; i < features.length; i++) {
        Feature f = features[i];
        BoundingBox fbounds = f.getBounds();
        if (!CRS.equalsIgnoreMetadata(targetCrs, fbounds)) {
            fbounds = fbounds.toBounds(targetCrs);
        }
        bounds.include(fbounds);
    }
    return bounds;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) BoundingBox(org.opengis.geometry.BoundingBox) Feature(org.opengis.feature.Feature)

Example 10 with BoundingBox

use of org.opengis.geometry.BoundingBox in project GeoGig by boundlessgeo.

the class DiffBounds method _call.

@Override
protected DiffSummary<BoundingBox, BoundingBox> _call() {
    checkArgument(cached && oldVersion == null || !cached, String.format("compare index allows only one revision to check against, got %s / %s", oldVersion, newVersion));
    checkArgument(newVersion == null || oldVersion != null, "If new rev spec is specified then old rev spec is mandatory");
    final String leftRefSpec = fromNullable(oldVersion).or(Ref.HEAD);
    final String rightRefSpec = fromNullable(newVersion).or(cached ? Ref.STAGE_HEAD : Ref.WORK_HEAD);
    RevTree left = resolveTree(leftRefSpec);
    RevTree right = resolveTree(rightRefSpec);
    ObjectDatabase leftSource = resolveSafeDb(leftRefSpec);
    ObjectDatabase rightSource = resolveSafeDb(rightRefSpec);
    PreOrderDiffWalk visitor = new PreOrderDiffWalk(left, right, leftSource, rightSource);
    CoordinateReferenceSystem crs = resolveCrs();
    BoundsWalk walk = new BoundsWalk(crs, stagingDatabase());
    PreOrderDiffWalk.Consumer consumer = walk;
    if (!pathFilters.isEmpty()) {
        consumer = new PathFilteringDiffConsumer(pathFilters, walk);
    }
    visitor.walk(consumer);
    DiffSummary<BoundingBox, BoundingBox> diffBounds = walk.getResult();
    return diffBounds;
}
Also used : ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) BoundingBox(org.opengis.geometry.BoundingBox) PreOrderDiffWalk(org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevTree(org.locationtech.geogig.api.RevTree) PathFilteringDiffConsumer(org.locationtech.geogig.api.plumbing.diff.PathFilteringDiffConsumer)

Aggregations

BoundingBox (org.opengis.geometry.BoundingBox)11 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)6 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)5 Test (org.junit.Test)4 Feature (org.opengis.feature.Feature)2 Optional (com.google.common.base.Optional)1 Envelope (com.vividsolutions.jts.geom.Envelope)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 Point (com.vividsolutions.jts.geom.Point)1 ConsoleReader (jline.console.ConsoleReader)1 DefaultProgressListener (org.locationtech.geogig.api.DefaultProgressListener)1 GeoGIG (org.locationtech.geogig.api.GeoGIG)1 Node (org.locationtech.geogig.api.Node)1 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)1 RevTree (org.locationtech.geogig.api.RevTree)1 DiffBounds (org.locationtech.geogig.api.plumbing.DiffBounds)1 DiffCount (org.locationtech.geogig.api.plumbing.DiffCount)1 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)1 DiffObjectCount (org.locationtech.geogig.api.plumbing.diff.DiffObjectCount)1 PathFilteringDiffConsumer (org.locationtech.geogig.api.plumbing.diff.PathFilteringDiffConsumer)1