@Override public FeatureCalc create(Expression aggregateAttribute) { return new AverageVisitor(aggregateAttribute); }
@Override protected FeatureCalc createVisitor(int attributeTypeIndex, SimpleFeatureType type) { return new AverageVisitor(attributeTypeIndex, type); } }
/** * Calculate average (using FeatureCalc) - only one parameter is used. * * @param collection collection to calculate the average * @param expression Single Expression argument * @return An object containing the average value of the attributes * @throws IllegalFilterException * @throws IOException */ static CalcResult calculateAverage( FeatureCollection<? extends FeatureType, ? extends Feature> collection, Expression expression) throws IllegalFilterException, IOException { AverageVisitor averageVisitor = new AverageVisitor(expression); collection.accepts(averageVisitor, null); return averageVisitor.getResult(); }
FeatureCalc calc; if (function == AggregationFunction.Average) { calc = new AverageVisitor(attIndex, features.getSchema()); } else if (function == AggregationFunction.Count) { calc = new CountVisitor();
/** * Calculate average (using FeatureCalc) - only one parameter is used. * * @param collection collection to calculate the average * @param expression Single Expression argument * * @return An object containing the average value of the attributes * * @throws IllegalFilterException * @throws IOException */ static CalcResult calculateAverage(FeatureCollection<? extends FeatureType, ? extends Feature> collection, Expression expression) throws IllegalFilterException, IOException { AverageVisitor averageVisitor = new AverageVisitor(expression); collection.accepts(averageVisitor, null); return averageVisitor.getResult(); }
/** * Calculate average (using FeatureCalc) - only one parameter is used. * * @param collection collection to calculate the average * @param expression Single Expression argument * * @return An object containing the average value of the attributes * * @throws IllegalFilterException * @throws IOException */ public static CalcResult calculateAverage(FeatureCollection collection, Expression expression) throws IllegalFilterException, IOException { AverageVisitor averageVisitor = new AverageVisitor(expression); collection.accepts(averageVisitor, null); return averageVisitor.getResult(); }
public void testAverage() throws IllegalFilterException, IOException { AverageVisitor averageVisitor = new AverageVisitor(0, ft); AverageVisitor averageVisitor2 = new AverageVisitor(3, ft2);
public void testStandardDeviation() throws Exception { FilterFactory factory = CommonFactoryFinder.getFilterFactory(null); Expression expr = factory.property(ft3.getDescriptor(0).getLocalName()); // first do it the old fashioned way to ensure backwards compatibility AverageVisitor visit1 = new AverageVisitor(expr); fc3.accepts(visit1, null); CalcResult result = visit1.getResult(); double average = result.toDouble(); StandardDeviationVisitor visit2 = new StandardDeviationVisitor(expr, average); fc3.accepts(visit2, null); assertEquals(28.86, visit2.getResult().toDouble(), 0.01); // then do it single pass StandardDeviationVisitor visit3 = new StandardDeviationVisitor(expr); fc3.accepts(visit3, null); assertEquals(28.86, visit3.getResult().toDouble(), 0.01); // test empty collection StandardDeviationVisitor emptyVisitor = new StandardDeviationVisitor(expr, average); empty.accepts(emptyVisitor, null); assertEquals(CalcResult.NULL_RESULT, emptyVisitor.getResult()); // test merge assertSame(result, emptyVisitor.getResult().merge(result)); assertSame(result, result.merge(emptyVisitor.getResult())); }
FeatureCalc calc; if (function == AggregationFunction.Average) { calc = new AverageVisitor(attIndex, features.getSchema()); } else if (function == AggregationFunction.Count) { calc = new CountVisitor();
int classNum = getClasses(); AverageVisitor averageVisit = new AverageVisitor(getExpression()); if (progress == null) progress = new NullProgressListener(); featureCollection.accepts(averageVisit, progress);