Search in sources :

Example 31 with FeatureIterator

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

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

the class FeatureStreamsTest method testEmptyIterator.

@Test
public void testEmptyIterator() {
    final FeatureIterator iterator = FeatureStreams.emptyIterator();
    assertFalse(iterator.hasNext());
    try {
        iterator.next();
        fail("Next on empty iterator should have raised a no such element exception.");
    } catch (NoSuchElementException ex) {
    // ok
    }
    try {
        iterator.remove();
        fail("Remove should have raise an error.");
    } catch (Exception ex) {
    // ok
    }
    iterator.close();
}
Also used : CheckCloseFeatureIterator(org.geotoolkit.storage.feature.CheckCloseFeatureIterator) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) NoSuchElementException(java.util.NoSuchElementException) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) DataStoreException(org.apache.sis.storage.DataStoreException) NoSuchElementException(java.util.NoSuchElementException) FactoryException(org.opengis.util.FactoryException) Test(org.junit.Test)

Example 33 with FeatureIterator

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

the class AddDelta method modify.

/**
 * {@inheritDoc }
 */
@Override
public FeatureIterator modify(final Query query, final FeatureIterator reader) throws DataStoreException {
    if (!query.getTypeName().equals(type))
        return reader;
    // remove the filter, it is handle at the end by the session
    // we can not filter here since some modify operation can follow
    // and change the filter result
    final Query qb = new Query();
    qb.copy(query);
    qb.setSelection(Filter.include());
    final FeatureIterator affected = features.subset(qb).iterator();
    final SortProperty[] sort = QueryUtilities.getSortProperties(query.getSortBy());
    if (sort != null && sort.length > 0) {
        return FeatureStreams.combine(query.getSortBy(), reader, affected);
    } else {
        return FeatureStreams.sequence(reader, affected);
    }
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) SortProperty(org.opengis.filter.SortProperty) Query(org.geotoolkit.storage.feature.query.Query)

Example 34 with FeatureIterator

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

the class RenderingRoutines method getIterator.

public static GraphicIterator getIterator(final FeatureSet features, final RenderingContext2D renderingContext) throws DataStoreException {
    final FeatureIterator iterator;
    final Stream<Feature> stream = features.features(false);
    final Iterator<Feature> i = stream.iterator();
    iterator = new FeatureIterator() {

        @Override
        public Feature next() throws FeatureStoreRuntimeException {
            return i.next();
        }

        @Override
        public boolean hasNext() throws FeatureStoreRuntimeException {
            return i.hasNext();
        }

        @Override
        public void close() {
            stream.close();
        }
    };
    final ProjectedFeature projectedFeature = new ProjectedFeature(renderingContext);
    return new GraphicIterator(iterator, projectedFeature);
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) ProjectedFeature(org.geotoolkit.display2d.primitive.ProjectedFeature) Feature(org.opengis.feature.Feature) ProjectedFeature(org.geotoolkit.display2d.primitive.ProjectedFeature)

Example 35 with FeatureIterator

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

the class DBRelationOperation method apply.

@Override
public Property apply(Feature ftr, ParameterValueGroup pvg) {
    final Object key = ftr.getPropertyValue(relation.getCurrentColumn());
    final Query qb = new Query();
    qb.setTypeName(NamesExt.create(relation.getForeignTable()));
    qb.setSelection(relation.toFilter(key));
    final FeatureCollection res = store.createSession(false).getFeatureCollection(qb);
    final Object value;
    if (type.getMaximumOccurs() == 1) {
        try (FeatureIterator ite = res.iterator()) {
            if (ite.hasNext()) {
                value = ite.next();
            } else {
                value = null;
            }
        }
    } else {
        value = res;
    }
    return new AbstractAssociation(type) {

        @Override
        public Feature getValue() throws MultiValuedPropertyException {
            if (value == null || value instanceof Feature) {
                return (Feature) value;
            }
            throw new MultiValuedPropertyException();
        }

        @Override
        public Collection<Feature> getValues() {
            if (value == null) {
                return Collections.EMPTY_LIST;
            } else if (value instanceof Feature) {
                return Arrays.asList((Feature) value);
            } else {
                return res;
            }
        }

        @Override
        public void setValue(Feature value) throws InvalidPropertyValueException {
            throw new UnsupportedOperationException("Not supported.");
        }
    };
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) AbstractAssociation(org.apache.sis.feature.AbstractAssociation) Query(org.geotoolkit.storage.feature.query.Query) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) MultiValuedPropertyException(org.opengis.feature.MultiValuedPropertyException) Feature(org.opengis.feature.Feature)

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