Search in sources :

Example 36 with RevFeature

use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.

the class CommitOpTest method testAmend.

@Test
public void testAmend() throws Exception {
    final ObjectId id = insertAndAdd(points1);
    final RevCommit commit1 = geogig.command(CommitOp.class).setMessage("Message").call();
    {
        assertCommit(commit1, null, null, null);
        assertEquals(id, repo.getRootTreeChild(appendChild(pointsName, idP1)).get().getObjectId());
        assertNotNull(repo.objectDatabase().get(id));
    }
    final ObjectId id2 = insertAndAdd(points2);
    final RevCommit commit2 = geogig.command(CommitOp.class).setAmend(true).call();
    {
        assertCommit(commit2, null, "groldan", "Message");
        Optional<RevFeature> p2 = geogig.command(RevObjectParse.class).setRefSpec("HEAD:" + appendChild(pointsName, idP2)).call(RevFeature.class);
        assertTrue(p2.isPresent());
        assertEquals(id2, p2.get().getId());
        Optional<RevFeature> p1 = geogig.command(RevObjectParse.class).setRefSpec("HEAD:" + appendChild(pointsName, idP1)).call(RevFeature.class);
        assertTrue(p1.isPresent());
        assertEquals(id, p1.get().getId());
    }
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    assertTrue(log.hasNext());
    log.next();
    assertFalse(log.hasNext());
}
Also used : Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) LogOp(org.locationtech.geogig.api.porcelain.LogOp) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 37 with RevFeature

use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.

the class ExportOp method getFeatures.

private static Iterator<SimpleFeature> getFeatures(final RevTree typeTree, final ObjectDatabase database, final ObjectId defaultMetadataId, final ProgressListener progressListener) {
    Iterator<NodeRef> nodes = new DepthTreeIterator("", defaultMetadataId, typeTree, database, Strategy.FEATURES_ONLY);
    // progress reporting
    nodes = Iterators.transform(nodes, new Function<NodeRef, NodeRef>() {

        private AtomicInteger count = new AtomicInteger();

        @Override
        public NodeRef apply(NodeRef input) {
            progressListener.setProgress((count.incrementAndGet() * 100.f) / typeTree.size());
            return input;
        }
    });
    Function<NodeRef, SimpleFeature> asFeature = new Function<NodeRef, SimpleFeature>() {

        private Map<ObjectId, FeatureBuilder> ftCache = Maps.newHashMap();

        @Override
        @Nullable
        public SimpleFeature apply(final NodeRef input) {
            final ObjectId metadataId = input.getMetadataId();
            final RevFeature revFeature = database.getFeature(input.objectId());
            FeatureBuilder featureBuilder = getBuilderFor(metadataId);
            Feature feature = featureBuilder.build(input.name(), revFeature);
            feature.getUserData().put(Hints.USE_PROVIDED_FID, true);
            feature.getUserData().put(RevFeature.class, revFeature);
            feature.getUserData().put(RevFeatureType.class, featureBuilder.getType());
            if (feature instanceof SimpleFeature) {
                return (SimpleFeature) feature;
            }
            return null;
        }

        private FeatureBuilder getBuilderFor(final ObjectId metadataId) {
            FeatureBuilder featureBuilder = ftCache.get(metadataId);
            if (featureBuilder == null) {
                RevFeatureType revFtype = database.getFeatureType(metadataId);
                featureBuilder = new FeatureBuilder(revFtype);
                ftCache.put(metadataId, featureBuilder);
            }
            return featureBuilder;
        }
    };
    Iterator<SimpleFeature> asFeatures = Iterators.transform(nodes, asFeature);
    UnmodifiableIterator<SimpleFeature> filterNulls = Iterators.filter(asFeatures, Predicates.notNull());
    return filterNulls;
}
Also used : FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) ObjectId(org.locationtech.geogig.api.ObjectId) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) RevFeature(org.locationtech.geogig.api.RevFeature) SimpleFeature(org.opengis.feature.simple.SimpleFeature) NodeRef(org.locationtech.geogig.api.NodeRef) Function(com.google.common.base.Function) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RevFeature(org.locationtech.geogig.api.RevFeature) DepthTreeIterator(org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator) Map(java.util.Map) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 38 with RevFeature

use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.

the class RevFeatureBuilderTest method testBuildFull.

@Test
public void testBuildFull() throws Exception {
    RevFeature feature = RevFeatureBuilder.build(points1);
    ImmutableList<Optional<Object>> values = feature.getValues();
    assertEquals(values.size(), points1.getProperties().size());
    for (Property prop : points1.getProperties()) {
        assertTrue(values.contains(Optional.fromNullable(prop.getValue())));
    }
    RevFeature feature2 = RevFeatureBuilder.build(lines1);
    values = feature2.getValues();
    assertEquals(values.size(), lines1.getProperties().size());
    for (Property prop : lines1.getProperties()) {
        assertTrue(values.contains(Optional.fromNullable(prop.getValue())));
    }
}
Also used : Optional(com.google.common.base.Optional) RevFeature(org.locationtech.geogig.api.RevFeature) Property(org.opengis.feature.Property) Test(org.junit.Test)

