Problem with GeoProcessor.GetDataElement (C#)

899
2
Jump to solution
04-11-2013 07:16 AM
JohnStephens
Occasional Contributor
I am writing an application that needs to run through a GDB with one dataset and multiple feature classes.  The feature classes have subtypes and coded domain values.  I need to get the count by subtype.  Every time I run this code in my application it crashes when it gets to "IDataElement dataElem = (IDataElement)gp2.GetDataElement(fcPath, ref dType);".  It does not throw an exception it just terminates the application completely.

The odd thing is that if I extract this code from the application it will run by itself.  Anyone have any ideas at all?  I'm desperate and I need to figure this out.

            GeoProcessor gp = new GeoProcessor();             IWorkspaceFactory wsFact = new FileGDBWorkspaceFactoryClass();             IWorkspace ws = wsFact.OpenFromFile(destData, 0);             IEnumDataset enumDS = ws.get_Datasets(esriDatasetType.esriDTFeatureDataset);             IFeatureDataset ltdsDS = (IFeatureDataset)enumDS.Next();             IEnumDataset enumFC = ltdsDS.Subsets;             IDataset currFC = enumFC.Next();              fCodeCounts = new Dictionary<string, Dictionary<int, int>>();             while (currFC != null)             {                 FeatureClass fc = (FeatureClass)currFC;                 IFeatureClass fcl = (IFeatureClass)fc;                 System.Object dType = "";                 string fcPath = destData + "\\" + ltdsDS.BrowseName + "\\" + fc.BrowseName;                 IDataElement dataElem = (IDataElement)gp.GetDataElement(fcPath, ref dType);                 IDEGdbTable deTbl = (IDEGdbTable)dataElem;                 IArray arr = deTbl.Subtypes;                 Dictionary<int, int> tempDict = new Dictionary<int, int>();                 fCodeCounts.Add(fc.BrowseName, new Dictionary<int,int>());                 for (int i = 0; i < (arr.Count); i++)                 {                     IGPSubtype gpSt = (IGPSubtype)arr.get_Element(i);                     tempDict.Add(gpSt.SubtypeCode, fcl.FeatureCount(CreateSubtypeQuery(gpSt.SubtypeCode)));                 }                 fCodeCounts.Add(fc.BrowseName, tempDict);                 currFC = enumFC.Next();             }
0 Kudos
1 Solution

Accepted Solutions
JohnStephens
Occasional Contributor
Not sure if anyone cares, but I solved my problem by getting to the Subtypes through ISubtype and IEnumSubtype instead of the GeoProcessor.

            while (currFC != null)             {                 FeatureClass fc = (FeatureClass)currFC;                 IFeatureClass fcl = (IFeatureClass)fc;                 ISubtypes subtypes = (ISubtypes)fcl;                 IEnumSubtype enumSubtype;                 int subtypeCode;                 string subtypeName;                 Dictionary<int, int> tempDict;                 if (subtypes.HasSubtype)                 {                     enumSubtype = subtypes.Subtypes;                     subtypeName = enumSubtype.Next(out subtypeCode);                     tempDict = new Dictionary<int, int>();                     while (subtypeName != null)                     {                                                tempDict.Add(subtypeCode, fcl.FeatureCount(CreateSubtypeQuery(subtypeCode)));                         subtypeName = enumSubtype.Next(out subtypeCode);                     }                     fCodeCounts.Add(fc.BrowseName, tempDict);                 }                 currFC = enumFC.Next();

View solution in original post

0 Kudos
2 Replies
JohnStephens
Occasional Contributor
Not sure if anyone cares, but I solved my problem by getting to the Subtypes through ISubtype and IEnumSubtype instead of the GeoProcessor.

            while (currFC != null)             {                 FeatureClass fc = (FeatureClass)currFC;                 IFeatureClass fcl = (IFeatureClass)fc;                 ISubtypes subtypes = (ISubtypes)fcl;                 IEnumSubtype enumSubtype;                 int subtypeCode;                 string subtypeName;                 Dictionary<int, int> tempDict;                 if (subtypes.HasSubtype)                 {                     enumSubtype = subtypes.Subtypes;                     subtypeName = enumSubtype.Next(out subtypeCode);                     tempDict = new Dictionary<int, int>();                     while (subtypeName != null)                     {                                                tempDict.Add(subtypeCode, fcl.FeatureCount(CreateSubtypeQuery(subtypeCode)));                         subtypeName = enumSubtype.Next(out subtypeCode);                     }                     fCodeCounts.Add(fc.BrowseName, tempDict);                 }                 currFC = enumFC.Next();
0 Kudos
JoseSanchez
Occasional Contributor III

In ArcGIS 10.4.1 we had a similar issue and we fixed the problem changing the property value "Embeded Interop types" to True from the reference library Esri.ArcGIS.GeoProcessor:

Embeded Interop types: True.

0 Kudos