<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Unable to cast several File GDB ArcObjects with Java in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/unable-to-cast-several-file-gdb-arcobjects-with/m-p/158079#M4154</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="java" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14327343436013615 jive_text_macro" data-renderedposition="71_8_912_16" jivemacro_uid="_14327343436013615"&gt;&lt;P&gt;IWorkspace workspace = new Workspace(name.open());&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After doing this modification, it solves the IWorkspace2 cast problem, good news.&lt;/P&gt;&lt;P&gt;So, it seems there is an error in the ArcObjects Java documentation I initially followed: &lt;A href="http://help.arcgis.com/en/sdk/10.0/java_ao_adf/conceptualhelp/engine/index.html#/How_to_create_new_geodatabases/0001000002w4000000/"&gt;http://help.arcgis.com/en/sdk/10.0/java_ao_adf/conceptualhelp/engine/index.html#/How_to_create_new_geodatabases/0001000002w4000000/&lt;/A&gt; in the &lt;STRONG&gt;Creating a file geodatabase workspace paragraph&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, this modification didn't solve the IFeatureClassLoad cast error. So, I also changed the way I open feature classes by:&lt;/P&gt;&lt;PRE __default_attr="java" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14327382612846890 jive_text_macro" data-renderedposition="234_8_912_16" jivemacro_uid="_14327382612846890"&gt;&lt;P&gt;featureWorkspace.openFeatureClass(featureClassName);&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;but the error is still here.&lt;/P&gt;&lt;P&gt;Any idea?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 27 May 2015 13:48:28 GMT</pubDate>
    <dc:creator>KevinLECOCQ</dc:creator>
    <dc:date>2015-05-27T13:48:28Z</dc:date>
    <item>
      <title>Unable to cast several File GDB ArcObjects with Java</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/unable-to-cast-several-file-gdb-arcobjects-with/m-p/158078#M4153</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- The IFeatureClass objects are not castable to IFeatureClassLoad (needed to load data faster) unlike what it's written in the documentation: &lt;A href="http://help.arcgis.com/en/sdk/10.0/java_ao_adf/api/arcobjects/com/esri/arcgis/geodatabase/IFeatureClassLoad.htmlhttp://" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/sdk/10.0/java_ao_adf/api/arcobjects/com/esri/arcgis/geodatabase/IFeatureClassLoad.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- 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: &lt;A href="http://help.arcgis.com/EN/sdk/10.0/Java_AO_ADF/api/arcobjects/com/esri/arcgis/geodatabase/IWorkspace2.html" title="http://help.arcgis.com/EN/sdk/10.0/Java_AO_ADF/api/arcobjects/com/esri/arcgis/geodatabase/IWorkspace2.html" rel="nofollow noopener noreferrer" target="_blank"&gt;IWorkspace2 (ArcObjects Java API)&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;More about how I create or open my file geodatabases, maybe the solution is here:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;// creation
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
&amp;nbsp; IWorkspaceName workspaceName = workspaceFactory.create(parentDirectory, gdbName, null, 0);
&amp;nbsp; IName name = (IName)workspaceName;
&amp;nbsp; 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);
&lt;SPAN style="line-height: 1.5;"&gt;Fields fields = new Fields();&lt;/SPAN&gt;
fields.addField(idField);
fields.addField(geometryShapeField);
&lt;SPAN style="line-height: 1.5;"&gt;IFeatureClassDescription fcDesc = new FeatureClassDescription();&lt;/SPAN&gt;
IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc;
&lt;SPAN style="line-height: 1.5;"&gt;IFeatureWorkspace featureWorkspace = new IFeatureWorkspaceProxy(workspace);&lt;/SPAN&gt;
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);&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:21:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/unable-to-cast-several-file-gdb-arcobjects-with/m-p/158078#M4153</guid>
      <dc:creator>KevinLECOCQ</dc:creator>
      <dc:date>2021-12-11T08:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to cast several File GDB ArcObjects with Java</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/unable-to-cast-several-file-gdb-arcobjects-with/m-p/158079#M4154</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="java" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14327343436013615 jive_text_macro" data-renderedposition="71_8_912_16" jivemacro_uid="_14327343436013615"&gt;&lt;P&gt;IWorkspace workspace = new Workspace(name.open());&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After doing this modification, it solves the IWorkspace2 cast problem, good news.&lt;/P&gt;&lt;P&gt;So, it seems there is an error in the ArcObjects Java documentation I initially followed: &lt;A href="http://help.arcgis.com/en/sdk/10.0/java_ao_adf/conceptualhelp/engine/index.html#/How_to_create_new_geodatabases/0001000002w4000000/"&gt;http://help.arcgis.com/en/sdk/10.0/java_ao_adf/conceptualhelp/engine/index.html#/How_to_create_new_geodatabases/0001000002w4000000/&lt;/A&gt; in the &lt;STRONG&gt;Creating a file geodatabase workspace paragraph&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, this modification didn't solve the IFeatureClassLoad cast error. So, I also changed the way I open feature classes by:&lt;/P&gt;&lt;PRE __default_attr="java" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14327382612846890 jive_text_macro" data-renderedposition="234_8_912_16" jivemacro_uid="_14327382612846890"&gt;&lt;P&gt;featureWorkspace.openFeatureClass(featureClassName);&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;but the error is still here.&lt;/P&gt;&lt;P&gt;Any idea?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 May 2015 13:48:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/unable-to-cast-several-file-gdb-arcobjects-with/m-p/158079#M4154</guid>
      <dc:creator>KevinLECOCQ</dc:creator>
      <dc:date>2015-05-27T13:48:28Z</dc:date>
    </item>
  </channel>
</rss>

