Search in sources :

Example 1 with SimpleFeatureCollection

use of org.geotools.data.simple.SimpleFeatureCollection 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 2 with SimpleFeatureCollection

use of org.geotools.data.simple.SimpleFeatureCollection 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 3 with SimpleFeatureCollection

use of org.geotools.data.simple.SimpleFeatureCollection 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 4 with SimpleFeatureCollection

use of org.geotools.data.simple.SimpleFeatureCollection 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)

Example 5 with SimpleFeatureCollection

use of org.geotools.data.simple.SimpleFeatureCollection in project GeoGig by boundlessgeo.

the class ExportOpTest method testExportFromTreeWithSeveralFeatureTypesUsingFeatureTypeId.

@Test
public void testExportFromTreeWithSeveralFeatureTypesUsingFeatureTypeId() throws Exception {
    Feature[] points = new Feature[] { points2, points1B, points3 };
    for (Feature feature : points) {
        insert(feature);
    }
    Feature[] expectedPoints = new Feature[] { points1B };
    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).setFilterFeatureTypeId(RevFeatureTypeImpl.build(modifiedPointsType).getId()).call();
    featureSource = dataStore.getFeatureSource(typeName);
    featureStore = (SimpleFeatureStore) featureSource;
    SimpleFeatureCollection featureCollection = featureStore.getFeatures();
    assertEquals(expectedPoints.length, featureCollection.size());
    SimpleFeatureIterator features = featureCollection.features();
    assertTrue(collectionsAreEqual(features, expectedPoints));
}
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

SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)43 SimpleFeature (org.opengis.feature.simple.SimpleFeature)27 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)24 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)21 Test (org.junit.Test)16 IOException (java.io.IOException)15 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)15 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)12 Feature (org.opengis.feature.Feature)10 ArrayList (java.util.ArrayList)9 MemoryDataStore (org.geotools.data.memory.MemoryDataStore)9 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)9 ListFeatureCollection (org.geotools.data.collection.ListFeatureCollection)7 File (java.io.File)6 HashMap (java.util.HashMap)6 ShapefileDataStore (org.geotools.data.shapefile.ShapefileDataStore)6 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)6 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)6 Geometry (com.vividsolutions.jts.geom.Geometry)5 DataStore (org.geotools.data.DataStore)5