use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class ShapefileReadWriteTest method test.
private void test(final FeatureType type, final FeatureCollection original, final File tmp, final ShapefileProvider maker, final boolean memorymapped, final Charset charset) throws IOException, MalformedURLException, Exception {
ShapefileFeatureStore shapefile;
GenericName typeName = type.getName();
final ParameterValueGroup params = maker.getOpenParameters().createValue();
params.parameter(ShapefileProvider.LOCATION).setValue(tmp.toURI());
params.parameter(ShapefileProvider.MEMORY_MAPPED.getName().toString()).setValue(memorymapped);
params.parameter(ShapefileProvider.DBFCHARSET.getName().toString()).setValue(charset);
shapefile = (ShapefileFeatureStore) maker.open(params);
shapefile.createFeatureType(type);
Session session = shapefile.createSession(true);
session.addFeatures(typeName.toString(), original);
session.commit();
assertFalse(session.hasPendingChanges());
FeatureCollection copy = session.getFeatureCollection(new Query(typeName));
compare(original, copy);
// review open
ShapefileFeatureStore review = new ShapefileFeatureStore(tmp.toURI(), memorymapped, charset);
typeName = review.getNames().iterator().next();
FeatureCollection again = review.createSession(true).getFeatureCollection(new Query(typeName));
compare(copy, again);
compare(original, again);
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class ShapefileTest method testDuplicateColumnNames.
@Test
public void testDuplicateColumnNames() throws Exception {
File file = TestData.file(AbstractTestCaseSupport.class, "bad/state.shp");
ShapefileFeatureStore featureStore = new ShapefileFeatureStore(file.toURI());
FeatureType schema = featureStore.getFeatureType(featureStore.getNames().iterator().next().toString());
// +3 for env,geom,id calculated fields
assertEquals(6 + 3, schema.getProperties(true).size());
assertTrue(featureStore.getCount(new Query(schema.getName())) > 0);
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class ShapefileTest method testHolyPolygons.
@Test
public void testHolyPolygons() throws Exception {
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
ftb.setName("test");
ftb.addAttribute(MultiPolygon.class).setName("a").addRole(AttributeRole.DEFAULT_GEOMETRY);
final FeatureType type = ftb.build();
Collection<Feature> features = new ArrayList<>();
File tmpFile = getTempFile();
tmpFile.delete();
// write features
ShapefileProvider make = new ShapefileProvider();
String pathId = ShapefileProvider.PATH.getName().getCode();
FeatureStore s = (FeatureStore) make.create(Parameters.toParameter(Collections.singletonMap(pathId, tmpFile.toURI().toURL()), make.getOpenParameters()));
s.createFeatureType(type);
GenericName typeName = type.getName();
Session session = s.createSession(true);
session.addFeatures(typeName.toString(), features);
session.commit();
s = new ShapefileFeatureStore(tmpFile.toURI());
typeName = s.getNames().iterator().next();
FeatureCollection fc = s.createSession(true).getFeatureCollection(new Query(typeName));
ShapefileReadWriteTest.compare(features, fc);
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class IndexedShapefileDataStoreTest method testEnvelope.
private void testEnvelope(final FeatureCollection features, final IndexType treeType) throws MalformedURLException, IOException, DataStoreException, URISyntaxException {
IndexedShapefileFeatureStore s = new IndexedShapefileFeatureStore(ShapeTestData.url(STATE_POP).toURI(), true, true, treeType, null);
GenericName typeName = s.getName();
FeatureCollection all = s.createSession(true).getFeatureCollection(new Query(typeName));
assertEquals(features.getEnvelope(), all.getEnvelope());
s.close();
}
use of org.geotoolkit.storage.feature.query.Query in project geotoolkit by Geomatys.
the class IndexedShapefileDataStoreTest method loadFeatures.
protected FeatureCollection loadFeatures(final String resource, final Query q) throws Exception {
URL url = ShapeTestData.url(resource);
IndexedShapefileFeatureStore s = new IndexedShapefileFeatureStore(url.toURI());
final FeatureCollection features;
if (q == null) {
features = s.createSession(true).getFeatureCollection(new Query(s.getName()));
} else {
features = s.createSession(true).getFeatureCollection(q);
}
s.close();
return features;
}
Aggregations