use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class SparseCloneTest method setupSparseClone.
private void setupSparseClone() throws Exception {
Map<String, String> filter = new HashMap<String, String>();
filter.put("default", "BBOX(pp,30, -125, 40, -110,'EPSG:4326')");
filter.put("Cities", "BBOX(pp,33, -125, 40, -110,'EPSG:4326')");
createFilterFile(filter);
// Commit several features to the remote
List<Feature> features = Arrays.asList(city3, road1, city2, road2);
LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
Map<Feature, ObjectId> oids = new HashMap<Feature, ObjectId>();
for (Feature f : features) {
ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
oids.put(f, oId);
final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).setMessage(f.getIdentifier().toString()).call();
expected.addFirst(commit);
Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
assertTrue(childObject.isPresent());
}
// Make sure the remote has all of the commits
Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
List<RevCommit> logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
// Make sure the local repository has no commits prior to clone
logs = localGeogig.geogig.command(LogOp.class).call();
assertNotNull(logs);
assertFalse(logs.hasNext());
// clone from the remote
CloneOp clone = clone();
clone.setDepth(0);
clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).setBranch("master").call();
logs = localGeogig.geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals("Roads.2", logged.get(0).getMessage());
assertFalse(expected.get(0).getId().equals(logged.get(0).getId()));
assertEquals(expected.get(2).getId(), logged.get(1).getId());
assertEquals(expected.get(3).getId(), logged.get(2).getId());
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class ReportMergeConflictsOpTest method testModifiedAndRemoved.
@Test
public void testModifiedAndRemoved() throws Exception {
insertAndAdd(points1);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("TestBranch").call();
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
insertAndAdd(points1Modified);
RevCommit masterCommit = geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("TestBranch").call();
deleteAndAdd(points1);
RevCommit branchCommit = geogig.command(CommitOp.class).call();
MergeScenarioReport conflicts = geogig.command(ReportMergeScenarioOp.class).setMergeIntoCommit(masterCommit).setToMergeCommit(branchCommit).call();
assertEquals(1, conflicts.getConflicts().size());
assertEquals(0, conflicts.getUnconflicted().size());
Boolean hasConflicts = geogig.command(CheckMergeScenarioOp.class).setCommits(Lists.newArrayList(masterCommit, branchCommit)).call();
assertTrue(hasConflicts.booleanValue());
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class ExportDiffOp method getFeatures.
private static Iterator<SimpleFeature> getFeatures(Iterator<DiffEntry> diffs, final boolean old, final ObjectDatabase database, final ObjectId metadataId, final ProgressListener progressListener) {
final SimpleFeatureType featureType = addFidAttribute(database.getFeatureType(metadataId));
final RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType);
final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
Function<DiffEntry, SimpleFeature> asFeature = new Function<DiffEntry, SimpleFeature>() {
@Override
@Nullable
public SimpleFeature apply(final DiffEntry input) {
NodeRef nodeRef = old ? input.getOldObject() : input.getNewObject();
if (nodeRef == null) {
return null;
}
final RevFeature revFeature = database.getFeature(nodeRef.objectId());
ImmutableList<Optional<Object>> values = revFeature.getValues();
for (int i = 0; i < values.size(); i++) {
String name = featureType.getDescriptor(i + 1).getLocalName();
Object value = values.get(i).orNull();
featureBuilder.set(name, value);
}
featureBuilder.set("geogig_fid", nodeRef.name());
Feature feature = featureBuilder.buildFeature(nodeRef.name());
feature.getUserData().put(Hints.USE_PROVIDED_FID, true);
feature.getUserData().put(RevFeature.class, revFeature);
feature.getUserData().put(RevFeatureType.class, revFeatureType);
if (feature instanceof SimpleFeature) {
return (SimpleFeature) feature;
}
return null;
}
};
Iterator<SimpleFeature> asFeatures = Iterators.transform(diffs, asFeature);
UnmodifiableIterator<SimpleFeature> filterNulls = Iterators.filter(asFeatures, Predicates.notNull());
return filterNulls;
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class ImportOp method transformFeatures.
private Iterator<Feature> transformFeatures(SimpleFeatureType featureType, String path) {
String refspec = Ref.WORK_HEAD + ":" + path;
Iterator<NodeRef> oldFeatures = command(LsTreeOp.class).setReference(refspec).setStrategy(Strategy.FEATURES_ONLY).call();
RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType);
Iterator<Feature> transformedIterator = transformIterator(oldFeatures, revFeatureType);
return transformedIterator;
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class ImportOp method alter.
/**
* Translates a feature pointed by a node from its original feature type to a given one, using
* values from those attributes that exist in both original and destination feature type. New
* attributes are populated with null values
*
* @param node The node that points to the feature. No checking is performed to ensure the node
* points to a feature instead of other type
* @param featureType the destination feature type
* @return a feature with the passed feature type and data taken from the input feature
*/
private Feature alter(NodeRef node, RevFeatureType featureType) {
RevFeature oldFeature = command(RevObjectParse.class).setObjectId(node.objectId()).call(RevFeature.class).get();
RevFeatureType oldFeatureType;
oldFeatureType = command(RevObjectParse.class).setObjectId(node.getMetadataId()).call(RevFeatureType.class).get();
ImmutableList<PropertyDescriptor> oldAttributes = oldFeatureType.sortedDescriptors();
ImmutableList<PropertyDescriptor> newAttributes = featureType.sortedDescriptors();
ImmutableList<Optional<Object>> oldValues = oldFeature.getValues();
List<Optional<Object>> newValues = Lists.newArrayList();
for (int i = 0; i < newAttributes.size(); i++) {
int idx = oldAttributes.indexOf(newAttributes.get(i));
if (idx != -1) {
Optional<Object> oldValue = oldValues.get(idx);
newValues.add(oldValue);
} else {
newValues.add(Optional.absent());
}
}
RevFeature newFeature = RevFeatureImpl.build(ImmutableList.copyOf(newValues));
FeatureBuilder featureBuilder = new FeatureBuilder(featureType);
Feature feature = featureBuilder.build(node.name(), newFeature);
return feature;
}
Aggregations