How to import an geodatabase to my Android project

6985
15
03-31-2014 05:20 AM
zijianzhu
New Contributor
Hello,
   I'm now beginning with an Android SIG project. However, I could not import my file of geodatabase to my project.

                Geodatabase geodatabase = null;

  File file = new File("/sdcard/geodatabase/GDB_Test.gdb");
  try {
   geodatabase = new Geodatabase("/sdcard/geodatabase/GDB_Test.gdb");
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   if (geodatabase != null)
    this.addressText.setText("ok");
   else if (file.exists())
    this.addressText.setText("can not read");
   else
    this.addressText.setText("nothing");

  }

  if (geodatabase != null) {
   for (GeodatabaseFeatureTable gdbFeatureTable : geodatabase
     .getGeodatabaseTables()) {
    if (gdbFeatureTable.hasGeometry())
     mMapView.addLayer(new FeatureLayer(gdbFeatureTable));
   }
  }


   There is always an exception and TextField shows "can not read". I've tried several files of geodatases but the results are the same.
    Thanks for helping
0 Kudos
15 Replies
zijianzhu
New Contributor
I tried to download the code from official tutorial website, the sample of code is "Offline routing". But it tells there are fatal error when I execute, I have already put the external files to the right path.

04-01 10:16:15.957: E/AndroidRuntime(30844): java.lang.UnsatisfiedLinkError: Couldn't load runtimecore_java from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.esri.arcgis.android.samples.offlineroutingandgeocoding-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.esri.arcgis.android.samples.offlineroutingandgeocoding-1, /vendor/lib, /system/lib]]]: findLibrary returned null

04-01 10:16:15.957: E/AndroidRuntime(30844):  at java.lang.Runtime.loadLibrary(Runtime.java:358)

Thank you for help
0 Kudos
LisandroRueckert
New Contributor II
I tried to download the code from official tutorial website, the sample of code is "Offline routing". But it tells there are fatal error when I execute, I have already put the external files to the right path.

04-01 10:16:15.957: E/AndroidRuntime(30844): java.lang.UnsatisfiedLinkError: Couldn't load runtimecore_java from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.esri.arcgis.android.samples.offlineroutingandgeocoding-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.esri.arcgis.android.samples.offlineroutingandgeocoding-1, /vendor/lib, /system/lib]]]: findLibrary returned null

04-01 10:16:15.957: E/AndroidRuntime(30844):  at java.lang.Runtime.loadLibrary(Runtime.java:358)

Thank you for help


Are you using eclipse plugin ?
try to excute the 'Add Application toolkit' and Fix Project Properties from  the ArcGis Tools of project context menu.
0 Kudos
LisandroRueckert
New Contributor II
Hi,

I have the same problem. My code is below.
A  java.lang.RuntimeException with message "Disk I/O error" is throwed when the Geodatabase is instantiated.


String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() ;
        dir = dir +"/teste/RH_SampleData.gdb";
        File f = new File(dir);
        if (f.exists())
        try {           
  geodatabase = new Geodatabase(dir);
  //get the geodatabase feature table
  geodatabaseFeatureTable = geodatabase.getGeodatabaseFeatureTableByLayerId(0);
  //create a feature layer
  FeatureLayer featureLayer = new FeatureLayer(geodatabaseFeatureTable);
  mMapView.addLayer(featureLayer);
        }
        catch (Exception e) {       
         Log.v("XXX","Erro ao abrir mapa",e);
        }
0 Kudos
RobertBurke
Esri Contributor
Hi Zijian and Lisandro,

In your examples, are you using file geodatabases? 
GDB_Test.gdb (Zijian)
RH_SampleData.gdb (Lisandro).

When using a geodatabase locally on an Android device you need to use a runtime geodatabase.

For a quick test or example, You could create runtime content using ArcMap.  On ArcMap's File menu, point to Share as, and click Runtime content. There is a bit more to it than just clicking a menu choice.  You can read more about the workflows here:

http://resources.arcgis.com/en/help/main/10.2/index.html#//00660000045q000000

ArcMap creates a .geodatabase file, that you can place on the Android device. 

For example, using a file browser I copied the output city.geodatabase onto my phone's sd card.  Then in Eclipse using the DDMS perspective you can see the file on the device and learn the folder names for the sd card.  In code I make a variable to reference that location:

