Search in sources :

Example 1 with FeatureIterator

use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.

the class FeatureStreamsTest method testStartIndexIterator.

@Test
public void testStartIndexIterator() {
    FeatureCollection collection = buildSimpleFeatureCollection();
    FeatureIterator ite = FeatureStreams.skip(collection.iterator(), 0);
    assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
    ite = FeatureStreams.skip(collection.iterator(), 1);
    assertEquals(2, FeatureStoreUtilities.calculateCount(ite));
    ite = FeatureStreams.skip(collection.iterator(), 2);
    assertTrue(ite.next() != null);
    try {
        ite.next();
        fail("Should have raise a no such element exception.");
    } catch (NoSuchElementException ex) {
    // ok
    }
    // check has next do not iterate
    ite = FeatureStreams.skip(collection.iterator(), 1);
    testIterationOnNext(ite, 2);
    // check sub iterator is properly closed
    CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
    assertFalse(checkIte.isClosed());
    ite = FeatureStreams.skip(checkIte, 1);
    while (ite.hasNext()) ite.next();
    ite.close();
    assertTrue(checkIte.isClosed());
}
Also used : CheckCloseFeatureIterator(org.geotoolkit.storage.feature.CheckCloseFeatureIterator) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) NoSuchElementException(java.util.NoSuchElementException) CheckCloseFeatureIterator(org.geotoolkit.storage.feature.CheckCloseFeatureIterator) Test(org.junit.Test)

Example 2 with FeatureIterator

use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.

the class FeatureStreamsTest method testFilterIterator.

@Test
public void testFilterIterator() {
    FeatureCollection collection = buildSimpleFeatureCollection();
    FeatureIterator ite = FeatureStreams.filter(collection.iterator(), Filter.include());
    assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
    ite = FeatureStreams.filter(collection.iterator(), Filter.exclude());
    assertEquals(0, FeatureStoreUtilities.calculateCount(ite));
    ite = FeatureStreams.filter(collection.iterator(), FF.equal(FF.literal("aaa"), FF.property("att_string")));
    assertEquals(1, FeatureStoreUtilities.calculateCount(ite));
    ite = FeatureStreams.filter(collection.iterator(), FF.equal(FF.literal("aaa"), FF.property("att_string")));
    assertEquals(id3, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
    try {
        ite.next();
        fail("Should have raise a no such element exception.");
    } catch (NoSuchElementException ex) {
    // ok
    }
    // check has next do not iterate
    ite = FeatureStreams.filter(collection.iterator(), Filter.include());
    testIterationOnNext(ite, 3);
    // check sub iterator is properly closed
    CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
    assertFalse(checkIte.isClosed());
    ite = FeatureStreams.filter(checkIte, Filter.include());
    while (ite.hasNext()) ite.next();
    ite.close();
    assertTrue(checkIte.isClosed());
}
Also used : CheckCloseFeatureIterator(org.geotoolkit.storage.feature.CheckCloseFeatureIterator) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) NoSuchElementException(java.util.NoSuchElementException) CheckCloseFeatureIterator(org.geotoolkit.storage.feature.CheckCloseFeatureIterator) Test(org.junit.Test)

Example 3 with FeatureIterator

use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.

the class FeatureStreamsTest method testCacheIterator.

@Test
@Ignore("See #GEOTK-489")
public void testCacheIterator() {
    FeatureCollection collection = buildSimpleFeatureCollection();
    FeatureIterator ite = FeatureStreams.cached(collection.iterator(), 1);
    assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
    ite = FeatureStreams.cached(collection.iterator(), 1);
    int mask = 0;
    Feature f;
    while (ite.hasNext()) {
        f = ite.next();
        final Object id = f.getPropertyValue(AttributeConvention.IDENTIFIER);
        if (id1.equals(id)) {
            mask |= 1 << 0;
        } else if (id2.equals(id)) {
            mask |= 1 << 1;
        } else if (id3.equals(id)) {
            mask |= 1 << 2;
        }
    }
    ite.close();
    if (mask != 7) {
        fail("missing features in iterations");
    }
}
Also used : CheckCloseFeatureIterator(org.geotoolkit.storage.feature.CheckCloseFeatureIterator) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) Feature(org.opengis.feature.Feature) Point(org.locationtech.jts.geom.Point) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with FeatureIterator

use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.

the class FeatureStreamsTest method testModifyIterator.

