基本主意是为features建立一个空间索引,然后利用该索引快速查找到该feature。
很奇怪的直接通过geotools的api,或者在google上搜索,竟然找不到直接的方法。
偶然的机会发现了一个简单的方法。基本步骤如下:(本文例子使用的是Geotools2.4.4)
dataStore = new ShapefileDataStore(url);
String typeName = dataStore.getTypeNames ()[0];
FeatureSource featureSource = dataStore.getFeatureSource( typeName );
FeatureCollection features = featureSource.getFeatures();
MemorySpatialIndex memSpatialIdx = new MemorySpatialIndex(features);
这样我们就对已经load的features建立了spatial index,当我们要进行空间查询时,以Envelope为参数
用下述方法即可。
//env --Envelope env
List<Feature> features = memSpatialIdx .findFeatures(env);
当然另外一种方式实现spatial index是使用Geotools中提供的RTEE或者QUADTREE,自己建立索引,然后利用
其api执行空间查询,实现起来也很简单,此处就不赘述。
很奇怪的直接通过geotools的api,或者在google上搜索,竟然找不到直接的方法。
偶然的机会发现了一个简单的方法。基本步骤如下:(本文例子使用的是Geotools2.4.4)
dataStore = new ShapefileDataStore(url);
String typeName = dataStore.getTypeNames ()[0];
FeatureSource featureSource = dataStore.getFeatureSource( typeName );
FeatureCollection features = featureSource.getFeatures();
MemorySpatialIndex memSpatialIdx = new MemorySpatialIndex(features);
这样我们就对已经load的features建立了spatial index,当我们要进行空间查询时,以Envelope为参数
用下述方法即可。
//env --Envelope env
List<Feature> features = memSpatialIdx .findFeatures(env);
当然另外一种方式实现spatial index是使用Geotools中提供的RTEE或者QUADTREE,自己建立索引,然后利用
其api执行空间查询,实现起来也很简单,此处就不赘述。