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());
}
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;
}
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())));
}
}
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());
}
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);
}
Aggregations