@Test
public void testModifyIterator() {
    FeatureCollection collection = buildSimpleFeatureCollection();
    FeatureType originalType = collection.getType();
    Filter filter = Filter.include();
    Map<String, Object> values = new HashMap<>();
    values.put("att_string", "toto");
    FeatureIterator ite = FeatureStreams.update(collection.iterator(), filter, values);
    assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
    ite = FeatureStreams.update(collection.iterator(), filter, values);
    while (ite.hasNext()) {
        assertTrue(ite.next().getProperty("att_string").getValue().equals("toto"));
    }
    filter = FF.equal(FF.literal("aaa"), FF.property("att_string"));
    ite = FeatureStreams.update(collection.iterator(), filter, values);
    assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
    ite = FeatureStreams.update(collection.iterator(), filter, values);
    while (ite.hasNext()) {
        Feature f = ite.next();
        if (f.getPropertyValue(AttributeConvention.IDENTIFIER).equals(id3)) {
            assertTrue(f.getProperty("att_string").getValue().equals("toto"));
        } else {
            assertFalse(f.getProperty("att_string").getValue().equals("toto"));
        }
    }
    ite = FeatureStreams.update(collection.iterator(), filter, values);
    ite.next();
    ite.next();
    ite.next();
    try {
        ite.next();
        fail("Should have raise a no such element exception.");
    } catch (NoSuchElementException ex) {
    // ok
    }
    // check has next do not iterate
    ite = FeatureStreams.update(collection.iterator(), filter, values);
    testIterationOnNext(ite, 3);
    // check sub iterator is properly closed
    CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
    assertFalse(checkIte.isClosed());
    ite = FeatureStreams.update(checkIte, filter, values);
    while (ite.hasNext()) ite.next();
    ite.close();
    assertTrue(checkIte.isClosed());
}
Also used : CheckCloseFeatureIterator(org.geotoolkit.storage.feature.CheckCloseFeatureIterator) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) FeatureType(org.opengis.feature.FeatureType) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) Filter(org.opengis.filter.Filter) HashMap(java.util.HashMap) LineString(org.locationtech.jts.geom.LineString) Feature(org.opengis.feature.Feature) NoSuchElementException(java.util.NoSuchElementException) CheckCloseFeatureIterator(org.geotoolkit.storage.feature.CheckCloseFeatureIterator) Test(org.junit.Test)

Example 5 with FeatureIterator

use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.

the class FeatureStreamsTest method testSortByIterator.

@Test
public void testSortByIterator() {
    SortProperty[] sorts = new SortProperty[] { FF.sort(FF.property("att_string"), SortOrder.ASCENDING) };
    FeatureCollection collection = buildSimpleFeatureCollection();
    FeatureIterator ite = FeatureStreams.sort(collection.iterator(), sorts);
    assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
    ite = FeatureStreams.sort(collection.iterator(), sorts);
    assertEquals(id3, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
    assertEquals(id1, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
    assertEquals(id2, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
    try {
        ite.next();
        fail("Should have raise a no such element exception.");
    } catch (NoSuchElementException ex) {
    // ok
    }
    // check has next do not iterate
    ite = FeatureStreams.sort(collection.iterator(), sorts);
    testIterationOnNext(ite, 3);
    // check sub iterator is properly closed
    CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
    assertFalse(checkIte.isClosed());
    ite = FeatureStreams.sort(checkIte, sorts);
    while (ite.hasNext()) ite.next();
    ite.close();
    assertTrue(checkIte.isClosed());
}
Also used : CheckCloseFeatureIterator(org.geotoolkit.storage.feature.CheckCloseFeatureIterator) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) SortProperty(org.opengis.filter.SortProperty) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) NoSuchElementException(java.util.NoSuchElementException) CheckCloseFeatureIterator(org.geotoolkit.storage.feature.CheckCloseFeatureIterator) Test(org.junit.Test)

Aggregations

FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)53 Feature (org.opengis.feature.Feature)41 Test (org.junit.Test)34 Query (org.geotoolkit.storage.feature.query.Query)30 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)24 FeatureType (org.opengis.feature.FeatureType)20 ResourceId (org.opengis.filter.ResourceId)20 Coordinate (org.locationtech.jts.geom.Coordinate)11 Point (org.locationtech.jts.geom.Point)11 Session (org.geotoolkit.storage.feature.session.Session)10 Geometry (org.locationtech.jts.geom.Geometry)10 HashMap (java.util.HashMap)9 CheckCloseFeatureIterator (org.geotoolkit.storage.feature.CheckCloseFeatureIterator)9 ArrayList (java.util.ArrayList)8 Date (java.util.Date)7 NoSuchElementException (java.util.NoSuchElementException)7 Filter (org.opengis.filter.Filter)7 File (java.io.File)6 Version (org.geotoolkit.version.Version)6 VersionControl (org.geotoolkit.version.VersionControl)6