Reading an ESRI shapefile from a zip-file during Runtime in Java - DataStoreFinder.getDataStore(connectParameters) returns null

痴心易碎 提交于 2019-12-04 03:42:31

Though your code seems correct, I have found a slightly different implementation of the crucial lines in our codebase:

Map<String, Object> map = new HashMap<>();
map.put(ShapefileDataStoreFactory.URLP.key, url);
map.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.TRUE);
DataStore shapefileStore = DataStoreFinder.getDataStore(map);

Just use the constructor of ShapefileDataStore like this:

// URL url = file.toURI().toURL();
DataStore shapefileStore = new ShapefileDataStore(url)

Your code is correct, but your classpath is missing the ShapeFileDataStore. Either fix your class path by adding the e.g: gt2-shapefile-2.3.2.jar

Or directly use

DataStore shapefileStore = new ShapefileDataStore(url)

This has the advanatage that you immedeatly will see, that your code cannot compile, due missing shapefile library.

With

Iterator availableStores =  DataStoreFinder.getAvailableDataStores();

you can output a list of all available data stores. If empty or if there is no ShapefileDataStoreFactory listed, you will know the cause is the classpath.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!