Здесь есть пример кода:
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;