Alessandro Radaelli wrote:

With geotools is it possible to query a Datastore with a query containing aggregate functions like count(*) or sum(*) and group by clauses? I mean the equivalent of an SQL statement like this SELECT count(*), sex from population where ....spatial constraints... GROUP BY sex My datastore is Oracle, so i could issue the SQL directly, but I would like to keep the Datastore abstraction, if possible...and if I perform the "group by" on the resultset in my java code I have a very slow solution and memory problems....

Support for aggregate functions is new -- I was just investigating this, and found a bug, GEOT-797 (now fixed on trunk). Optimizations exist for JDBC feature collections, so you should be able to do your aggregate functions without iterating through the entire feature collection). I don't know what will happen with multiple parameters + aggregates -- we'd need a good example to step through.

I've only tested this with PostGIS, but here is an example:

FeatureType featureType = dstore.getSchema("bc_voting_areas");
JDBCFeatureSource source = new JDBCFeatureSource(dstore, featureType);
Query query = new DefaultQuery(featureType.toString(), null);
FeatureCollection fc = new PostgisFeatureCollection(source, query); 
//JDBCFeatureCollection could also be used here
ExpressionBuilder eb = new ExpressionBuilder();
FunctionExpression expr = (FunctionExpression) 
eb.parser("Collection_Sum(vregist)");
int result = ((Number) expr.getValue(fc)).intValue();

http://svn.geotools.org/geotools/trunk/gt/plugin/postgis/test/org/geotools/data/postgis/collection/PostgisFeatureCollectionOnlineTest.java

There are likely better ways to do this (involving factories, etc), but this one works.

Cheers,
Cory.

----
Cory Horner
Refractions Research Inc.
http://www.refractions.net


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to