Thanks Jody,
Your right, the example is not a good one ; actually I don't expect any result from this expression ;)
I haven't yet look at the links you provided (I'll do it a little later i promise). You spoke about XPath ; Groovy for instance encapsulate a XPath like means to filter data in a object graph (http://wiki.codehaus.org/groovy/PathExpressionLanguage) . I like the way it is done personnaly. Up to now Groovy is not in my opinion ready to be used with geotools (but in a near future I hope), but we could take some ideas form this language.
But I like the string subsitution too ;) like before expressed :
String filterExpression = "(myType.myAttribute >= ${aValue}) or (myOtherType.myOtherAttribute range ${aRange})";
//use of the JDK5 variable lenght list of parameters
aFilter = FilterFactory.readFrom(filterExpression,aValue, aRange);

regards
Xavier
ps : a quite good object oriented parser builder link : http://sablecc.org/features.html

Jody Garnett a écrit :
Xavier Méhaut wrote:

Hello,
I've a question regarding the expressions in geotools which are quite verbose. Is there a means to express filter expressions in a more concise way like for instance :
String filterExpression = "(myType.myAttribute >= aValue) and (myOtherType.myOtherAttribute range 100..300)";

Don't talk to the elves for they will tell you both yes and no ...

No: OGC Filters don't let you work with two feature types at once, indeed what would you expect your example to return?
Yes: with a little work, you can do what you want - this is part of ongoing RnD usually refered to as "Joins" (insert scary music here, sounds of developers screaming etc...).

Here is you answer without explaination - several links follow if you want to find out more.

Expr expr = Exprs.attribute( "myType.myAttribute" ).gt( aValue ).and( Exprs.attribute("myOtherType.myOtherAttribute").between( 100, 300 ) );

FeatureReader reader = myType.getFeatures().reader();
while( reader.hasNext() ){
 Feature feature = reader.next();
 Expr expr2 = expr.resolve( "myType", feature );
 Expr expr3 = expr2.reduce( "myOtherType" );
 Filter filter = expr3.filter( myOtherType.getSchema() );
 FeatureReader reader2 = myOtherType.getFeatures(  filter  ).reader();
 while( reader2.hasNext() ){
   Feature feature2 = reader2.next();
   // the information you were looking for are in feature1 and feature 2
 }
}

Have a look at the experimental expression module. I would love any feed back you have to offer. There is an RnD page on the wiki about this subject (http://docs.codehaus.org/display/GEOTOOLS/Expr+Examples).

The code is here http://svn.geotools.org/geotools/trunk/gt/ext/experimental/

There is also, somewhere, a parser that will take in SQL like expressions and turn them into a Filter.

Jody Garnett

--- code example from src/org/geotools/expr/package.html ---

Example Expr:
Exprs.bbox( extent ).and( Exprs.attribute("cost").lt( 50 ) )


Example Filter:
Expression extentExpression =
    factory.createBBoxExpression( bbox );

String geomName = featureType.getDefaultGeometry().getName()
Expression geomExpression =
    factory.createAttributeExpression( featureType, geomName );       
GeometryFilter disjointExpression =
    factory.createGeometryFilter( GeometryFilter.GEOMETRY_DISJOINT );
disjointExpression.addLeftGeometry( geomExpression );
disjointExpression.addRightGeometry( extentExpression );       
Filter bboxFilter = disjointExpression.not();       
AttributeExpression costExpression =
    factory.createAttributeExpression( featureType, "cost" );
    
CompareFilter lessThanFilter =
    factory.createCompareFilter( CompareFilter.COMPARE_LESS_THAN );
lessThanFilter.addLeftValue( costExpression );
lessThanFilter.addRightValue( factory.createLiteralExpression( 50 ) );       
LogicFilter filter = factory.createLogicFilter( bboxFilter, lessThanFilter, LogicFilter.LOGIC_AND);




--
Get Thunderbird