use of org.geotoolkit.storage.feature.FeatureWriter in project geotoolkit by Geomatys.
the class IndexedShapefileDataStoreTest method writeFeatures.
private void writeFeatures(final IndexedShapefileFeatureStore s, final Collection<Feature> fc) throws Exception {
final FeatureType type = fc.iterator().next().getType();
s.createFeatureType(type);
final FeatureWriter fw = s.getFeatureWriter(new Query(type.getName()));
final Iterator<Feature> it = fc.iterator();
while (it.hasNext()) {
Feature feature = it.next();
Feature newFeature = fw.next();
FeatureExt.copy(feature, newFeature, false);
fw.write();
}
fw.close();
assertEquals(20, s.getCount(new Query(type.getName())));
}
use of org.geotoolkit.storage.feature.FeatureWriter in project geotoolkit by Geomatys.
the class IndexedShapefileDataStoreTest method testUpdating.
/**
* Create a set of features, then remove every other one, updating the
* remaining. Test for removal and proper update after reloading...
*/
@Test
public void testUpdating() throws Throwable {
IndexedShapefileFeatureStore sds = createDataStore();
loadFeatures(sds);
FeatureWriter writer = null;
try {
writer = sds.getFeatureWriter(new Query(sds.getName()));
while (writer.hasNext()) {
Feature feat = writer.next();
Byte b = (Byte) feat.getPropertyValue("b");
if ((b.byteValue() % 2) == 0) {
writer.remove();
} else {
feat.setPropertyValue("b", new Byte((byte) -1));
}
}
} finally {
if (writer != null) {
writer.close();
}
}
FeatureCollection fc = loadFeatures(sds);
assertEquals(10, fc.size());
FeatureIterator i = fc.iterator();
for (; i.hasNext(); ) {
assertEquals(-1, ((Byte) i.next().getPropertyValue("b")).byteValue());
}
i.close();
sds.close();
}
use of org.geotoolkit.storage.feature.FeatureWriter in project geotoolkit by Geomatys.
the class IndexedShapefileDataStoreTest method testRemoveFromFrontAndCloseTransaction.
/**
* Create a test file, then continue removing the first entry until there
* are no features left.
*/
@Test
public void testRemoveFromFrontAndCloseTransaction() throws Throwable {
IndexedShapefileFeatureStore sds = createDataStore();
int idx = loadFeatures(sds).size();
while (idx > 0) {
FeatureWriter writer = null;
try {
writer = sds.getFeatureWriter(new Query(sds.getName()));
writer.next();
writer.remove();
} finally {
if (writer != null) {
writer.close();
writer = null;
}
}
assertEquals(--idx, loadFeatures(sds).size());
}
}
Aggregations