【发布时间】:2020-06-05 21:33:18
【问题描述】:
我需要按他们的几何区域遍历已排序的 SimpleFeatureCollection。
我发现经典的 SimpleFeatureIterator 未排序,并且存在一个 SortedFeatureIterator( SimpleFeatureIterator iterator, SimpleFeatureType schema,SortBy[] sortBy, int maxFeatures) 对象,我试过了使用。
这个 sortBy 对象需要一个 PropertyName,我猜它必须由 FilterFactory 生成。 这是我的问题:我找不到如何设置此属性以使用函数运行。我发现org.opengis.filter.expression.Function是存在的,比如org.opengis.filter.expression.Function.AreaFunction比较合适。但是由于 PropertyName 和 AreaFunction 都扩展了 org.opengis.filter.expression.Expression 接口,我找不到将函数放入的方法SortBy 对象。我尝试了几件事并查看了,但没有找到解决方案。
有什么想法吗?我是否有正确的思维方式,我是否错过了拯救方法?非常感谢你的帮助。
PS:区域不是我收藏的一个属性(虽然这是一个肮脏的黑客解决方案,但我尽量避免它们......)
代码示例:
SimpleFeatureIterator sfcIt = sfc.features();
FilterFactory2 ff = FeatureUtilities.DEFAULT_FILTER_FACTORY;
Function function = new AreaFunction();
//first intention
SortBy[] s = {ff.sort(function.toString(), SortOrder.ASCENDING)};
//second intention
Expression expr = ff.function(function.toString(), ff.property("the_geom"));
//desperate intention
final PropertyName propertyName = (PropertyName) function; //utopic
final PropertyName propertyName = ff.arithmeticOperators(true, function); //that isn't the same function object...
SortBy[] sort = { new SortByImpl(expr, SortOrder.ASCENDING) };
SortBy[] sort = { new SortByImpl(propertyName, SortOrder.ASCENDING) };
SortedFeatureIterator sfcIter = new SortedFeatureIterator(sfcIter, sfc.getSchema(), sort, sfc.size());
感谢您的意见! 马克西姆·科伦布
【问题讨论】:
标签: java geotools filterfactory