我遵循http://docs.geotools.org/latest/userguide/library/main/collection.html#performance-options的建议,出于性能原因使用SpatialIndexFeatureCollection。
呈现要素时,将抛出UnsupportedOperationException。
图层初始化如下
File shpFile = ...;
FileDataStore dataStore = FileDataStoreFinder.getDataStore(shpFile);
SimpleFeatureSource featureSource = dataStore.getFeatureSource();
SpatialIndexFeatureCollection collection = new SpatialIndexFeatureCollection(featureSource.getSchema());
collection.addAll(featureSource.getFeatures());
FeatureLayer layer = new FeatureLayer
( new SpatialIndexFeatureSource(collection)
, ... // create SLD here
, "Title");
抛出的异常是
06.06.2013 13:04:56 org.geotools.renderer.lite.StreamingRenderer fireErrorEvent
SCHWERWIEGEND: null
java.lang.UnsupportedOperationException
at org.geotools.data.collection.SpatialIndexFeatureCollection.subCollection(SpatialIndexFeatureCollection.java:128)
at org.geotools.data.collection.SpatialIndexFeatureSource.getFeatureCollection(SpatialIndexFeatureSource.java:142)
at org.geotools.data.collection.SpatialIndexFeatureSource.getFeatures(SpatialIndexFeatureSource.java:115)
at org.geotools.data.collection.SpatialIndexFeatureSource.getFeatures(SpatialIndexFeatureSource.java:65)
at org.geotools.renderer.lite.StreamingRenderer.processStylers(StreamingRenderer.java:2023)
at org.geotools.renderer.lite.StreamingRenderer.paint(StreamingRenderer.java:829)
at org.geotools.swt.SwtMapPane.handleEvent(SwtMapPane.java:1186)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
at org.eclipse.swt.widgets.Composite.WM_PAINT(Composite.java:1564)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4585)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4976)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2546)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3756)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at de.viate.matiyari.rcp.ui.application.DefaultApplication.start(DefaultApplication.java:158)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Geotools版本是9.2。
出了什么问题?
谢谢
迈克尔
答案 0 :(得分:1)
不是您问题的解决方案,但原因是:
从SpatialIndexFeatureCollection.java中提取:
public SimpleFeatureCollection subCollection(Filter filter) {
throw new UnsupportedOperationException();
}
我猜这个方法还没有实现。
编辑: 我做的是以下内容:
File = ...;//the shapefile
Map<Object, Object> map = new HashMap<>();
map.put( "url", file.toURI().toURL() );
DataStore dataStore = DataStoreFinder.getDataStore(map);
List<Name> names = dataStore.getNames();
SimpleFeatureSource featureSource = dataStore.getFeatureSource(names.get(0));
SimpleFeatureCollection collection = featureSource.getFeatures(filter);
SpatialIndexFeatureCollection spatialCollection = new SpatialIndexFeatureCollection(collection);
// Fast spatial Access
SimpleFeatureSource source = DataUtilities.source( spatialCollection );
SimpleFeatureCollection features = source.getFeatures();
// use features.features();