use of org.geotoolkit.storage.feature.FeatureWriter in project geotoolkit by Geomatys.
the class DefaultJDBCFeatureStore method handleRemoveWithFeatureWriter.
/**
* Convenient method to handle adding features operation by using the
* FeatureWriter.
*/
protected void handleRemoveWithFeatureWriter(final String groupName, final Filter filter, Connection cnx) throws DataStoreException {
try (FeatureWriter writer = getFeatureWriterInternal(groupName, filter, EditMode.UPDATE, cnx, null)) {
while (writer.hasNext()) {
writer.next();
writer.remove();
}
} catch (FeatureStoreRuntimeException | IOException ex) {
throw new DataStoreException(ex);
}
}
use of org.geotoolkit.storage.feature.FeatureWriter in project geotoolkit by Geomatys.
the class ShapefileDataStoreTest method testWriteShapefileWithNoRecords.
@Test
public void testWriteShapefileWithNoRecords() throws Exception {
final FeatureTypeBuilder ftb = new FeatureTypeBuilder().setName("whatever");
ftb.addAttribute(Polygon.class).setName("a").addRole(AttributeRole.DEFAULT_GEOMETRY);
ftb.addAttribute(String.class).setName("b");
FeatureType featureType = ftb.build();
File tempFile = getTempFile();
ShapefileFeatureStore shapefileFeatureStore = new ShapefileFeatureStore(tempFile.toURI());
shapefileFeatureStore.createFeatureType(featureType);
FeatureWriter featureWriter = shapefileFeatureStore.getFeatureWriter(new Query(shapefileFeatureStore.getName()));
// don't add any features to the data store....
// this should open a shapefile with no records. Not sure about the
// semantics of this,
// but it's meant to be used in the context of a FeatureCollection
// iteration,
// where the FeatureCollection<SimpleFeatureType, SimpleFeature> has nothing in it.
featureWriter.close();
}
use of org.geotoolkit.storage.feature.FeatureWriter in project geotoolkit by Geomatys.
the class ShapefileDataStoreTest method writeFeatures.
private void writeFeatures(final ShapefileFeatureStore s, final Collection<Feature> fc) throws Exception {
final FeatureType sft = fc.iterator().next().getType();
s.createFeatureType(sft);
try (FeatureWriter fw = s.getFeatureWriter(new Query(sft.getName()))) {
Iterator<Feature> it = fc.iterator();
while (it.hasNext()) {
Feature feature = it.next();
Feature newFeature = fw.next();
FeatureExt.copy(feature, newFeature, false);
fw.write();
}
}
}
use of org.geotoolkit.storage.feature.FeatureWriter in project geotoolkit by Geomatys.
the class ShapefileDataStoreTest method testRemoveFromBackAndClose.
/**
* Create a test file, then continue removing the last entry until there are
* no features left.
*/
@Test
public void testRemoveFromBackAndClose() throws Throwable {
ShapefileFeatureStore sds = createDataStore();
int idx = loadFeatures(sds).size();
while (idx > 0) {
FeatureWriter writer = null;
try {
writer = sds.getFeatureWriter(new Query(sds.getName()));
while (writer.hasNext()) {
writer.next();
}
writer.remove();
} finally {
if (writer != null) {
writer.close();
writer = null;
}
}
assertEquals(--idx, loadFeatures(sds).size());
}
}
use of org.geotoolkit.storage.feature.FeatureWriter in project geotoolkit by Geomatys.
the class IndexedShapefileDataStoreTest method testRemoveFromFrontAndClose.
/**
* Create a test file, then continue removing the first entry until there
* are no features left.
*/
@Test
public void testRemoveFromFrontAndClose() 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());
}
sds.close();
}
Aggregations