Search in sources :

Example 6 with DiffEntry

use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.

the class DiffTreeTest method testBoundsFilteringReprojecting.

@Test
public void testBoundsFilteringReprojecting() throws Exception {
    ObjectDatabase db = geogit.getContext().objectDatabase();
    RevTree tree1 = tree(1000, db);
    RevTree tree2 = tree(50, db);
    RevTree root = createRoot(db, tree1, tree2);
    CoordinateReferenceSystem nativeCrs = revtype.type().getCoordinateReferenceSystem();
    CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:4326", true);
    ReferencedEnvelope nativeFilter = new ReferencedEnvelope(49.9, 51.1, 49.9, 51.1, nativeCrs);
    ReferencedEnvelope queryFilter = nativeFilter.transform(queryCrs, true);
    List<DiffEntry> diffs;
    diffTree.setOldTree(ObjectId.NULL).setNewTree(root.getId());
    diffTree.setBoundsFilter(queryFilter);
    diffs = ImmutableList.copyOf(diffTree.call());
    assertEquals(2, diffs.size());
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevTree(org.locationtech.geogig.api.RevTree) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 7 with DiffEntry

use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.

the class DiffTreeTest method testBoundsFiltering.

@Test
public void testBoundsFiltering() {
    ObjectDatabase db = geogit.getContext().objectDatabase();
    RevTree tree1 = tree(1000, db);
    RevTree tree2 = tree(50, db);
    RevTree root = createRoot(db, tree1, tree2);
    CoordinateReferenceSystem crs = revtype.type().getCoordinateReferenceSystem();
    ReferencedEnvelope filter;
    List<DiffEntry> diffs;
    diffTree.setOldTree(ObjectId.NULL).setNewTree(root.getId());
    filter = new ReferencedEnvelope(50, 51, 50, 51, crs);
    diffTree.setBoundsFilter(filter);
    diffs = ImmutableList.copyOf(diffTree.call());
    assertEquals(2, diffs.size());
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevTree(org.locationtech.geogig.api.RevTree) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 8 with DiffEntry

use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.

the class OSMHistoryImportTest method test.

@Test
public void test() throws Exception {
    cli.execute("config", "user.name", "Gabriel Roldan");
    cli.execute("config", "user.email", "groldan@boundlessgeo.com");
    cli.execute("osm", "import-history", fakeOsmApiUrl, "--to", "10");
    GeoGIG geogig = cli.getGeogig();
    List<DiffEntry> changes = ImmutableList.copyOf(geogig.command(DiffOp.class).setOldVersion("HEAD~2").setNewVersion("HEAD~1").call());
    assertEquals(1, changes.size());
    DiffEntry entry = changes.get(0);
    assertEquals(ChangeType.MODIFIED, entry.changeType());
    assertEquals("node/20", entry.getOldObject().path());
    assertEquals("node/20", entry.getNewObject().path());
    Optional<RevFeature> oldRevFeature = geogig.command(RevObjectParse.class).setObjectId(entry.getOldObject().objectId()).call(RevFeature.class);
    Optional<RevFeature> newRevFeature = geogig.command(RevObjectParse.class).setObjectId(entry.getNewObject().objectId()).call(RevFeature.class);
    assertTrue(oldRevFeature.isPresent());
    assertTrue(newRevFeature.isPresent());
    Optional<RevFeatureType> type = geogig.command(RevObjectParse.class).setObjectId(entry.getOldObject().getMetadataId()).call(RevFeatureType.class);
    assertTrue(type.isPresent());
    FeatureType featureType = type.get().type();
    CoordinateReferenceSystem expected = CRS.decode("EPSG:4326", true);
    CoordinateReferenceSystem actual = featureType.getCoordinateReferenceSystem();
    assertTrue(actual.toString(), CRS.equalsIgnoreMetadata(expected, actual));
}
Also used : FeatureType(org.opengis.feature.type.FeatureType) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevFeature(org.locationtech.geogig.api.RevFeature) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) GeoGIG(org.locationtech.geogig.api.GeoGIG) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 9 with DiffEntry

use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.

the class BlameOp method _call.

@Override
protected BlameReport _call() {
    String fullPath = (commit != null ? commit.toString() : Ref.HEAD) + ":" + path;
    Optional<ObjectId> id = command(RevParse.class).setRefSpec(fullPath).call();
    if (!id.isPresent()) {
        throw new BlameException(StatusCode.FEATURE_NOT_FOUND);
    }
    TYPE type = command(ResolveObjectType.class).setObjectId(id.get()).call();
    if (!type.equals(TYPE.FEATURE)) {
        throw new BlameException(StatusCode.PATH_NOT_FEATURE);
    }
    Optional<RevFeatureType> featureType = command(ResolveFeatureType.class).setRefSpec(path).call();
    BlameReport report = new BlameReport(featureType.get());
    Iterator<RevCommit> log = command(LogOp.class).addPath(path).setUntil(commit).call();
    RevCommit commit = log.next();
    RevObjectParse revObjectParse = command(RevObjectParse.class);
    DiffOp diffOp = command(DiffOp.class);
    DiffFeature diffFeature = command(DiffFeature.class);
    while (!report.isComplete()) {
        if (!log.hasNext()) {
            String refSpec = commit.getId().toString() + ":" + path;
            RevFeature feature = revObjectParse.setRefSpec(refSpec).call(RevFeature.class).get();
            report.setFirstVersion(feature, commit);
            break;
        }
        RevCommit commitB = log.next();
        Iterator<DiffEntry> diffs = diffOp.setNewVersion(commit.getId()).setOldVersion(commitB.getId()).setReportTrees(false).call();
        while (diffs.hasNext()) {
            DiffEntry diff = diffs.next();
            if (path.equals(diff.newPath())) {
                if (diff.isAdd()) {
                    String refSpec = commit.getId().toString() + ":" + path;
                    RevFeature feature = revObjectParse.setRefSpec(refSpec).call(RevFeature.class).get();
                    report.setFirstVersion(feature, commit);
                    break;
                }
                FeatureDiff featureDiff = diffFeature.setNewVersion(Suppliers.ofInstance(diff.getNewObject())).setOldVersion(Suppliers.ofInstance(diff.getOldObject())).call();
                Map<PropertyDescriptor, AttributeDiff> attribDiffs = featureDiff.getDiffs();
                Iterator<PropertyDescriptor> iter = attribDiffs.keySet().iterator();
                while (iter.hasNext()) {
                    PropertyDescriptor key = iter.next();
                    Optional<?> value = attribDiffs.get(key).getNewValue();
                    String attribute = key.getName().toString();
                    report.addDiff(attribute, value, commit);
                }
            }
        }
        commit = commitB;
    }
    return report;
}
Also used : PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) ObjectId(org.locationtech.geogig.api.ObjectId) DiffFeature(org.locationtech.geogig.api.plumbing.DiffFeature) FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) RevFeature(org.locationtech.geogig.api.RevFeature) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) TYPE(org.locationtech.geogig.api.RevObject.TYPE) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 10 with DiffEntry

