3

I would like to change programatically the SQL Query of a LYR file. I'm developping in C# using ArcObject.

Actually I'm able to get an instance of IWorkspaceFactory from an opened layer with this code :

  IDataLayer dataLayer = (IDataLayer)lyrFile.Layer;       
  IDatasetName datasetName = (IDatasetName)dataLayer.DataSourceName;
  IWorkspaceFactory wsFactory = datasetName.WorkspaceName.WorkspaceFactory;

But from here I'm stuck. I don't know how to access to the SQL Query. I've read that with ISQLWorkspace I could maybe do something. But, really I'm not sure at all.

The goal here is to create multiple copies of a layer file (lyr), changing only the SQL Query slightly. I need to do so because I do not have enough functionnalities within the "Definition Query" tab to implements different variations of my SQL query.

The Sql Query that I'm looking to change programmatically.

  • 1
    What do you mean by the SQL-query for the layer? If you mean the definition-query you may set it via IFeatureLayerDefinition.DefinitionExpression – HimBromBeere Jun 18 '15 at 14:56
  • I have just added an image in my question in order to explain what I am trying to do. – Jean-François Legendre Jun 18 '15 at 15:02
  • I can do slightly change within the WHERE clause part of my SQL with IFeatureLayerDefinition.DefinitionExpression. But if I want to do a LEFT OTER JOIN, I have to change the SQL Query "under the hood". – Jean-François Legendre Jun 18 '15 at 15:05
  • 1
    You cannot change the SQL query used by ArcGIS to include a LEFT OUTER JOIN without using a view which includes such a join – Vince Jun 18 '15 at 15:27
4

Arcobjects has two interfaces to join multiple FeatureClasses and (or) Tables:

  1. Query tables (IQueryDef)
  2. RelQueryTables

The result of your join can be added to the map as a Layer if the result has a geometry column.

Make sure to read this Page to check the differences of two and select the one that suites your needs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.