Search in sources :

Example 6 with FeatureCollection

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

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

Example 8 with FeatureCollection

use of org.geotoolkit.storage.feature.FeatureCollection 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 9 with FeatureCollection

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

the class FeatureStreamsTest method buildSimpleFeatureCollection.

private FeatureCollection buildSimpleFeatureCollection() {
    FeatureType originalType = buildOriginalFT();
    FeatureCollection collection = FeatureStoreUtilities.collection("id", originalType);
    Feature sf1 = originalType.newInstance();
    sf1.setPropertyValue("id", 0);
    sf1.setPropertyValue("att_geom", GF.createPoint(new Coordinate(3, 0)));
    sf1.setPropertyValue("att_string", "bbb");
    sf1.setPropertyValue("att_double", 3d);
    collection.add(sf1);
    Feature sf2 = originalType.newInstance();
    sf2.setPropertyValue("id", 1);
    sf2.setPropertyValue("att_geom", GF.createPoint(new Coordinate(1, 0)));
    sf2.setPropertyValue("att_string", "ccc");
    sf2.setPropertyValue("att_double", 1d);
    collection.add(sf2);
    Feature sf3 = originalType.newInstance();
    sf3.setPropertyValue("id", 2);
    sf3.setPropertyValue("att_geom", GF.createPoint(new Coordinate(2, 0)));
    sf3.setPropertyValue("att_string", "aaa");
    sf3.setPropertyValue("att_double", 2d);
    collection.add(sf3);
    return collection;
}
Also used : FeatureType(org.opengis.feature.FeatureType) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) Coordinate(org.locationtech.jts.geom.Coordinate) Feature(org.opengis.feature.Feature)

Example 10 with FeatureCollection

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

the class FeatureStreamsTest method buildComplexFeatureCollection.

private FeatureCollection buildComplexFeatureCollection() {
    FeatureTypeBuilder builder = new FeatureTypeBuilder();
    builder.setName(NAME);
    builder.addAttribute(Integer.class).setName("id").addRole(AttributeRole.IDENTIFIER_COMPONENT);
    builder.addAttribute(String.class).setName("att_string");
    builder.addAttribute(Double.class).setName("att_double");
    FeatureType ct = builder.build();
    FeatureCollection collectionComplex = FeatureStoreUtilities.collection("cid", ct);
    Feature f1 = ct.newInstance();
    f1.setPropertyValue("id", COMPLEX_ID_1);
    f1.setPropertyValue("att_string", "aaaa");
    f1.setPropertyValue("att_double", 12.0);
    collectionComplex.add(f1);
    Feature f2 = ct.newInstance();
    f2.setPropertyValue("id", COMPLEX_ID_2);
    f2.setPropertyValue("att_string", "bbbb");
    f2.setPropertyValue("att_double", 7.0);
    collectionComplex.add(f2);
    return collectionComplex;
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) LineString(org.locationtech.jts.geom.LineString) Feature(org.opengis.feature.Feature)

Aggregations

FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)131 Feature (org.opengis.feature.Feature)75 Test (org.junit.Test)49 Coordinate (org.locationtech.jts.geom.Coordinate)49 LinearRing (org.locationtech.jts.geom.LinearRing)39 Query (org.geotoolkit.storage.feature.query.Query)31 FeatureType (org.opengis.feature.FeatureType)27 FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)24 LineString (org.locationtech.jts.geom.LineString)23 MultiPoint (org.locationtech.jts.geom.MultiPoint)16 ProcessDescriptor (org.geotoolkit.process.ProcessDescriptor)15 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)15 Geometry (org.locationtech.jts.geom.Geometry)14 AbstractProcessTest (org.geotoolkit.processing.vector.AbstractProcessTest)13 Session (org.geotoolkit.storage.feature.session.Session)12 CheckCloseFeatureIterator (org.geotoolkit.storage.feature.CheckCloseFeatureIterator)10 Point (org.locationtech.jts.geom.Point)10 GenericName (org.opengis.util.GenericName)10 NoSuchElementException (java.util.NoSuchElementException)8 File (java.io.File)7