I have following code:
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);
Whne I run this program, I get:
shapefile-test.zip is not one of the files types that is known to be associated with a shapefile
When I unizip the file using mac's zip archive utility,it unzips to a folder containing six files(.prj, .shp,.shx,.dbf,.qmd,.cpg).
So it this error due ot the fact that there is a folder at root level of zip, while ShapefileDataStoreFactory needs those six files at root level.
Note: I create zip using 'zip -j...' command.
GeoTools doesn't handle zipped shapefiles, point the datastore at the .shp
file or a shp.gz
and it should be fine.
Note you should probably use theUrls.toUrl
method to make the URL