Search on IFeatureSelection using field from a Join Layer

432
1
12-06-2013 02:52 PM
EdwardBlair
Occasional Contributor
I've got a tool that needs to operate on a selected set of features in a layer.  It then needs to process a subset of the selected features based on a query filter.  This is straightforward.  For example:

IFeatureSelection pFSel = (IFeatureSelection)pFLayer;
ISelectionSet pSelectionSet = pFSel.SelectionSet;
IQueryFilter pQF = new QueryFilter();
pQF.WhereClause = "MATERIAL = 'PL';
IFeatureCursor pCursor;
pSelectionSet.Search(pQF, true, out pCursor);

And pCursor holds the result.

Now, what if the layer in question is a join layer.

If I want to select from the join layer using a field in the joined table I can use SearchDisplayFeatures on IGeoFeatureLayer, as in:

IGeoFeatureLayer pGeoFLayer = (IGeoFeatureLayer)pFLayer;
pCursor = pGeoFLayer.SearchDisplayFeatures(pQF, true);

Which works fine.  But if I want to subset an existing selection set using a query filter that references a field in the join table... well, I'm stumped.  Any suggestions would be much appreciated.

Thanks,
Ed
0 Kudos
1 Reply
EdwardBlair
Occasional Contributor
After some sleep I realized the solution to the problem was to create a new selection layer from the first layer that had the join, and then use SearchDisplayFeatures on the selection layer.  Briefly, key parts of this are:

// Get a reference to the join table
IDisplayTable displayTable = (IDisplayTable)pFLayer;
ITable table = displayTable.DisplayTable;
IRelQueryTable relQueryTable = (IRelQueryTable)table;
ITable destTable = relQueryTable.DestinationTable;
IDataset tableDS = (IDataset)destTable;
// Create a temporary layer using the selection set from the
// current layer
IFeatureLayerDefinition pFLayerDef = (IFeatureLayerDefinition) pFLayer;
IFeatureLayer pTempLayer = pFLayerDef.CreateSelectionLayer(pFLayer.Name + "_xxTemp", true,
  tableDS.Name, "");
// Search the new layer.. pCursor has the results
IGeoFeatureLayer pGeoFLayer = (IGeoFeatureLayer)pTempLayer;
pCursor = pGeoFLayer.SearchDisplayFeatures(pQF, true);

// Remove the temporary layer
m_pMap.DeleteLayer((ILayer)pTempLayer);

(Its probably not the intent of this forum for someone to ask a question and then later answer it themselves -- but it may be that writing the question down helped me solve it.  I don't think I get points for this.  Anyway, thanks Forums!)

Ed
0 Kudos