1

出于性能原因,我遵循了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。

出了什么问题?

谢谢

迈克尔

4

1 回答 1

1

Not a solution to your problem but the reason:

Extract from SpatialIndexFeatureCollection.java:

public SimpleFeatureCollection subCollection(Filter filter) {
    throw new UnsupportedOperationException();
}

I guess this method is not yet implemented.

Edit: What I did was the following:

    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();
于 2013-06-20T08:28:07.147 回答