Search in sources :

Example 1 with CheckCloseFeatureIterator

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

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

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

the class FeatureStreamsTest method testReprojectFeatureIterator.

@Test
public void testReprojectFeatureIterator() throws DataStoreException, FactoryException {
    Query query = new Query(collection.getType().getName());
    FeatureReader reader = collection.getSession().getFeatureStore().getFeatureReader(query);
    final CoordinateReferenceSystem targetCRS = CommonCRS.WGS84.geographic();
    FeatureReader retyped = FeatureStreams.decorate(reader, new ReprojectMapper(reader.getFeatureType(), targetCRS), new Hints());
    int mask = 0;
    Feature f;
    while (retyped.hasNext()) {
        f = retyped.next();
        final Object id = f.getPropertyValue(AttributeConvention.IDENTIFIER);
        assertEquals(4, f.getType().getProperties(true).size());
        assertEquals(targetCRS, JTS.findCoordinateReferenceSystem((Geometry) f.getProperty("att_geom").getValue()));
        if (id1.equals(id)) {
            mask |= 1 << 0;
            assertEquals(GF.createPoint(new Coordinate(0, 3)).toString(), f.getProperty("att_geom").getValue().toString());
        } else if (id2.equals(id)) {
            mask |= 1 << 1;
            assertEquals(GF.createPoint(new Coordinate(0, 1)).toString(), f.getProperty("att_geom").getValue().toString());
        } else if (id3.equals(id)) {
            mask |= 1 << 2;
            assertEquals(GF.createPoint(new Coordinate(0, 2)).toString(), f.getProperty("att_geom").getValue().toString());
        }
    }
    if (mask != 7) {
        fail("missing features in iterations");
    }
    // check has next do not iterate
    reader = collection.getSession().getFeatureStore().getFeatureReader(query);
    retyped = FeatureStreams.decorate(reader, new ReprojectMapper(reader.getFeatureType(), CommonCRS.WGS84.geographic()), new Hints());
    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, new ReprojectMapper(checkIte.getFeatureType(), CommonCRS.WGS84.geographic()), new Hints());
    while (retyped.hasNext()) retyped.next();
    retyped.close();
    assertTrue(checkIte.isClosed());
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Query(org.geotoolkit.storage.feature.query.Query) Hints(org.geotoolkit.factory.Hints) Coordinate(org.locationtech.jts.geom.Coordinate) ReprojectMapper(org.geotoolkit.feature.ReprojectMapper) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) 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)

Example 4 with CheckCloseFeatureIterator

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

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

the class FeatureStreamsTest method testWrapReader.

@Test
public void testWrapReader() {
    FeatureCollection collection = buildSimpleFeatureCollection();
    // check has next do not iterate
    FeatureReader reader = FeatureStreams.asReader(collection.iterator(), collection.getType());
    testIterationOnNext(reader, 3);
    // check sub iterator is properly closed
    CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
    assertFalse(checkIte.isClosed());
    reader = FeatureStreams.asReader(checkIte, collection.getType());
    while (reader.hasNext()) reader.next();
    reader.close();
    assertTrue(checkIte.isClosed());
}
Also used : FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) FeatureReader(org.geotoolkit.storage.feature.FeatureReader) 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