3

I recently found an issue with Geotools and getting the datastore for a shapefile.

If I try:

FileDataStore dataStore = FileDataStoreFinder.getDataStore(file);

-or-

Map connect = new HashMap();
connect.put("url", file.toURL());

DataStore dataStore = DataStoreFinder.getDataStore(connect);

getDataStore() always returns null. But using:

ShapefileDataStore dataStore = new ShapefileDataStore(file.toURI().toURL());

then the dataStore is set to the shapefile. Anyone have any ideas why this is? Is this a bug with Geootools 8.2? I'm running Geotools on Tomcat 7, perhaps there is some issue with Tomcat and the DataStore and FileDataStore classes?

Thanks!

  • 1
    can you add what file actually contains? I suspect either it doesn't end .shp or it contains spaces and is not being encoded correctly – Ian Turton Sep 24 '12 at 8:35
1

Check your class path, it might miss the jars that are able to read the shape file:

Check the availabel DataStores:

Iterator availableStores =  DataStoreFinder.getAvailableDataStores();
LOGGER.info("List available Stores: {");
            while (availableStores.hasNext()) {
                LOGGER.info(availableStores.next().toString());
            }
LOGGER.info("}");

if the List is empty, then the necessary jar is missing in the classpath.

In my case, using an old version of geotools, I had to add the gt2-shapefile-2.3.2 to the classpath

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.