@Test public void testCoverageViewGranuleSourceAggregation() throws Exception { final String VIEW_NAME = "viewAggregate"; CoverageInfo info = buildHeterogeneousResolutionView( VIEW_NAME, cv -> { cv.setSelectedResolution(SelectedResolution.BEST); }, "B02", "B03", "B04", "B01"); StructuredGridCoverage2DReader reader = (StructuredGridCoverage2DReader) info.getGridCoverageReader(null, null); GranuleSource source = reader.getGranules(VIEW_NAME, true); Query query = new Query(VIEW_NAME); // used to throw exception here SimpleFeatureCollection granules = source.getGranules(query); MinVisitor visitor = new MinVisitor("location"); granules.accepts(visitor, null); assertEquals("20170410T103021026Z_fullres_CC2.1989_T32TMT_B01.tif", visitor.getMin()); }
@Override public void accepts(FeatureVisitor visitor, ProgressListener progress) throws IOException { // the delegate might have an optimized way to handle filters and still apply a // visitor (e.g., ContentFeatureCollection), but avoid self-looping final SimpleFeatureCollection sc = delegate.subCollection(filter); if (sc instanceof FilteringSimpleFeatureCollection) { super.accepts(visitor, progress); } else { sc.accepts(visitor, progress); } }
public void accepts( org.opengis.feature.FeatureVisitor visitor, org.opengis.util.ProgressListener progress) throws IOException { if (canDelegate(visitor)) { delegate.accepts(visitor, progress); } else { DataUtilities.visit(this, visitor, progress); } }
/** * Calculate count (using FeatureCalc) - only one parameter is used. * * @param collection collection to calculate the count * @return An object containing the count value of the attributes * @throws IllegalFilterException * @throws IOException */ static CalcResult calculateCount(SimpleFeatureCollection collection) throws IllegalFilterException, IOException { CountVisitor countVisitor = new CountVisitor(); collection.accepts(countVisitor, null); return countVisitor.getResult(); }
/** * Calculate minimum (using FeatureCalc) - only one parameter is used. * * @param collection collection to calculate the minimum * @param expression Single Expression argument * @return An object containing the minimum value of the attributes * @throws IllegalFilterException * @throws IOException */ static CalcResult calculateMin(SimpleFeatureCollection collection, Expression expression) throws IllegalFilterException, IOException { MinVisitor minVisitor = new MinVisitor(expression); collection.accepts(minVisitor, null); return minVisitor.getResult(); }
/** * Calculate sum (using FeatureCalc) - only one parameter is used. * * @param collection collection to calculate the sum * @param expression Single Expression argument * @return An object containing the sum value of the attributes * @throws IllegalFilterException * @throws IOException */ static CalcResult calculateSum(SimpleFeatureCollection collection, Expression expression) throws IllegalFilterException, IOException { SumVisitor sumVisitor = new SumVisitor(expression); collection.accepts(sumVisitor, null); return sumVisitor.getResult(); }
/** * Calculate maximum (using FeatureCalc) - only one parameter is used. * * @param collection collection to calculate the maximum * @param expression Single Expression argument * @return An object containing the maximum value of the attributes * @throws IllegalFilterException * @throws IOException */ static CalcResult calculateMax(SimpleFeatureCollection collection, Expression expression) throws IllegalFilterException, IOException { MaxVisitor maxVisitor = new MaxVisitor(expression); collection.accepts(maxVisitor, null); return maxVisitor.getResult(); }
/** * Calculate unique (using FeatureCalc) - only one parameter is used. * * @param collection collection to calculate the unique * @param expression Single Expression argument * @return An object containing the unique value of the attributes * @throws IllegalFilterException * @throws IOException */ static CalcResult calculateUnique(SimpleFeatureCollection collection, Expression expression) throws IllegalFilterException, IOException { UniqueVisitor uniqueVisitor = new UniqueVisitor(expression); collection.accepts(uniqueVisitor, null); return uniqueVisitor.getResult(); }
/** * Calculate nearest using {@link NearestVisitor}. * * @param Collection collection to calculate the maximum * @param Expression Single Expression argument * @param value Attribute value used for nearest search * @return An object containing the maximum value of the attributes * @throws IllegalFilterException * @throws IOException */ static Object near(SimpleFeatureCollection collection, Expression expression, Object value) throws IllegalFilterException, IOException { NearestVisitor visitor = new NearestVisitor(expression, value); collection.accepts(visitor, new NullProgressListener()); return visitor.getNearestMatch(); }
private void assertOptimalVisit(FeatureVisitor visitor) throws IOException, SchemaException { SimpleFeatureCollection retypedCollection = new ForceCoordinateSystemFeatureResults(visitorCollection, utm32n); retypedCollection.accepts(visitor, null); assertSame(lastVisitor, visitor); }
private void assertOptimalVisit(FeatureVisitor visitor) throws Exception { SimpleFeatureCollection retypedCollection = new ReprojectFeatureResults(visitorCollection, utm32n); retypedCollection.accepts(visitor, null); assertSame(lastVisitor, visitor); }
private CalcResult countGranulesMatchingCalc(Filter filter, RasterManager manager) throws IOException { Query q = new Query(manager.getTypeName()); q.setFilter(filter); SimpleFeatureCollection lc = manager.getGranuleCatalog().getGranules(q); List<Expression> groupByExpressions = Arrays.asList((Expression) getLocationProperty(manager)); GroupByVisitor groupVisitor = new GroupByVisitor(Aggregate.COUNT, NilExpression.NIL, groupByExpressions, null); lc.accepts(groupVisitor, null); return groupVisitor.getResult(); }
public void testUniquePreserveOrder() throws IOException { UniqueVisitor uniqueVisitor = new UniqueVisitor(0, ft); uniqueVisitor.setPreserveOrder(true); fc.accepts(uniqueVisitor, null); Set value1 = uniqueVisitor.getResult().toSet(); assertEquals(1, value1.iterator().next()); uniqueVisitor.reset(); invfc.accepts(uniqueVisitor, null); value1 = uniqueVisitor.getResult().toSet(); assertEquals(3, value1.iterator().next()); }
public void testBoundsNotOptimized() throws Exception { BoundsVisitor boundsVisitor = new BoundsVisitor(); SimpleFeatureCollection retypedCollection = new ReprojectFeatureResults(visitorCollection, utm32n); retypedCollection.accepts(boundsVisitor, null); // not optimized assertNull(lastVisitor); } }
public void testBoundsNotOptimized() throws IOException, SchemaException { BoundsVisitor boundsVisitor = new BoundsVisitor(); SimpleFeatureCollection retypedCollection = new ForceCoordinateSystemFeatureResults(visitorCollection, utm32n); retypedCollection.accepts(boundsVisitor, null); // not optimized assertNull(lastVisitor); } }
public void computeAggregateFunction(Query query, FeatureCalc function) throws IOException { query = mergeHints(query); checkStore(); SimpleFeatureSource fs = getTileIndexStore().getFeatureSource(query.getTypeName()); if (fs instanceof ContentFeatureSource) ((ContentFeatureSource) fs).accepts(query, function, null); else { final SimpleFeatureCollection collection = fs.getFeatures(query); collection.accepts(function, null); } }
public void testAreaInvalidPolygon() throws IllegalFilterException, IOException { SumAreaVisitor areaVisitor = new SumAreaVisitor(1, ft6); fc6.accepts(areaVisitor, null); double value1 = areaVisitor.getResult().toDouble(); assertEquals(0.0, value1); }
public void testVisitor() throws IOException { Filter filter = ff.equal(ff.property("someAtt"), ff.literal("1"), false); SimpleFeatureCollection collection = new FilteringSimpleFeatureCollection(delegate, filter); collection.accepts( new FeatureVisitor() { public void visit(Feature feature) { assertEquals(1, feature.getProperty("someAtt").getValue()); } }, null); }
public void testArea() throws IllegalFilterException, IOException { SumAreaVisitor areaVisitor = new SumAreaVisitor(1, ft4); fc4.accepts(areaVisitor, null); SumAreaVisitor areaVisitor2 = new SumAreaVisitor(1, ft5); fc5.accepts(areaVisitor2, null); double value1 = areaVisitor.getResult().toDouble(); assertEquals(10.0, value1); double value2 = areaVisitor2.getResult().toDouble(); assertEquals(12.0, value2); CalcResult areaResult1 = areaVisitor.getResult(); CalcResult areaResult2 = areaVisitor2.getResult(); CalcResult areaResult3 = areaResult1.merge(areaResult2); assertEquals((double) 22.0, areaResult3.toDouble(), 0); }
public void testCountSumMerge() throws IllegalFilterException, IOException { CountVisitor countVisitor = new CountVisitor(); fc2.accepts(countVisitor, null); // count = 2 SumVisitor sumVisitor = new SumVisitor(3, ft2); fc2.accepts(sumVisitor, null); // sum = 7.5 CalcResult countResult = countVisitor.getResult(); CalcResult sumResult = sumVisitor.getResult(); CalcResult averageResult1 = countResult.merge(sumResult); CalcResult averageResult2 = sumResult.merge(countResult); // both average results were correct? assertEquals((double) 3.75, averageResult1.toDouble(), 0); assertEquals((double) 3.75, averageResult2.toDouble(), 0); // neither sum nor count was destroyed? assertEquals(2, countResult.toInt()); assertEquals((double) 7.5, sumResult.toDouble(), 0); }