Question

I'm developing wfs application using Geotools.I'm using compare filter object for my wfs feature attribute filtering. For example Shape_Area > 0 or CITY ="ANKARA" query works fine but if I define another filter problems come out.

System.out.println("type name:"+data.getTypeNames()[3]);
features = data.getFeatureSource(data.getTypeNames()[3]);
//count features
col = features.getFeatures();
System.out.println("# All feature's count= "+col.size());
//create the filter
filter = filterFactory.createCompareFilter(CompareFilter.COMPARE_GREATER_THAN);
FeatureType featureType = features.getFeatures().getSchema();
filter.addLeftValue(filterFactory.createAttributeExpression("Shape_Area"));
filter.addRightValue(filterFactory.createLiteralExpression(100000));
//count filtered features
col = features.getFeatures(filter);
System.out.println("# Filtered results "+col.size());

Another filter(filter2) defination code sample

 filter2 =filterFactory.createCompareFilter(CompareFilter.COMPARE_EQUALS);
 filter2.addLeftValue(filterFactory.createAttributeExpression("CITY"));
 filter2.addRightValue(filterFactory.createLiteralExpression("ANKARA"));

Getting results with multiple filter

col = features.getFeatures(filter.and(filter2));

Where am I doing wrong?

Was it helpful?

Solution

You must be using a really old copy of GeoTools - I have not seen the filter.and(filter2) use since we made the filter interfaces immutable in GeoTools 2.3?

Can you try setting this up using filter factory all the way:

filter = ff.and(
  ff.greater( ff.property("Shape_Area"), ff.literal(100000)),
  ff.equal( ff.property("CITY"), ff.literal("ANKARA"));

Or using CQL:

filter = CQL.toFilter(" Shape_Area > 100000 AND CITY = 'ANKARA'")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top