0

SimpleFeatureCollection に対してネストされたループを実行したいと考えています。ポイントごとに、その近隣を見つけて処理する必要があります。

ただし、SimpleFeatureCollection は反復子のみを許可し、配列へのアクセスは許可しないため、ネストされたループを実装することはできません (少なくともそのように見えます)。この反復子には previous() メソッドがないため、リセットして同じコレクションに対して 2 つの反復子を使用することはできません。

そのため、インデックスで機能にアクセスする他の方法があるかどうか疑問に思っていました。

ありがとう

4

2 に答える 2

2

ここにコード例があります:http: //docs.geotools.org/latest/userguide/library/main/collection.html#join

ループをネストする方法を示します。

void polygonInteraction() {
    SimpleFeatureCollection polygonCollection = null;
    SimpleFeatureCollection fcResult = null;
    final SimpleFeatureCollection found = FeatureCollections.newCollection();

    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
    SimpleFeature feature = null;

    Filter polyCheck = null;
    Filter andFil = null;
    Filter boundsCheck = null;

    String qryStr = null;

    SimpleFeatureIterator it = polygonCollection.features();
    try {
        while (it.hasNext()) {
            feature = it.next();
            BoundingBox bounds = feature.getBounds();
            boundsCheck = ff.bbox(ff.property("the_geom"), bounds);

            Geometry geom = (Geometry) feature.getDefaultGeometry();
            polyCheck = ff.intersects(ff.property("the_geom"), ff.literal(geom));

            andFil = ff.and(boundsCheck, polyCheck);

            try {
                fcResult = featureSource.getFeatures(andFil);
                // go through results and copy out the found features
                fcResult.accepts(new FeatureVisitor() {
                    public void visit(Feature feature) {
                        found.add((SimpleFeature) feature);
                    }
                }, null);
            } catch (IOException e1) {
                System.out.println("Unable to run filter for " + feature.getID() + ":" + e1);
                continue;
            }

        }
    } finally {
        it.close();
    }
}

すでにアクセスした機能を無視して、コンテンツをスキップする場合::

HashSet<FeatureId> skip = new HashSet<FeatureId>();
...
if( skip.contains( feature.getId() ) ) continue;
于 2012-11-05T11:37:09.877 に答える
0

一般に、コレクションを変更するのではなく、読み取るだけであれば、コレクションに対して複数のイテレータを使用できます。この質問を参照してください。

SimpleFeatureCollectionルールの例外ではないことを願っています!

ネストされたループの場合、内側のループを実行するたびに別の反復子を作成できます。前のものを「リセット」する必要はありません。

于 2012-03-05T22:30:49.387 に答える