我有以下代码:
String shapeFileZipPath = "path/to/shapefile-test.zip";
File file = new File(shapeFileZipPath);
Map<String, Serializable> map = new HashMap();
map.put("url", file.toURI().toURL());
ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
ShapefileDataStore dataStore = (ShapefileDataStore) dataStoreFactory.createDataStore(map);
System.out.println(dataStore);
当我运行该程序时,我得到:
shapefile-test.zip is not one of the files types that is known to be associated with a shapefile
当我使用 mac 的 zip 存档实用程序解压该文件时,它会解压到一个包含六个文件(.prj、.shp、.shx、.dbf、.qmd、.cpg)的文件夹。
因此,出现此错误的原因是 zip 根级别有一个文件夹,而 ShapefileDataStoreFactory 需要根级别的这六个文件。
注意:我使用“zip -j ...”命令创建 zip。