use of org.geotools.data.simple.SimpleFeatureIterator in project GeoGig by boundlessgeo.
the class GeoGigFeatureSourceTest method toList.
private List<SimpleFeature> toList(SimpleFeatureCollection collection) {
List<SimpleFeature> features = Lists.newArrayList();
SimpleFeatureIterator iterator = collection.features();
try {
while (iterator.hasNext()) {
features.add(iterator.next());
}
} finally {
iterator.close();
}
return features;
}
use of org.geotools.data.simple.SimpleFeatureIterator in project GeoGig by boundlessgeo.
the class GeoGigFeatureSourceTest method testFeatureIdsAreVersioned.
@Test
public void testFeatureIdsAreVersioned() throws IOException {
SimpleFeatureCollection collection = pointsSource.getFeatures(Query.ALL);
SimpleFeatureIterator features = collection.features();
Set<FeatureId> ids = Sets.newHashSet();
try {
while (features.hasNext()) {
SimpleFeature next = features.next();
FeatureId identifier = next.getIdentifier();
ids.add(identifier);
}
} finally {
features.close();
}
List<NodeRef> refs = toList(repo.command(LsTreeOp.class).setReference(pointsName).setStrategy(Strategy.FEATURES_ONLY).call());
assertEquals(3, refs.size());
Map<String, NodeRef> expected = new HashMap<String, NodeRef>();
for (NodeRef ref : refs) {
expected.put(ref.path(), ref);
}
for (FeatureId id : ids) {
assertFalse("ResourceId is a query object", id instanceof ResourceId);
assertNotNull(id.getID());
assertNotNull(id + " has no featureVersion set", id.getFeatureVersion());
NodeRef ref = expected.get(id.getID());
assertNotNull(ref);
assertEquals(ref.objectId().toString(), id.getFeatureVersion());
}
}
use of org.geotools.data.simple.SimpleFeatureIterator in project GeoGig by boundlessgeo.
the class ExportDiffOpTest method testExportDiffUsingOldVersion.
@Test
public void testExportDiffUsingOldVersion() throws Exception {
insertAndAdd(points1);
final RevCommit insertCommit = geogig.command(CommitOp.class).setAll(true).call();
final String featureId = points1.getIdentifier().getID();
final Feature modifiedFeature = feature((SimpleFeatureType) points1.getType(), featureId, "changedProp", new Integer(1500));
insertAndAdd(modifiedFeature, points2);
final RevCommit changeCommit = geogig.command(CommitOp.class).setAll(true).call();
Feature[] points = new Feature[] { points1 };
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.add("geogig_fid", String.class);
for (AttributeDescriptor descriptor : pointsType.getAttributeDescriptors()) {
builder.add(descriptor);
}
builder.setName(pointsType.getName());
builder.setCRS(pointsType.getCoordinateReferenceSystem());
SimpleFeatureType outputFeatureType = builder.buildFeatureType();
MemoryDataStore dataStore = new MemoryDataStore(outputFeatureType);
final String typeName = dataStore.getTypeNames()[0];
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
geogig.command(ExportDiffOp.class).setFeatureStore(featureStore).setPath(pointsName).setNewRef(changeCommit.getId().toString()).setOldRef(insertCommit.getId().toString()).setUseOld(true).call();
featureSource = dataStore.getFeatureSource(typeName);
featureStore = (SimpleFeatureStore) featureSource;
SimpleFeatureCollection featureCollection = featureStore.getFeatures();
assertEquals(featureCollection.size(), points.length);
SimpleFeatureIterator features = featureCollection.features();
assertTrue(collectionsAreEqual(features, points));
}
use of org.geotools.data.simple.SimpleFeatureIterator in project GeoGig by boundlessgeo.
the class ExportDiffOpTest method testExportDiff.
@Test
public void testExportDiff() throws Exception {
insertAndAdd(points1);
final RevCommit insertCommit = geogig.command(CommitOp.class).setAll(true).call();
final String featureId = points1.getIdentifier().getID();
final Feature modifiedFeature = feature((SimpleFeatureType) points1.getType(), featureId, "changedProp", new Integer(1500));
insertAndAdd(modifiedFeature, points2);
final RevCommit changeCommit = geogig.command(CommitOp.class).setAll(true).call();
Feature[] points = new Feature[] { modifiedFeature, points2 };
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.add("geogig_fid", String.class);
for (AttributeDescriptor descriptor : pointsType.getAttributeDescriptors()) {
builder.add(descriptor);
}
builder.setName(pointsType.getName());
builder.setCRS(pointsType.getCoordinateReferenceSystem());
SimpleFeatureType outputFeatureType = builder.buildFeatureType();
MemoryDataStore dataStore = new MemoryDataStore(outputFeatureType);
final String typeName = dataStore.getTypeNames()[0];
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
geogig.command(ExportDiffOp.class).setFeatureStore(featureStore).setPath(pointsName).setNewRef(changeCommit.getId().toString()).setOldRef(insertCommit.getId().toString()).call();
featureSource = dataStore.getFeatureSource(typeName);
featureStore = (SimpleFeatureStore) featureSource;
SimpleFeatureCollection featureCollection = featureStore.getFeatures();
assertEquals(featureCollection.size(), points.length);
SimpleFeatureIterator features = featureCollection.features();
assertTrue(collectionsAreEqual(features, points));
}
use of org.geotools.data.simple.SimpleFeatureIterator in project GeoGig by boundlessgeo.
the class ExportOpTest method testExportFromWorkingTree.
@Test
public void testExportFromWorkingTree() throws Exception {
Feature[] points = new Feature[] { points1, points2, points3 };
for (Feature feature : points) {
insert(feature);
}
MemoryDataStore dataStore = new MemoryDataStore(pointsType);
final String typeName = dataStore.getTypeNames()[0];
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName).call();
featureSource = dataStore.getFeatureSource(typeName);
featureStore = (SimpleFeatureStore) featureSource;
SimpleFeatureCollection featureCollection = featureStore.getFeatures();
assertEquals(featureCollection.size(), points.length);
SimpleFeatureIterator features = featureCollection.features();
assertTrue(collectionsAreEqual(features, points));
}
Aggregations