Search in sources :

Example 56 with Query

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

Example 57 with Query

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());
    }
}
Also used : FeatureWriter(org.geotoolkit.storage.feature.FeatureWriter) Query(org.geotoolkit.storage.feature.query.Query) Point(org.locationtech.jts.geom.Point) Test(org.junit.Test)

Example 58 with Query

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

Example 59 with Query

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

Example 60 with Query

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

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