gpt4 book ai didi

java - SHP 打开 : datastore DataStoreFactorySpi is not an ImageIO SPI class

转载 作者:行者123 更新时间:2023-11-29 06:51:10 28 4
gpt4 key购买 nike

在学校,我必须创建一个 API,其中我需要在 shapefile 中包含一些几何图形。我使用 geotools librairie 打开 shapefile。这是我的代码:

public class main {

public static void main(String[] args) throws Exception{
String filepath = "SHP_test/testSHPindex.shp";
File shp = new File(filepath);

Map<String, URL> map = new HashMap<String, URL>();
map.put( "url", shp.toURI().toURL() );
DataStore dataStore = DataStoreFinder.getDataStore(map);


SimpleFeatureSource featureSource = dataStore.getFeatureSource(dataStore.getTypeNames()[0]);
SimpleFeatureCollection collection = featureSource.getFeatures();


}

我得到这个错误:

Exception in thread "main" java.lang.IllegalArgumentException: org.geotools.data.DataStoreFactorySpi is not an ImageIO SPI class
at java.desktop/javax.imageio.spi.ServiceRegistry.checkClassAllowed(ServiceRegistry.java:745)
at java.desktop/javax.imageio.spi.ServiceRegistry.<init>(ServiceRegistry.java:140)
at org.geotools.factory.FactoryRegistry.<init>(FactoryRegistry.java:155)
at org.geotools.factory.FactoryCreator.<init>(FactoryCreator.java:91)
at org.geotools.data.DataStoreFinder.getServiceRegistry(DataStoreFinder.java:128)
at org.geotools.data.DataStoreFinder.getAvailableDataStores(DataStoreFinder.java:115)
at org.geotools.data.DataStoreFinder.getDataStore(DataStoreFinder.java:87)
at org.ensg.projetperso.llb.maven.api.spatialindexingtest.testshapefile.main.main(main.java:30)

不想创建数据存储,我不明白它来自哪里......你能帮我吗 ?提前致谢..

劳拉

最佳答案

这似乎是 GeoTools 中的一个已知问题,请参阅 FactoryRegistry Refactoring for Java 9 Compatibility .来自问题:

TL;DR: org.geotools.factory.FactoryRegistry extends javax.imageio.spi.ServiceRegistry, but on Java 9 the latter throws an exception if extended by non-JDK classes; this breaks GeoTools on Java 9

您需要将您的 GeoTools 版本升级到与 Java 9 兼容的版本(首选),或者将您的 Java“降级”到 Java 8。

关于java - SHP 打开 : datastore DataStoreFactorySpi is not an ImageIO SPI class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47888812/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com