在学校,我必须创建一个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)
数据存储区不希望被创建,我不知道它来自哪里...... 你能帮我吗 ? 提前谢谢..
洛尔
答案 0 :(得分:5)
这似乎是GeoTools中的一个已知问题,请参阅FactoryRegistry Refactoring for Java 9 Compatibility。从问题:
TL; DR:
org.geotools.factory.FactoryRegistry
扩展javax.imageio.spi.ServiceRegistry
,但在Java 9上,如果由非JDK类扩展,则后者抛出异常;这打破了Java 9上的GeoTools
您需要将GeoTools版本升级到Java 9兼容(首选),或将Java“降级”为Java 8.