Search in sources :

Example 51 with FeatureIterator

use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.

the class FidQueryTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    final URI uri = backshp.toURI();
    ds = new IndexedShapefileFeatureStore(uri, false, true, IndexType.QIX, null);
    numFeatures = 0;
    name = ds.getNames().iterator().next();
    session = ds.createSession(true);
    final FeatureIterator features = ds.getFeatureReader(new Query(name));
    try {
        while (features.hasNext()) {
            numFeatures++;
            final Feature feature = features.next();
            fids.put(FeatureExt.getId(feature).getIdentifier(), feature);
        }
    } finally {
        if (features != null)
            features.close();
    }
    assertEquals(numFeatures, fids.size());
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) Query(org.geotoolkit.storage.feature.query.Query) URI(java.net.URI) Feature(org.opengis.feature.Feature)

Example 52 with FeatureIterator

use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.

the class FidQueryTest method testModifyFeature.

@Test
public void testModifyFeature() throws Exception {
    final Feature feature = this.fids.values().iterator().next();
    final long newId = 237594123;
    final ResourceId createFidFilter = FeatureExt.getId(feature);
    final FeatureType schema = feature.getType();
    session.updateFeatures(schema.getName().toString(), createFidFilter, Collections.singletonMap("ID", newId));
    session.commit();
    final FeatureIterator features = ds.getFeatureReader(Query.filtered(name.toString(), createFidFilter));
    try {
        assertFalse(feature.equals(features.next()));
    } finally {
        if (features != null) {
            features.close();
        }
    }
    feature.setPropertyValue("ID", newId);
    this.assertFidsMatch();
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) FeatureType(org.opengis.feature.FeatureType) ResourceId(org.opengis.filter.ResourceId) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Example 53 with FeatureIterator

use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.

the class RegroupProcess method getAttributeValues.

/**
 * Browse in input FeatureCollection all different values of the specified attribute
 * If regroupAttribute is null, we return an empty Collection.
 */
static Collection<Object> getAttributeValues(final String regroupAttribute, final FeatureCollection featureList) {
    final Collection<Object> values = new ArrayList<>();
    if (regroupAttribute != null) {
        try (final FeatureIterator featureIter = featureList.iterator()) {
            while (featureIter.hasNext()) {
                final Feature feature = featureIter.next();
                final Object value = feature.getPropertyValue(regroupAttribute);
                if (!values.contains(value)) {
                    values.add(value);
                }
            }
        }
    }
    return values;
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) ArrayList(java.util.ArrayList) Feature(org.opengis.feature.Feature)

Aggregations

FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)53 Feature (org.opengis.feature.Feature)41 Test (org.junit.Test)34 Query (org.geotoolkit.storage.feature.query.Query)30 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)24 FeatureType (org.opengis.feature.FeatureType)20 ResourceId (org.opengis.filter.ResourceId)20 Coordinate (org.locationtech.jts.geom.Coordinate)11 Point (org.locationtech.jts.geom.Point)11 Session (org.geotoolkit.storage.feature.session.Session)10 Geometry (org.locationtech.jts.geom.Geometry)10 HashMap (java.util.HashMap)9 CheckCloseFeatureIterator (org.geotoolkit.storage.feature.CheckCloseFeatureIterator)9 ArrayList (java.util.ArrayList)8 Date (java.util.Date)7 NoSuchElementException (java.util.NoSuchElementException)7 Filter (org.opengis.filter.Filter)7 File (java.io.File)6 Version (org.geotoolkit.version.Version)6 VersionControl (org.geotoolkit.version.VersionControl)6