use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.

the class DiffOp method _call.

/**
     * Executes the diff operation.
     * 
     * @return an iterator to a set of differences between the two trees
     * @see DiffEntry
     */
@Override
protected Iterator<DiffEntry> _call() {
    checkArgument(cached && oldRefSpec == null || !cached, String.format("compare index allows only one revision to check against, got %s / %s", oldRefSpec, newRefSpec));
    checkArgument(newRefSpec == null || oldRefSpec != null, "If new rev spec is specified then old rev spec is mandatory");
    Iterator<DiffEntry> iterator;
    if (cached) {
        // compare the tree-ish (default to HEAD) and the index
        DiffIndex diffIndex = command(DiffIndex.class).addFilter(this.pathFilter).setReportTrees(reportTrees);
        if (oldRefSpec != null) {
            diffIndex.setOldVersion(oldRefSpec);
        }
        iterator = diffIndex.call();
    } else if (newRefSpec == null) {
        DiffWorkTree workTreeIndexDiff = command(DiffWorkTree.class).setFilter(pathFilter).setReportTrees(reportTrees);
        if (oldRefSpec != null) {
            workTreeIndexDiff.setOldVersion(oldRefSpec);
        }
        iterator = workTreeIndexDiff.call();
    } else {
        iterator = command(DiffTree.class).setOldVersion(oldRefSpec).setNewVersion(newRefSpec).setPathFilter(pathFilter).setReportTrees(reportTrees).call();
    }
    return iterator;
}
Also used : DiffTree(org.locationtech.geogig.api.plumbing.DiffTree) DiffIndex(org.locationtech.geogig.api.plumbing.DiffIndex) DiffWorkTree(org.locationtech.geogig.api.plumbing.DiffWorkTree) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Aggregations

DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)83 ObjectId (org.locationtech.geogig.api.ObjectId)38 Test (org.junit.Test)31 RevCommit (org.locationtech.geogig.api.RevCommit)31 NodeRef (org.locationtech.geogig.api.NodeRef)24 DiffOp (org.locationtech.geogig.api.porcelain.DiffOp)17 RevFeature (org.locationtech.geogig.api.RevFeature)15 RevTree (org.locationtech.geogig.api.RevTree)15 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)14 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)14 RevObject (org.locationtech.geogig.api.RevObject)11 Patch (org.locationtech.geogig.api.plumbing.diff.Patch)11 Feature (org.opengis.feature.Feature)10 Optional (com.google.common.base.Optional)9 GeoGIG (org.locationtech.geogig.api.GeoGIG)8 Repository (org.locationtech.geogig.repository.Repository)8 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)8 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)8 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 IOException (java.io.IOException)5