考虑到所需的最小点数,如何通过 MultiPoint 和 MultiPolygon 之间的交集过滤 SpatialIndexFeatureCollection

How to filter SpatialIndexFeatureCollection by intersection between MultiPoint and MultiPolygon considering a min amount of points required

数据库是 MultiPolygons,代表例如 SpatialIndexFeatureCollection 中保存的城市的街区。传入的请求数据是一个 shapefile,其中包含代表建筑物等的 MultiPoint 对象。我们的目标是 return 所有包含至少 n 个输入数据点的多边形。

没有最低要求,我们有一个可行的解决方案,通过使用 FilterFactory2.dwithin() 作为过滤器查询集合,并将多点拆分为一组点作为输入以创建 SimpleFeatureCollection。不过,这种方法每次只找到 returns 一次多面体。因此我们不能按出现次数过滤结果。分别过滤每个点的集合似乎非常低效。

有没有办法处理多点和多面之间的交集?

听起来好像需要依次查询每个多边形的点集合,保留返回集合大于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"));
    }