AnsweredAssumed Answered

How to read shape file from sd card on Android?

Question asked by geronimostudios on Nov 21, 2016
Latest reply on Nov 25, 2016 by geronimostudios

I was trying to display some geometry from a shapefile in Android and I ran into this exception when trying to create a
ShapeFileFeatureTable using a path on the sd card:

 java.lang.RuntimeException: Shape file not found: /storage/emulated/0/stations.shp
at com.esri.core.geodatabase.Geodatabase.nativeOpenShapefile(Native Method)
at com.esri.core.geodatabase.Geodatabase.a(SourceFile:126)
at com.esri.core.geodatabase.ShapefileFeatureTable.<init>(SourceFile:79)

I've tried with different paths and with and without the first '/' and haven't managed to fix this error. The file exists on the
sd card and can be read by the app as Geodatabase.a() checks if the file exists and throws a FileNotFoundException otherwise.

This is the source code I'm using (the full project and shape file are also attached):

File esd = Environment.getExternalStorageDirectory();
//        String path = esd.getPath() + "/stations.shp";
String path = "/storage/emulated/0/stations.shp";
Log.w("shp path", "path " + path);
ShapefileFeatureTable shpFile = null;
try {
   shpFile = new ShapefileFeatureTable(path);
   if (shpFile != null) {
       Envelope env = shpFile.getExtent();
       if (env != null) {
           Log.w("read shape", env.getWidth() + "x" + env.getHeight());
} catch (FileNotFoundException e) {

Can anyone please tell me if i'm doing something wrong or if the shape file is not valid. Also is there any other way to display 
Geometry objects from shape files? Any help will be appreciated.

Thank you,