1 Reply Latest reply on Dec 7, 2013 9:31 AM by Ed Blair

    Search on IFeatureSelection using field from a Join Layer

    Ed Blair

      This is more of an ArcGIS/ArcObjects question than an ArcFM/ArcFM Objects question, but I know this audience is a broad minded group and may have tackled this item before.

       

      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.  If I search on the selection set with a query filter that includes a field from the join layer it just blows up:

       

      IFeatureSelection pFSel = (IFeatureSelection)pGeoFLayer;

      ISelectionSet pSelectionSet = pFSel.SelectionSet;

      IQueryFilter pQF = new QueryFilter();

      pQF.WhereClause = "<RelatedTable>.MATERIAL = 'PL';

      IFeatureCursor pCursor;

      pSelectionSet.Search(pQF, true, out pCursor);  // Kaboom!

       

      Any suggestions would be much appreciated.

       

      Thanks,

      Ed

        • Re: Search on IFeatureSelection using field from a Join Layer
          Ed Blair

          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 Exchange!)

           

          Ed