Search in sources :

Example 21 with Query

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);
}
Also used : GenericName(org.opengis.util.GenericName) Query(org.geotoolkit.storage.feature.query.Query) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) Session(org.geotoolkit.storage.feature.session.Session)

Example 22 with Query

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);
}
Also used : FeatureType(org.opengis.feature.FeatureType) Query(org.geotoolkit.storage.feature.query.Query) File(java.io.File) Test(org.junit.Test)

Example 23 with Query

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);
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) Query(org.geotoolkit.storage.feature.query.Query) ArrayList(java.util.ArrayList) Feature(org.opengis.feature.Feature) GenericName(org.opengis.util.GenericName) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) File(java.io.File) FeatureStore(org.geotoolkit.storage.feature.FeatureStore) Session(org.geotoolkit.storage.feature.session.Session) Test(org.junit.Test)

Example 24 with Query

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();
}
Also used : GenericName(org.opengis.util.GenericName) Query(org.geotoolkit.storage.feature.query.Query) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection)

Example 25 with Query

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;
}
Also used : Query(org.geotoolkit.storage.feature.query.Query) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) URL(java.net.URL)

Aggregations

Query (org.geotoolkit.storage.feature.query.Query)82 Test (org.junit.Test)50 Feature (org.opengis.feature.Feature)43 FeatureType (org.opengis.feature.FeatureType)36 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)31 FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)30 Session (org.geotoolkit.storage.feature.session.Session)20 Point (org.locationtech.jts.geom.Point)18 ResourceId (org.opengis.filter.ResourceId)18 GenericName (org.opengis.util.GenericName)15 Coordinate (org.locationtech.jts.geom.Coordinate)14 FeatureWriter (org.geotoolkit.storage.feature.FeatureWriter)13 File (java.io.File)10 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)9 FeatureStore (org.geotoolkit.storage.feature.FeatureStore)9 Filter (org.opengis.filter.Filter)9 URL (java.net.URL)8 Date (java.util.Date)8 DataStoreException (org.apache.sis.storage.DataStoreException)8 FeatureReader (org.geotoolkit.storage.feature.FeatureReader)8