Select to view content in your preferred language

How to import an geodatabase to my Android project

7600
15
03-31-2014 05:20 AM
zijianzhu
Deactivated User
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
Deactivated User
This sample demonstrates the services pattern for generating a runtime geodatabase from a feature service.


Yes, but the server 10.0 do not have the "synchronize replica " option and "Create Replica " option. I have tried but failed, can not generate local geodatabase.

Zijian
0 Kudos
LisandroRueckert
Deactivated User
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));




This is valid for the Java Runtime too ? It only will work with .geodatabase file ?
0 Kudos
sarahzohar
Deactivated User
I need more information about this topic
0 Kudos
sarahzohar
Deactivated User
Are you sure our clients are using the 10.0 server and I do not know if the update will be the clients.
0 Kudos
sarahzohar
Deactivated User
I think! This is a temporary fix to get your mxd files working.
0 Kudos
LukeCatania
Occasional Contributor
My code crashed at

Geodatabase geodatabase = new Geodatabase(gdbPath);

with error java.io.FileNotFoundException: /ArcGIS/TEC/LocalNetwork/Obstacles/data/test.geodatabase does not exist.

My MXD contains one polygon feature class.  When I run the create runtime content tool and I have a .geodatabase file, but nothing else. I have created runtime content for a network and open and solve on that that with no issue, but there is also a .tn directory that contains the network.  Where are the obstacle data stored?  is it in the .geodatabase file?  That is only Kilobytes in size. 

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