例如,数据库是表示在SpatialIndexFeatureCollection中保存的城市的居民区的MultiPolygons。传入的请求数据是包含表示例如建筑物的MultiPoint对象的shapefile。我们的目标是返回至少包含n个输入数据点的所有多多边形。
在没有最低要求的情况下,我们有一个可行的解决方案,通过使用FilterFactory2.d()作为过滤器来查询集合,并将多点拆分为一组点作为输入,以创建一个SimpleFeatureCollection。但是,这种方法只返回一次找到的多多边形。因此,我们不能通过出现的次数来过滤结果。单独过滤每个点的集合似乎效率很低。
有没有办法处理多点和多多边形之间的交集?
发布于 2021-01-20 21:32:51
听起来好像您需要依次查询每个多边形的points集合,并保留返回集合大于N的那些多边形。
int N = 3;
FileDataStore pointsDS = new ShapefileDataStore(URLs.fileToUrl(new File("/data/natural_earth/110m_cultural/110m_populated_places.shp")));
FileDataStore polyDS = new ShapefileDataStore(URLs.fileToUrl(new File("/data/natural_earth/110m_cultural/110m_admin_0_countries.shp")));
SimpleFeatureCollection points = pointsDS.getFeatureSource().getFeatures();
SimpleFeatureCollection polys = polyDS.getFeatureSource().getFeatures();
FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2();
Expression propertyName = filterFactory.property(points.getSchema()
.getGeometryDescriptor().getName());
ArrayList<SimpleFeature> results = new ArrayList<>();
try(SimpleFeatureIterator itr = polys.features()){
while (itr.hasNext()) {
SimpleFeature poly = itr.next();
Filter filter = filterFactory.within(propertyName, filterFactory.literal(poly.getDefaultGeometry()));
SimpleFeatureCollection sub = points.subCollection(filter);
if(sub.size()>N){
results.add(poly);
}
}
}
for(SimpleFeature f:results){
System.out.println(f.getAttribute("NAME"));
}https://stackoverflow.com/questions/65807785
复制相似问题