Select to view content in your preferred language

How to change programmatically the data source (FeatureClass-property) of IFeatureLayer with DataSourceType = "Query Feature Class" in ArcMap 10.3 ?

3380
1
03-16-2016 09:49 AM
ThomasKoch
New Contributor

Hi all,

I have a Feature-Layer pointing to an Oracle Table (user-maintained rowid) with spatial type "SDO_GEOMETRY". The Oracle Table is not SDE-registered. By both loading the table from ArcCatalog into ArcMap or using ArcTool MakeQueryLayer I get a layer with data type "Query Feature Class".

Map operations e.g. zooming, panning, selecting etc. work.

My issue is changing the data source programmatically (c#, ArcMap 10.3) either results to exceptions or a layer with data type "Feature Class" and consecutively drawing errors in ArcMap when loading additional layers and executing map operations e.g. zooming, panning, selecting etc:

Drawing errors also occur when I create this layer by ArcTool MakeFeatureLayer although when loaded stand-alone, i.e. no additional layer are load in TOC, map operations e.g. zooming, panning, selecting etc. work without any errors.

Input: IFeatureWorkspace featureWS (cast from IWorkspace with Type = esriRemoteDatabaseWorkspace)

Input: IFeatureLayer pFeatureLayer

  • DataSourceType: Query Feature Class
  • FeatureClass: with AliasName "schema1.%Table1" (what does the character "%" mean ?? / where does this character come from ?? My table's name is "schema1.Table1" !!)

#region Alternative 1: IQueryDef => System.Runtime.InteropServices.COMException (0x80050140): Abstract Data Types not supported

IQueryDef queryDef = featureWS.CreateQueryDef();

queryDef.Tables = "schema1.Table1";

queryDef.SubFields = "*";

queryDef.WhereClause = string.Empty;

IFeatureDataset pFeatureQuery =

    featureWS.OpenFeatureQuery("Table1", queryDef);

pFeatureLayer.FeatureClass = pFeatureQuery as IFeatureClass;

#endregion

#region Alternative 2: ITable zu IDataset => Data Source Type = FeatureClass => Drawing Error in ArcMap

ITable table = featureWS.OpenTable("schema1.Table1");

IDataset dataSet = table as IDataset;

pFeatureLayer.FeatureClass = dataSet as IFeatureClass;

pFeatureLayer.DataSourceType = "Query Feature Class";

#endregion

So my question is how to change programmatically the data source (FeatureClass-property) of IFeatureLayer with DataSourceType = "Query Feature Class" in ArcMap 10.3 avoiding the change of DataSourceType, any exceptions and drawing errors ?

Any help is appreciated !

0 Kudos
1 Reply
OlivierDamanet
Deactivated User

I don't know if you are still looking for a solution here, but here is how I set data source of Query Layers programmatically:

ISqlWorkspace sw = featureWS as ISqlWorkspace;

string query = string.Format("SELECT * FROM {0}", tableName);

IQueryDescription queryDesc = sw.GetQueryDescription(query);

queryDesc.OIDFields = tableID; string queryClassName = "";

//get a unique name for this Query Class

sw.CheckDatasetName(tableName, queryDesc, out queryClassName);

IFeatureClass featureClass = sw.OpenQueryClass(queryClassName, queryDesc) as IFeatureClass;

featureLayer.FeatureClass = featureClass;

Hope this helps

0 Kudos