Search in sources :

Example 1 with SimpleFeatureIterator

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;
}
Also used : SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 2 with SimpleFeatureIterator

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());
    }
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) NodeRef(org.locationtech.geogig.api.NodeRef) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) HashMap(java.util.HashMap) ResourceId(org.opengis.filter.identity.ResourceId) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Test(org.junit.Test)

Example 3 with SimpleFeatureIterator

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));
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) Feature(org.opengis.feature.Feature) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 4 with SimpleFeatureIterator

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));
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) Feature(org.opengis.feature.Feature) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 5 with SimpleFeatureIterator

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));
}
Also used : SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) Feature(org.opengis.feature.Feature) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Test(org.junit.Test)

Aggregations

SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)33 SimpleFeature (org.opengis.feature.simple.SimpleFeature)33 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)24 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)19 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)15 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)13 Test (org.junit.Test)13 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 MemoryDataStore (org.geotools.data.memory.MemoryDataStore)9 Feature (org.opengis.feature.Feature)9 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)8 Geometry (com.vividsolutions.jts.geom.Geometry)6 HashMap (java.util.HashMap)6 Query (org.geotools.data.Query)6 Map (java.util.Map)5 DataStore (org.geotools.data.DataStore)5 ListFeatureCollection (org.geotools.data.collection.ListFeatureCollection)5 File (java.io.File)4