use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class IndexedShapefileDataStoreTest method testTestTransaction.
@Test
public void testTestTransaction() throws Exception {
final IndexedShapefileFeatureStore sds = createDataStore();
final long idx = sds.getCount(new Query(sds.getName()));
final Session session = sds.createSession(true);
Feature[] newFeatures1 = new Feature[1];
Feature[] newFeatures2 = new Feature[2];
GeometryFactory fac = org.geotoolkit.geometry.jts.JTS.getFactory();
newFeatures1[0] = sds.getFeatureType().newInstance();
newFeatures1[0].setPropertyValue("a", fac.createPoint(new Coordinate(0, 0)));
newFeatures2[0] = sds.getFeatureType().newInstance();
newFeatures2[0].setPropertyValue("a", fac.createPoint(new Coordinate(0, 0)));
newFeatures2[1] = sds.getFeatureType().newInstance();
newFeatures2[1].setPropertyValue("a", fac.createPoint(new Coordinate(0, 0)));
session.addFeatures(sds.getName().toString(), FeatureStoreUtilities.collection(newFeatures1));
session.addFeatures(sds.getName().toString(), FeatureStoreUtilities.collection(newFeatures2));
session.commit();
assertEquals(idx + 3, sds.getCount(new Query(sds.getName())));
sds.close();
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class IndexedShapefileDataStoreTest method testFidFilter.
@Test
public void testFidFilter() throws Exception {
File shpFile = copyShapefiles(STATE_POP);
URL url = shpFile.toURI().toURL();
IndexedShapefileFeatureStore ds = new IndexedShapefileFeatureStore(url.toURI(), true, true, IndexType.NONE, null);
FeatureCollection features = ds.createSession(true).getFeatureCollection(new Query(ds.getName()));
FeatureIterator indexIter = features.iterator();
Set<String> expectedFids = new HashSet<>();
final Filter fidFilter;
try {
FilterFactory2 ff = FilterUtilities.FF;
Set<Filter<Object>> fids = new HashSet<>();
while (indexIter.hasNext()) {
Feature newFeature = indexIter.next();
String id = FeatureExt.getId(newFeature).getIdentifier();
expectedFids.add(id);
fids.add(ff.resourceId(id));
}
switch(fids.size()) {
case 0:
fidFilter = Filter.exclude();
break;
case 1:
fidFilter = fids.iterator().next();
break;
default:
fidFilter = ff.or(fids);
break;
}
} finally {
indexIter.close();
}
Set<String> actualFids = new HashSet<>();
{
indexIter = ds.getFeatureReader(Query.filtered(ds.getName().toString(), fidFilter));
while (indexIter.hasNext()) {
Feature next = indexIter.next();
String id = FeatureExt.getId(next).getIdentifier();
actualFids.add(id);
}
indexIter.close();
}
TreeSet<String> lackingFids = new TreeSet<>(expectedFids);
lackingFids.removeAll(actualFids);
TreeSet<String> unexpectedFids = new TreeSet<>(actualFids);
unexpectedFids.removeAll(expectedFids);
String lacking = String.valueOf(lackingFids);
String unexpected = String.valueOf(unexpectedFids);
String failureMsg = "lacking fids: " + lacking + ". Unexpected ones: " + unexpected;
assertEquals(failureMsg, expectedFids.size(), actualFids.size());
assertEquals(failureMsg, expectedFids, actualFids);
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class IndexedShapefileDataStoreTest method testRemoveFromBackAndClose.
/**
* Create a test file, then continue removing the last entry until there are
* no features left.
*/
@Test
public void testRemoveFromBackAndClose() throws Throwable {
IndexedShapefileFeatureStore 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());
}
sds.close();
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class ShapefileQuadTreeReadWriteTest method testWriteTwice.
@Test
public void testWriteTwice() throws Exception {
copyShapefiles("shapes/stream.shp");
ShapefileProvider fac = new ShapefileProvider();
FeatureStore s1 = createDataStore(fac, TestData.url(AbstractTestCaseSupport.class, "shapes/stream.shp"), true);
GenericName typeName = s1.getNames().iterator().next();
FeatureType type = s1.getFeatureType(typeName.toString());
FeatureCollection one = s1.createSession(true).getFeatureCollection(new Query(typeName));
ShapefileProvider maker = new ShapefileProvider();
doubleWrite(type, one, getTempFile(), maker, false);
doubleWrite(type, one, getTempFile(), maker, true);
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class ShapefileQuadTreeReadWriteTest method test.
private void test(final FeatureType type, final FeatureCollection one, final File tmp, final ShapefileProvider maker, final boolean memorymapped) throws IOException, MalformedURLException, Exception {
FeatureStore s;
s = createDataStore(maker, tmp.toURI().toURL(), memorymapped);
s.createFeatureType(type);
Session session = s.createSession(true);
session.addFeatures(type.getName().toString(), one);
session.commit();
s = createDataStore(new ShapefileProvider(), tmp.toURI().toURL(), true);
GenericName typeName = s.getNames().iterator().next();
FeatureCollection two = s.createSession(true).getFeatureCollection(new Query(typeName));
// copy values, order is not tested here.
Collection<Feature> cone = new ArrayList<>();
Collection<Feature> ctwo = new ArrayList<>();
FeatureStoreUtilities.fill(one, cone);
FeatureStoreUtilities.fill(two, ctwo);
// one.containsAll(two);
// two.containsAll(one);
}
Aggregations