Search in sources :

Example 6 with CheckCloseFeatureIterator

use of org.geotoolkit.storage.feature.CheckCloseFeatureIterator 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)

Example 7 with CheckCloseFeatureIterator

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

the class FeatureStreamsTest method testWrapIterator.

@Test
public void testWrapIterator() {
    FeatureCollection collection = buildSimpleFeatureCollection();
    // check has next do not iterate
    FeatureIterator ite = FeatureStreams.asIterator(collection.iterator());
    testIterationOnNext(ite, 3);
    // check sub iterator is properly closed
    CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
    assertFalse(checkIte.isClosed());
    ite = FeatureStreams.asIterator(checkIte);
    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) CheckCloseFeatureIterator(org.geotoolkit.storage.feature.CheckCloseFeatureIterator) Test(org.junit.Test)

Example 8 with CheckCloseFeatureIterator

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

the class FeatureStreamsTest method testMaxIterator.

@Test
public void testMaxIterator() {
    FeatureCollection collection = buildSimpleFeatureCollection();
    FeatureIterator ite = FeatureStreams.limit(collection.iterator(), 10);
    assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
    ite = FeatureStreams.limit(collection.iterator(), 2);
    assertEquals(2, FeatureStoreUtilities.calculateCount(ite));
    ite = FeatureStreams.limit(collection.iterator(), 1);
    assertEquals(id1, 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.limit(collection.iterator(), 10);
    testIterationOnNext(ite, 3);
    // check sub iterator is properly closed
    CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
    assertFalse(checkIte.isClosed());
    ite = FeatureStreams.limit(checkIte, 10);
    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 9 with CheckCloseFeatureIterator

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

the class FeatureStreamsTest method testSortByIteratorOnComplex.

@Test
public void testSortByIteratorOnComplex() {
    FeatureCollection collectionComplex = buildComplexFeatureCollection();
    FeatureCollection collection = buildSimpleFeatureCollection();
    // test string sort -----------------------------------------------------
    SortProperty[] sorts = new SortProperty[] { FF.sort(FF.property("att_string"), SortOrder.DESCENDING) };
    FeatureIterator ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
    assertEquals(2, FeatureStoreUtilities.calculateCount(ite));
    ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
    assertEquals(COMPLEX_ID_2, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
    assertEquals(COMPLEX_ID_1, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
    try {
        ite.next();
        fail("Should have raise a no such element exception.");
    } catch (NoSuchElementException ex) {
    // ok
    }
    // test string sort -----------------------------------------------------
    sorts = new SortProperty[] { FF.sort(FF.property("att_double"), SortOrder.DESCENDING) };
    ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
    assertEquals(2, FeatureStoreUtilities.calculateCount(ite));
    ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
    assertEquals(COMPLEX_ID_1, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
    assertEquals(COMPLEX_ID_2, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
    try {
        ite.next();
        fail("Should have raise a no such element exception.");
    } catch (NoSuchElementException ex) {
    // ok
    }
    // test double sort -----------------------------------------------------
    sorts = new SortProperty[] { FF.sort(FF.property("att_double"), SortOrder.ASCENDING) };
    ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
    assertEquals(2, FeatureStoreUtilities.calculateCount(ite));
    ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
    assertEquals(COMPLEX_ID_2, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
    assertEquals(COMPLEX_ID_1, 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(collectionComplex.iterator(), sorts);
    testIterationOnNext(ite, 2);
    // 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)

Example 10 with CheckCloseFeatureIterator

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

the class FeatureStreamsTest method testRetypeFeatureIterator.

@Test
public void testRetypeFeatureIterator() throws DataStoreException {
    final FeatureCollection collection = buildSimpleFeatureCollection();
    final ViewMapper reducedType = new ViewMapper(collection.getType(), AttributeConvention.IDENTIFIER, "att_double");
    final Query query = new Query(collection.getType().getName());
    FeatureReader reader = collection.getSession().getFeatureStore().getFeatureReader(query);
    FeatureReader retyped = FeatureStreams.decorate(reader, reducedType, null);
    assertEquals(reducedType.getMappedType(), retyped.getFeatureType());
    int mask = 0;
    Feature f;
    while (retyped.hasNext()) {
        f = retyped.next();
        final Object id = f.getPropertyValue(AttributeConvention.IDENTIFIER);
        assertEquals(2, f.getType().getProperties(true).size());
        if (id1.equals(id)) {
            mask |= 1 << 0;
            assertEquals(3d, (Double) f.getProperty("att_double").getValue(), DELTA);
        } else if (id2.equals(id)) {
            mask |= 1 << 1;
            assertEquals(1d, (Double) f.getProperty("att_double").getValue(), DELTA);
        } else if (id3.equals(id)) {
            mask |= 1 << 2;
            assertEquals(2d, (Double) f.getProperty("att_double").getValue(), DELTA);
        }
    }
    assertEquals("missing features in iterations", 7, mask);
    // check has next do not iterate
    reader = collection.getSession().getFeatureStore().getFeatureReader(query);
    retyped = FeatureStreams.decorate(reader, reducedType, null);
    testIterationOnNext(retyped, 3);
    // check sub iterator is properly closed
    reader = collection.getSession().getFeatureStore().getFeatureReader(query);
    CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(reader);
    assertFalse(checkIte.isClosed());
    retyped = FeatureStreams.decorate(checkIte, reducedType, null);
    while (retyped.hasNext()) retyped.next();
    retyped.close();
    assertTrue(checkIte.isClosed());
}
Also used : Query(org.geotoolkit.storage.feature.query.Query) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) ViewMapper(org.geotoolkit.feature.ViewMapper) FeatureReader(org.geotoolkit.storage.feature.FeatureReader) Feature(org.opengis.feature.Feature) Point(org.locationtech.jts.geom.Point) CheckCloseFeatureIterator(org.geotoolkit.storage.feature.CheckCloseFeatureIterator) Test(org.junit.Test)

Aggregations

CheckCloseFeatureIterator (org.geotoolkit.storage.feature.CheckCloseFeatureIterator)10 Test (org.junit.Test)10 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)9 FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)7 NoSuchElementException (java.util.NoSuchElementException)6 FeatureReader (org.geotoolkit.storage.feature.FeatureReader)3 Feature (org.opengis.feature.Feature)3 Query (org.geotoolkit.storage.feature.query.Query)2 Point (org.locationtech.jts.geom.Point)2 SortProperty (org.opengis.filter.SortProperty)2 HashMap (java.util.HashMap)1 Hints (org.geotoolkit.factory.Hints)1 ReprojectMapper (org.geotoolkit.feature.ReprojectMapper)1 ViewMapper (org.geotoolkit.feature.ViewMapper)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 Geometry (org.locationtech.jts.geom.Geometry)1 LineString (org.locationtech.jts.geom.LineString)1 FeatureType (org.opengis.feature.FeatureType)1 Filter (org.opengis.filter.Filter)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1