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());
}
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();
}
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;
}
Aggregations