use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class ShapefileDataStoreTest method testLoadAndVerify.
@Test
public void testLoadAndVerify() throws Exception {
FeatureCollection features = loadFeatures(STATE_POP, new Query(NamesExt.create("statepop")));
// FeatureCollection<SimpleFeatureType, SimpleFeature> features = loadFeaturesM2();
int count = features.size();
assertTrue("Have features", count > 0);
// assertEquals("Number of Features loaded",49,features.size()); // FILE
// (correct value)
// assertEquals("Number of Features loaded",3, count); // JAR
Feature firstFeature = firstFeature(features);
FeatureType schema = firstFeature.getType();
assertNotNull(FeatureExt.getDefaultGeometry(schema));
assertEquals("Number of Attributes", 256, schema.getProperties(true).size());
assertEquals("Value of statename is wrong", "Illinois", firstFeature.getPropertyValue("STATE_NAME"));
assertEquals("Value of land area is wrong", 143986.61, ((Double) firstFeature.getPropertyValue("LAND_KM")).doubleValue(), 0.001);
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class ShapefileDataStoreTest method testRemoveFromFrontAndClose.
/**
* Create a test file, then continue removing the first entry until there
* are no features left.
*/
@Test
public void testRemoveFromFrontAndClose() throws Throwable {
ShapefileFeatureStore sds = createDataStore();
int idx = loadFeatures(sds).size();
while (idx > 0) {
FeatureWriter writer = null;
try {
writer = sds.getFeatureWriter(new Query(sds.getNames().iterator().next()));
writer.next();
writer.remove();
} finally {
if (writer != null) {
writer.close();
writer = null;
}
}
assertEquals(--idx, loadFeatures(sds).size());
}
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class ShapefileDataStoreTest 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 {
ShapefileFeatureStore sds = createDataStore();
loadFeatures(sds);
FeatureWriter writer = null;
try {
writer = sds.getFeatureWriter(new Query(sds.getNames().iterator().next()));
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();
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class ShapefileDataStoreTest method loadFeatures.
protected FeatureCollection loadFeatures(final String resource, Query query) throws Exception {
assertNotNull(query);
URL url = ShapeTestData.url(resource);
ShapefileFeatureStore s = new ShapefileFeatureStore(url.toURI(), true, null);
final Query builder = new Query();
builder.copy(query);
builder.setTypeName(s.getName());
query = builder;
return s.createSession(true).getFeatureCollection(query);
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class ShapefileDataStoreTest method testRemoveFromFrontAndCloseTransaction.
/**
* Create a test file, then continue removing the first entry until there
* are no features left.
*/
@Test
public void testRemoveFromFrontAndCloseTransaction() throws Throwable {
ShapefileFeatureStore sds = createDataStore();
int idx = loadFeatures(sds).size();
while (idx > 0) {
FeatureWriter writer = null;
try {
writer = sds.getFeatureWriter(new Query(sds.getName()));
// System.out.println("classe : " + writer.getClass());
writer.next();
writer.remove();
} finally {
if (writer != null) {
writer.close();
writer = null;
}
}
assertEquals(--idx, loadFeatures(sds).size());
}
}
Aggregations