Select to view content in your preferred language

How to access .GDB folder on local machine from JAVA Runtime API?

1242
2
12-16-2021 12:41 AM
RobertSchweikert
Emerging Contributor

Hi, I want to access a local .gdb folder from the java runtime API. Is it possible to do it directly, if no then what is to be done? I'm using the below code to access the GDB file(folder). I also tried putting the GDB into a zip file but the result was same:

 

File geodatabaseFile = new File("C:\\Users\\gaura\\Desktop\\GeoDBSamples\\Delemont_ele" +
".gdb");
Geodatabase geodatabase = new Geodatabase(geodatabaseFile.getAbsolutePath());
geodatabase.loadAsync();
System.out.println(geodatabase.getInternal().getLoadStatus().name());

geodatabase.addDoneLoadingListener(() -> {
System.out.println("Loading GDB...");
});

while (geodatabase.getLoadStatus() != LoadStatus.LOADED) {
if (geodatabase.getLoadStatus() == LoadStatus.FAILED_TO_LOAD || geodatabase.getLoadStatus() == LoadStatus.NOT_LOADED) {
break;
}
}

System.out.println("GDB Loading Status: " + geodatabase.getLoadStatus());

if (null != geodatabase.getLoadError()) {
System.out.println("GDB Load Error Cause: " + geodatabase.getLoadError().getMessage());
}


if (geodatabase.getLoadStatus() == LoadStatus.LOADED) {

var tables = geodatabase.getGeodatabaseAnnotationTables();

for (GeodatabaseFeatureTable gdbFT : tables) {
gdbFT.addDoneLoadingListener(() -> {
System.out.println("Loading GeoDB FT...");
});

while (gdbFT.getLoadStatus() != LoadStatus.LOADED) {
if (gdbFT.getLoadStatus() == LoadStatus.FAILED_TO_LOAD || gdbFT.getLoadStatus() == LoadStatus.NOT_LOADED) {
break;
}
}
System.out.println("GDB FT Load Status: " + gdbFT.getLoadStatus());

if (gdbFT.getLoadStatus() == LoadStatus.LOADED) {
System.out.println("Fields GDB FT: " + gdbFT.getFields());
System.out.println("Geometry Type GDB FT : " + gdbFT.getGeometryType());
}
}
}

 Console Output:

 

Loading GDB...
GDB Loading Status: FAILED_TO_LOAD
GDB Load Error Cause: No data.

0 Kudos
2 Replies
MarkBaird
Esri Regular Contributor

It depends on where the gdb came from.  If it's a Runtime geodatabase for offline purposes it will certainly work.

If it's a geodatabase straight from ArcGIS Pro, then you will have issues.

If you explain a little about the workflow you are trying to achieve I'll point you in the right direction.

 

0 Kudos
RobertSchweikert
Emerging Contributor

Hi Mark , I'm not sure about the GDB type that I am going to get in future from my client. I will get that soon. Meanwhile can you tell me how to access it if it is from ArcGIS Pro? Also what kind of GDB should I ask the client for (technical name) if I need to access it directly from the Java API?

0 Kudos