のコード例はここにあります: 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;
ありがとう、DNA。実際にはこのコレクションを変更する必要があります(特定のプロパティを変更して既に処理済みのポイントをマークする必要があります)。私はちょっと分かりました、私が欲しいものをする方法、それはちょうどとても醜いように見えます。基本的には、私は新しいコレクションを作成し、イテレータを上書きします。とにかくありがとう、とにかく – porter
ハッシュセットで既にヒットした機能の機能IDを記録するだけです。注意GeoToolsは、少量のデータで作業していることがわかっている場合は、リストにフィーチャーをコピーすると、大量のデータを処理できるように、このように構成されています。 –