Geotools wfs插件使用多个过滤器

时间:2014-01-17 11:19:57

标签: java plugins filtering geotools

我正在使用Geotools开发wfs应用程序。我正在使用比较过滤器对象来进行我的wfs特征属性过滤。例如,Shape_Area> 0或CITY =“ANKARA”查询工作正常但如果我定义了另一个过滤器问题就出来了。

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());

另一个过滤器(filter2)定义代码示例

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

使用多个过滤器获得结果

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

我在哪里做错了?

1 个答案:

答案 0 :(得分:0)

您必须使用GeoTools的旧版本 - 我没有看过filter.and(filter2),因为我们在GeoTools 2.3中使过滤器接口不可变?

您可以尝试使用过滤器工厂进行设置:

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

或使用CQL:

filter = CQL.toFilter(" Shape_Area > 100000 AND CITY = 'ANKARA'")