Geotools FeatureCollectionのドキュメントを見ると、パフォーマンス オプションのサブセクションに次のように記載されています。
TreeSetFeatureCollection: デフォルトで使用される従来の TreeSet 実装。
コンテンツがインデックス化されていないため、これは空間クエリではうまく機能しないことに注意してください。
後で、SpatialIndexFeatureCollection
クエリを高速化するために次のことをお勧めします。
SpatialIndexFeatureCollection: 空間インデックスを使用してコンテンツを保持し、MapLayer で高速に視覚的に表示します。一度使用すると、この機能コレクションにコンテンツを追加することはできません
DataUtilities.source( featureCollection ) は、空間インデックスを利用できる SpatialIndexFeatureSource で SpatialIndexFeatureCollection をラップします。
与えられた例は次のとおりです。
final SimpleFeatureType TYPE =
DataUtilities.createType("location","geom:Point,name:String");
WKTReader2 wkt = new WKTReader2();
SimpleFeatureCollection collection = new SpatialIndexFeatureCollection();
collection.add( SimpleFeatureBuilder.build( TYPE, new Object[]{ wkt.read("POINT(1,2)"), "name1"} ));
collection.add( SimpleFeatureBuilder.build( TYPE, new Object[]{ wkt.read("POINT(4,4)"), "name1"} ));
// Fast spatial Access
SimpleFeatureSource source = DataUtilities.source( collection );
SimpleFeatureCollection features = source.getFeatures( filter );
このコードをコンパイルできないことに加えて (SimpleFeatureCollection
はインターフェースであり、メンバーを含まない)、次のように定義されている直接呼び出しadd
のコードSpatialIndexFeatureSource.getFeatures(Filter)
SpatialIndexFeatureCollection.subCollection(Filter)
public SimpleFeatureCollection subCollection(Filter filter) {
throw new UnsupportedOperationException();
}
これは、これを使用する私自身の試みの例です
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
SimpleFeatureCollection answers = getAnswers();
SpatialIndexFeatureCollection collection = new SpatialIndexFeatureCollection();
collection.addAll(answers);
SimpleFeatureSource source = DataUtilities.source( collection );
SimpleFeatureCollection gridCollection = getGridCollection();
SimpleFeatureIterator iter = gridCollection.features();
while(iter.hasNext()) {
SimpleFeature grid = iter.next();
Geometry gridCell = (Geometry) grid.getDefaultGeometry();
Filter gridFilter = ff.intersects(ff.property("geometry"), ff.literal(gridCell));
SimpleFeatureCollection results = source.getFeatures(combinedFilter);
}
当然のことながら、これによりUnsupportedOperationException
私はこの例を機能させることができず、空間インデックスを利用したいと思っています。SpatialIndexFeatureCollection
上記の例に似たものをどのように使用すればよいですか?