Example 39 with RevFeature

use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.

the class ApplyPatchOpTest method testModifyFeatureAttributePatch.

@Test
public void testModifyFeatureAttributePatch() throws Exception {
    insert(points1);
    Patch patch = new Patch();
    String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
    Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
    Optional<?> oldValue = Optional.fromNullable(points1.getProperty("sp").getValue());
    GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, Optional.of("new"));
    map.put(pointsType.getDescriptor("sp"), diff);
    FeatureDiff feaureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(pointsType), RevFeatureTypeImpl.build(pointsType));
    patch.addModifiedFeature(feaureDiff);
    geogig.command(ApplyPatchOp.class).setPatch(patch).call();
    RevTree root = repo.workingTree().getTree();
    Optional<Node> featureBlobId = findTreeChild(root, path);
    assertTrue(featureBlobId.isPresent());
    Iterator<DiffEntry> unstaged = repo.workingTree().getUnstaged(pointsName);
    ArrayList<DiffEntry> diffs = Lists.newArrayList(unstaged);
    assertEquals(2, diffs.size());
    Optional<RevFeature> feature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:" + path).call(RevFeature.class);
    assertTrue(feature.isPresent());
    ImmutableList<Optional<Object>> values = feature.get().getValues();
    assertEquals("new", values.get(0).get());
}
Also used : PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) GenericAttributeDiffImpl(org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl) Node(org.locationtech.geogig.api.Node) FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) RevFeature(org.locationtech.geogig.api.RevFeature) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) RevTree(org.locationtech.geogig.api.RevTree) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 40 with RevFeature

use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.

the class ImportOpTest method testAdaptFeatureType.

@Test
public void testAdaptFeatureType() throws Exception {
    ImportOp importOp = geogig.command(ImportOp.class);
    importOp.setDataStore(TestHelper.createTestFactory().createDataStore(null));
    importOp.setTable("shpLikeTable");
    importOp.setDestinationPath("table");
    importOp.call();
    Optional<RevFeature> feature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:table/feature1").call(RevFeature.class);
    assertTrue(feature.isPresent());
    RevFeatureType originalFeatureType = geogig.command(ResolveFeatureType.class).setRefSpec("WORK_HEAD:table/feature1").call().get();
    importOp.setTable("shpLikeTable2");
    importOp.call();
    feature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:table/feature1").call(RevFeature.class);
    assertTrue(feature.isPresent());
    RevFeatureType featureType = geogig.command(ResolveFeatureType.class).setRefSpec("WORK_HEAD:table/feature1").call().get();
    assertEquals(originalFeatureType.getId(), featureType.getId());
    GeometryFactory gf = new GeometryFactory();
    ImmutableList<Optional<Object>> values = feature.get().getValues();
    assertEquals(values.get(0).get(), gf.createPoint(new Coordinate(0, 7)));
    assertEquals(values.get(1).get(), 3.2);
    assertEquals(values.get(2).get(), 1100.0);
    importOp.setTable("GeoJsonLikeTable");
    importOp.call();
    feature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:table/feature1").call(RevFeature.class);
    assertTrue(feature.isPresent());
    featureType = geogig.command(ResolveFeatureType.class).setRefSpec("WORK_HEAD:table/feature1").call().get();
    assertEquals(originalFeatureType.getId(), featureType.getId());
    values = feature.get().getValues();
    assertEquals(values.get(0).get(), gf.createPoint(new Coordinate(0, 8)));
    assertEquals(values.get(1).get(), 4.2);
    assertEquals(values.get(2).get(), 1200.0);
}
Also used : ResolveFeatureType(org.locationtech.geogig.api.plumbing.ResolveFeatureType) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Optional(com.google.common.base.Optional) Coordinate(com.vividsolutions.jts.geom.Coordinate) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Aggregations

RevFeature (org.locationtech.geogig.api.RevFeature)89 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)46 Test (org.junit.Test)45 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)43 Optional (com.google.common.base.Optional)40 NodeRef (org.locationtech.geogig.api.NodeRef)32 File (java.io.File)24 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)24 ObjectId (org.locationtech.geogig.api.ObjectId)21 AddOp (org.locationtech.geogig.api.porcelain.AddOp)21 ImmutableList (com.google.common.collect.ImmutableList)20 Feature (org.opengis.feature.Feature)20 List (java.util.List)19 RevObject (org.locationtech.geogig.api.RevObject)18 RevTree (org.locationtech.geogig.api.RevTree)16 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)16 SimpleFeature (org.opengis.feature.simple.SimpleFeature)16 ArrayList (java.util.ArrayList)15 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)15 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)15