use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class ShapefileDataStoreTest method loadFeatures.
protected FeatureCollection loadFeatures(final String resource, final Charset charset, final Query q) throws Exception {
URL url = ShapeTestData.url(resource);
ShapefileFeatureStore s = new ShapefileFeatureStore(url.toURI(), false, charset);
if (q == null) {
return s.createSession(true).getFeatureCollection(new Query(s.getName()));
} else {
return s.createSession(true).getFeatureCollection(q);
}
}
use of org.geotoolkit.storage.feature.query.Query 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.query.Query in project geotoolkit by Geomatys.
the class ShapefileDataStoreTest method testEnvelope.
/**
* Test envelope versus old DataSource
*/
@Test
public void testEnvelope() throws Exception {
FeatureCollection features = loadFeatures(STATE_POP, new Query(NamesExt.create("statepop")));
ShapefileFeatureStore s = new ShapefileFeatureStore(ShapeTestData.url(STATE_POP).toURI());
String typeName = s.getName().toString();
FeatureCollection all = s.createSession(true).getFeatureCollection(new Query(s.getName()));
assertEquals(features.getEnvelope(), all.getEnvelope());
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class ShapefileDataStoreTest method testLoadDanishChars.
@Test
public void testLoadDanishChars() throws Exception {
FeatureCollection fc = loadFeatures(DANISH, new Query(NamesExt.create("danish_point")));
Feature first = firstFeature(fc);
// Charlotte (but with the o is stroked)
assertEquals("Charl\u00F8tte", first.getPropertyValue("TEKST1"));
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class ShapefileReadWriteTest method test.
private void test(final String f, final Charset charset) throws Exception {
// Work on File rather than URL from JAR.
copyShapefiles(f);
ShapefileFeatureStore s = new ShapefileFeatureStore(TestData.url(AbstractTestCaseSupport.class, f).toURI(), false, charset);
GenericName typeName = s.getNames().iterator().next();
Session session = s.createSession(true);
FeatureType type = s.getFeatureType(typeName.toString());
FeatureCollection one = session.getFeatureCollection(new Query(typeName));
File tmp = getTempFile();
ShapefileProvider maker = new ShapefileProvider();
test(type, one, tmp, maker, true, charset);
// TODO consider reuse tmp results in
File tmp2 = getTempFile();
// failure
test(type, one, tmp2, maker, false, charset);
}
Aggregations