Search in sources :

Example 6 with FilterFactory2

use of org.geotoolkit.filter.FilterFactory2 in project geotoolkit by Geomatys.

the class IndexedShapefileDataStoreTest method performQueryComparison.

private ArrayList performQueryComparison(final IndexedShapefileFeatureStore indexedDS, final IndexedShapefileFeatureStore baselineDS, final JTSEnvelope2D newBounds) throws FactoryRegistryException, IOException, DataStoreException {
    FeatureCollection features;
    FeatureIterator indexIter;
    FilterFactory2 fac = FilterUtilities.FF;
    String geometryName = FeatureExt.getDefaultGeometry(indexedDS.getFeatureType()).getName().tip().toString();
    Filter filter = fac.bbox(fac.property(geometryName), newBounds);
    features = indexedDS.createSession(true).getFeatureCollection(Query.filtered(indexedDS.getName().toString(), filter));
    FeatureCollection features2 = baselineDS.createSession(true).getFeatureCollection(Query.filtered(baselineDS.getName().toString(), filter));
    FeatureIterator baselineIter = features2.iterator();
    indexIter = features.iterator();
    ArrayList baselineFeatures = new ArrayList();
    ArrayList indexedFeatures = new ArrayList();
    try {
        while (baselineIter.hasNext()) {
            baselineFeatures.add(baselineIter.next());
        }
        while (indexIter.hasNext()) {
            indexedFeatures.add(indexIter.next());
        }
        assertFalse(indexIter.hasNext());
        assertFalse(baselineIter.hasNext());
        assertTrue(baselineFeatures.containsAll(indexedFeatures));
        assertTrue(indexedFeatures.containsAll(baselineFeatures));
    } finally {
        indexIter.close();
        baselineIter.close();
    }
    return indexedFeatures;
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) Filter(org.opengis.filter.Filter) ArrayList(java.util.ArrayList) FilterFactory2(org.geotoolkit.filter.FilterFactory2)

Example 7 with FilterFactory2

use of org.geotoolkit.filter.FilterFactory2 in project geotoolkit by Geomatys.

the class ShapefileQuadTreeReadWriteTest method testGetBoundsQuery.

/**
 * Test optimized getBounds(). Testing when filter is a bbox filter and a fidfilter
 *
 * @throws Exception
 */
@Test
// fails randomly, urgent need to write shapefile store in SIS
@Ignore
public void testGetBoundsQuery() throws Exception {
    File file = copyShapefiles("shapes/streams.shp");
    ShapefileProvider fac = new ShapefileProvider();
    final ParameterValueGroup params = fac.getOpenParameters().createValue();
    params.parameter(ShapefileProvider.LOCATION).setValue(file.toURI());
    params.parameter(ShapefileProvider.CREATE_SPATIAL_INDEX.getName().toString()).setValue(Boolean.TRUE);
    IndexedShapefileFeatureStore ds = (IndexedShapefileFeatureStore) fac.open(params);
    FilterFactory2 ff = FilterUtilities.FF;
    ResourceId filter = ff.resourceId("streams.84");
    FeatureIterator iter = ds.getFeatureReader(Query.filtered(ds.getName().toString(), filter));
    JTSEnvelope2D bounds;
    try {
        bounds = new JTSEnvelope2D(FeatureExt.getEnvelope(iter.next()));
    } finally {
        iter.close();
    }
    Query query = Query.filtered(ds.getNames().iterator().next().toString(), filter);
    Envelope result = (Envelope) ds.getEnvelope(query);
    assertTrue(result.equals(bounds));
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) JTSEnvelope2D(org.geotoolkit.geometry.jts.JTSEnvelope2D) Query(org.geotoolkit.storage.feature.query.Query) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ResourceId(org.opengis.filter.ResourceId) Envelope(org.locationtech.jts.geom.Envelope) File(java.io.File) FilterFactory2(org.geotoolkit.filter.FilterFactory2) ShapefileProvider(org.geotoolkit.data.shapefile.ShapefileProvider) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with FilterFactory2

use of org.geotoolkit.filter.FilterFactory2 in project geotoolkit by Geomatys.

the class MathCalcProcess method execute.

@Override
protected void execute() throws ProcessException {
    final GridCoverage[] inCoverages = inputParameters.getValue(MathCalcDescriptor.IN_COVERAGES);
    final String inFormula = inputParameters.getValue(MathCalcDescriptor.IN_FORMULA);
    final String[] inMapping = inputParameters.getValue(MathCalcDescriptor.IN_MAPPING);
    final WritableGridCoverageResource outRef = inputParameters.getValue(MathCalcDescriptor.IN_RESULT_COVERAGE);
    final GridGeometry gg;
    try {
        gg = outRef.getGridGeometry();
    } catch (DataStoreException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
    // create expression
    final FilterFactory2 ff = FilterUtilities.FF;
    final Expression exp;
    try {
        exp = CQL.parseExpression(inFormula, ff);
    } catch (CQLException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
    // prepare dynamic pick object
    final MathCalcCoverageEvaluator evaluator;
    try {
        evaluator = new MathCalcCoverageEvaluator(inCoverages, inMapping, exp, gg.getCoordinateReferenceSystem());
    } catch (FactoryException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
    final FillCoverage filler = new FillCoverage();
    try {
        if (outRef instanceof TiledResource) {
            filler.fill((TiledResource) outRef, evaluator);
        } else {
            filler.fill(outRef, evaluator, null);
        }
    } catch (DataStoreException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    } catch (TransformException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    } catch (FactoryException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) DataStoreException(org.apache.sis.storage.DataStoreException) FactoryException(org.opengis.util.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) ProcessException(org.geotoolkit.process.ProcessException) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) Expression(org.opengis.filter.Expression) TiledResource(org.geotoolkit.storage.multires.TiledResource) WritableGridCoverageResource(org.apache.sis.storage.WritableGridCoverageResource) CQLException(org.apache.sis.cql.CQLException) FilterFactory2(org.geotoolkit.filter.FilterFactory2)

Aggregations

FilterFactory2 (org.geotoolkit.filter.FilterFactory2)8 Filter (org.opengis.filter.Filter)5 FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)4 Test (org.junit.Test)4 Query (org.geotoolkit.storage.feature.query.Query)3 File (java.io.File)2 HashSet (java.util.HashSet)2 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)2 Expression (org.opengis.filter.Expression)2 URL (java.net.URL)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)1 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)1 CQLException (org.apache.sis.cql.CQLException)1 DataStoreException (org.apache.sis.storage.DataStoreException)1 WritableGridCoverageResource (org.apache.sis.storage.WritableGridCoverageResource)1