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;
}
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));
}
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);
}
}
Aggregations