整理几种Geotools操作矢量文件模糊查找数据

根据fid查询

FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();

Set fids = new HashSet<>();
fids.add(ff.featureId("road.1"));
fids.add(ff.featureId("road.2"));

Filter filter = ff.id(fids);
SimpleFeatureCollection result = featureSource.getFeatures(filter);

指定某个参数,使用FilterFactory2 

FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Filter filter = ff.equals(ff.property("NAME"), ff.literal("道路"));
SimpleFeatureCollection result = featureSource.getFeatures(filter);

使用CQL适应多个参数查询

//1、如sql写法
Filter filter = CQL.toFilter("DWMC like '%医院%' and GXR = 'admin'");
//Filter filter = CQL.toFilter("DWMC like '%医院%' or GXR = 'admin'");
SimpleFeatureCollection result = featureSource.getFeatures(filter);

//2、建议写法
List filters= CQL.toFilterList("DWMC like '%医院%';GXR = 'admin'");
//且 
Filter filter = ff.and(filters);
//或
//Filter filter = ff.or(filters);
SimpleFeatureCollection result = featureSource.getFeatures(filter);
还有许多未曾深入挖掘的官方函数,用到再记录



你可能感兴趣的:(JAVA)