Hello GT users,

I need your help.

I have a problem with the aggregation functions (SumVisitor, MaxVisitor…).
Following the example from:
http://docs.codehaus.org/display/GEOTDOC/10+FeatureCollection+Aggregate+Func
tions, I wrote this function:

 

 

public List<Feature> aggregate(Collection<? extends Feature> source,
FeatureType targetType) {

                                List<Feature> result = new
ArrayList<Feature>();

                               SimpleFeature target = null;

                               FilterFactory2 ff =
CommonFactoryFinder.getFilterFactory2(null);

                               Function sum =
ff.function(this.aggregationRule, ff.property(this.onAttributeName));

                               FeatureCollection sourceFeatures =
FeatureCollections.newCollection(); 

                               for (Feature f : source){

                                               sourceFeatures.add(f);

                               }

                               Object value = sum.evaluate(sourceFeatures);

                               target = SimpleFeatureBuilder.build(

 
(SimpleFeatureType) targetType, new Object[]{}, 

 
UUID.randomUUID().toString());

                                               

 
target.setAttribute(this.onAttributeName,value);

                               result.add(target);

                               return result;

                }

 

 

And a Test:

 

 

@Test

                public void testAggregate(){

                               SimpleFeatureType ft = null;

                               SimpleFeatureTypeBuilder ftbuilder = new
SimpleFeatureTypeBuilder();

 
ftbuilder.setName(NameHelper.sourceLocalname);

 
ftbuilder.setNamespaceURI(NameHelper.sourceNamespace);

                               ftbuilder.add("SomeAttr", Integer.class);

                               ft = ftbuilder.buildFeatureType();

                               SimpleFeatureBuilder builder = new
SimpleFeatureBuilder(ft);

                               Feature source1 = SimpleFeatureBuilder.build(

                                                               ft, new
Object[]{"2"}, UUID.randomUUID().toString());

                               Feature source2 = SimpleFeatureBuilder.build(

                                                               ft, new
Object[]{"3"}, UUID.randomUUID().toString());

                               List<Feature> features = new
ArrayList<Feature>();

                               features.add(source1);

                                features.add(source2);

 

                               FeatureAggregator2 fa = new
FeatureAggregator2(NameHelper.sourceLocalname, "aggregate:Collection_Sum");

                               List<Feature>results = fa.aggregate(features,
ft);

                               assertTrue(results.size() == 1);

 
assertTrue(results.get(0).getProperty(NameHelper.sourceLocalname).getValue()
.toString() == "5");

                }

 

 

Running the test I get the warning:

WARNUNG: Can't load a service for category "ConverterFactory". Cause is
"NoClassDefFoundError: org/apache/commons/beanutils/Converter".

 

And the failure trace:

java.lang.NoClassDefFoundError:
org/apache/commons/jxpath/ri/model/NodePointerFactory

                at java.lang.Class.forName0(Native Method)

                at java.lang.Class.forName(Unknown Source)

                at sun.misc.Service$LazyIterator.next(Unknown Source)

                at
org.geotools.filter.expression.PropertyAccessors.<clinit>(PropertyAccessors.
java:45)

                at
org.geotools.filter.AttributeExpressionImpl.getPropertyAccessor(AttributeExp
ressionImpl.java:204)

                at
org.geotools.filter.AttributeExpressionImpl.evaluate(AttributeExpressionImpl
.java:187)

                at
org.geotools.filter.AttributeExpressionImpl.evaluate(AttributeExpressionImpl
.java:182)

                at
org.geotools.feature.visitor.SumVisitor.visit(SumVisitor.java:94)

                at
org.geotools.feature.DefaultFeatureCollection.accepts(DefaultFeatureCollecti
on.java:668)

                at
org.geotools.filter.function.Collection_SumFunction.calculateSum(Collection_
SumFunction.java:81)

                at
org.geotools.filter.function.Collection_SumFunction.evaluate(Collection_SumF
unction.java:139)

                at
eu.esdihumboldt.cst.transformer.service.rename.FeatureAggregator2.aggregate(
FeatureAggregator2.java:134)

                at
eu.esdihumboldt.cst.service.rename.FeatureAggregatorTest.testAggregate(Featu
reAggregatorTest.java:39)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)

                at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown
Source)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)

                at java.lang.reflect.Method.invoke(Unknown Source)

                at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.
java:44)

                at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.j
ava:15)

                at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.ja
va:41)

                at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.jav
a:20)

                at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28
)

                at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)

                at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.jav
a:73)

                at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.jav
a:46)

                at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)

                at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)

                at
org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)

                at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28
)

                at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)

                at org.junit.runners.ParentRunner.run(ParentRunner.java:220)

                at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestRef
erence.java:46)

                at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:3
8)

                at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRu
nner.java:467)

                at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRu
nner.java:683)

                at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.
java:390)

                at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner
.java:197)

Caused by: java.lang.ClassNotFoundException:
org.apache.commons.jxpath.ri.model.NodePointerFactory

                at java.net.URLClassLoader$1.run(Unknown Source)

                at java.security.AccessController.doPrivileged(Native
Method)

                at java.net.URLClassLoader.findClass(Unknown Source)

                at java.lang.ClassLoader.loadClass(Unknown Source)

                at sun.misc.Launcher$AppClassLoader.loadClass(Unknown
Source)

                at java.lang.ClassLoader.loadClass(Unknown Source)

                ... 37 more

 

My question:

-          Am I using the SumVisitor in a wrong way or is there a bug in
geotools?

-          If there is a bug, does anybody know a workaround?

 

Kind regards and thanks for your help,

Uli Schäffler

 

 

--

 

------------------------------------------------------------------------------
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to