I use the ArcObjects 10.2 API for Java and I reported several incoherences between the API documentation and what I'm experiencing, especially regarding File GDB relative interface casts:
- The IFeatureClass objects are not castable to IFeatureClassLoad (needed to load data faster) unlike what it's written in the documentation: http://help.arcgis.com/en/sdk/10.0/java_ao_adf/api/arcobjects/com/esri/arcgis/geodatabase/IFeatureCl...
- The IWorkspace object is not castable to IWorkspace2 (needed to check name existence). I get that com.esri.arcgis.geodatabase.IWorkspaceProxy cannot be cast to com.esri.arcgis.geodatabase.IWorkspace2. However, the documentation says it's for Geodatabase and shapefiles: IWorkspace2 (ArcObjects Java API).
More about how I create or open my file geodatabases, maybe the solution is here:
// creation IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory(); IWorkspaceName workspaceName = workspaceFactory.create(parentDirectory, gdbName, null, 0); IName name = (IName)workspaceName; IWorkspace workspace = new IWorkspaceProxy(name.open()); // opening IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory(); IWorkspace workspace = workspaceFactory.openFromFile(gdbPath, 0); // feature class creation String geometryShapeFieldName = "Shape"; GeometryDef geometryDef = new GeometryDef(); geometryDef.setGeometryType(geometryType); geometryDef.setSpatialReferenceByRef(spatialReference); Field idField = new Field(); idField.setName("OBJECTID"); idField.setAliasName("OBJECTID"); idField.setType(esriFieldType.esriFieldTypeOID); Field geometryShapeField = new Field(); geometryShapeField.setName(geometryShapeFieldName); geometryShapeField.setType(esriFieldType.esriFieldTypeGeometry); geometryShapeField.setGeometryDefByRef(geometryDef); Fields fields = new Fields(); fields.addField(idField); fields.addField(geometryShapeField); IFeatureClassDescription fcDesc = new FeatureClassDescription(); IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc; IFeatureWorkspace featureWorkspace = new IFeatureWorkspaceProxy(workspace); IFeatureDataset featureDataset = featureWorkspace.openFeatureDataset(name); IFeatureClass featureClass = featureDataset.createFeatureClass(featureClassName, fields, ocDesc.getInstanceCLSID(), ocDesc.getClassExtensionCLSID(), esriFeatureType.esriFTSimple, geometryShapeFieldName, ""); // feature class opening IGPUtilities gpUtilities = new GPUtilities(); IFeatureClass featureClass = gpUtilities.openFeatureClassFromString(featureClassFullPath); boolean exists = ((IWorkspace2)workspace).isNameExists(esriDatasetType.esriDTFeatureClass, name); // don't work, cast exception IFeatureClassLoad featureClassLoad = (IFeatureClassLoad)featureClass; // don't work either featureClassLoad.setLoadOnlyMode(true);
Writing this question, I found a solution: it was at the creation of the workspace, we don't have to call the IWorkspaceProxy constructor but the Workspace() constructor:
IWorkspace workspace = new Workspace(name.open());
After doing this modification, it solves the IWorkspace2 cast problem, good news.
So, it seems there is an error in the ArcObjects Java documentation I initially followed: http://help.arcgis.com/en/sdk/10.0/java_ao_adf/conceptualhelp/engine/index.html#/How_to_create_new_g... in the Creating a file geodatabase workspace paragraph.
Anyway, this modification didn't solve the IFeatureClassLoad cast error. So, I also changed the way I open feature classes by:
featureWorkspace.openFeatureClass(featureClassName);
but the error is still here.
Any idea?