String gdbPath = "/storage/extSdCard/ArcGISApp/city.geodatabase";

//In a try...catch I create a Geodatabase object and use the path.

Geodatabase geodatabase = new Geodatabase(gdbPath);

//From there you can get FeatureTables by their index position.  This line gets the first table using 0 as the index.

GeodatabaseFeatureTable geodatabaseFeatureTable = geodatabase.getGeodatabaseFeatureTableByLayerId(0);

//You can then use the table to create a feature layer and add the layer to the map.
FeatureLayer featureLayer = new FeatureLayer(geodatabaseFeatureTable);
mMapView.addLayer(featureLayer);

Please check out this page for more details on the patterns of working with offline data:

https://developers.arcgis.com/android/guide/create-an-offline-map.htm

Please let me know if this helps.
0 Kudos
LisandroRueckert
New Contributor II
HI,

Yes. I was try to using file geodatabases. I thought that .geodatabase was only a newer version of .gdb that came with 10.2.2 🙂
Using .geodatabase it works fine.

Thank you.

Lisandro
0 Kudos
EdwardLin
New Contributor II
The *.gdb file is for ArcGIS desktop, not for android. If you want to use vector data in android, you have to convert it to *.geodatabase.
(1)In ArcGIS Desktop 10.2.2, open *.gdb file, use runtime content to convert to *.geodatbase.
(2)Put the *.geodatbase in the android card.
Geodatabase localGdb = new Geodatabase( geodatabasePath);
    for (GeodatabaseFeatureTable gdbFeatureTable : localGdb.getGeodatabaseTables()) {
      if (gdbFeatureTable.hasGeometry())
      map.addLayer(new FeatureLayer(gdbFeatureTable));
0 Kudos
sarahzohar
New Contributor
I read a lot of postings in this topic and i want to find exact this type of topic. so, thanks
0 Kudos
zijianzhu
New Contributor
Hi Zijian and Lisandro,

In your examples, are you using file geodatabases? 
GDB_Test.gdb (Zijian)
RH_SampleData.gdb (Lisandro).

When using a geodatabase locally on an Android device you need to use a runtime geodatabase.

For a quick test or example, You could create runtime content using ArcMap.  On ArcMap's File menu, point to Share as, and click Runtime content. There is a bit more to it than just clicking a menu choice.  You can read more about the workflows here:

http://resources.arcgis.com/en/help/main/10.2/index.html#//00660000045q000000

ArcMap creates a .geodatabase file, that you can place on the Android device. 

For example, using a file browser I copied the output city.geodatabase onto my phone's sd card.  Then in Eclipse using the DDMS perspective you can see the file on the device and learn the folder names for the sd card.  In code I make a variable to reference that location:

String gdbPath = "/storage/extSdCard/ArcGISApp/city.geodatabase";

//In a try...catch I create a Geodatabase object and use the path.

Geodatabase geodatabase = new Geodatabase(gdbPath);

//From there you can get FeatureTables by their index position.  This line gets the first table using 0 as the index.

GeodatabaseFeatureTable geodatabaseFeatureTable = geodatabase.getGeodatabaseFeatureTableByLayerId(0);

//You can then use the table to create a feature layer and add the layer to the map.
FeatureLayer featureLayer = new FeatureLayer(geodatabaseFeatureTable);
mMapView.addLayer(featureLayer);

Please check out this page for more details on the patterns of working with offline data:

https://developers.arcgis.com/android/guide/create-an-offline-map.htm

Please let me know if this helps.



Thanks, that is the reason. Our company are currently using ArcGIS serveur 10.0 and I do not know if we can update to 10.2 for free or not. In fact our clients are using the server 10.0 and I do not know if the update will block the clients. If it blocks the clients, I do not think our manager will do it for this Android Project, so that we can not use the offline edit and synchonization of geodatabase. Is there any solution to use these functions without update the ArcGIS server?

Sincerely

ZHU Zijian
0 Kudos
DanO_Neill
Occasional Contributor III
Is there any solution to use these functions without update the ArcGIS server?


This sample demonstrates the services pattern for generating a runtime geodatabase from a feature service.
0 Kudos