Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.
public static void SelectBy(this IActiveView view, ILayer2 targetLayer, 
    string filterClause, esriSelectionResultEnum selectionResult ) {

    IFeatureSelection featureSelection = targetLayer as IFeatureSelection;
    if ( featureSelection == null ) return;

    IQueryFilter queryFilter = new QueryFilterClass();
    queryFilter.WhereClause = filterClause;

    IColor selectColor = featureSelection.SelectionColor;
    selectColor = Local.ColorToIColor( System.Drawing.Color.OrangeRed );
    featureSelection.SelectionColor = selectColor;
    view.PartialRefresh( esriViewDrawPhase.esriViewGeoSelection, view.FocusMap, null );

    featureSelection.SelectFeatures( queryFilter, selectionResult, false );
    ISelectionSet selectionSet = featureSelection.SelectionSet;
    view.PartialRefresh( esriViewDrawPhase.esriViewGeoSelection, view.FocusMap, null );
}

If I use this code to make a selection calling it with:

view.SelectBy( layer, "[KeyField] = 10000.0",   
    esriSelectionResultEnum.esriSelectionResultNew);  

My feature polygons are always FILLED. If I set the featureSelection.Symbol field to a SimpleLineSymbol (and set SetSelectionSymbol=true) it shows nothing. How do I do a feature selection that is NOT filled (as happens when I use IMap.SelectByShape()?)

share|improve this question

1 Answer 1

public static void SelectBy( this IActiveView view, ILayer2 targetLayer, string filterClause, esriSelectionResultEnum selectionResult ) {
    IFeatureSelection featureSelection = targetLayer as IFeatureSelection;
    if ( featureSelection == null ) return;
    IQueryFilter queryFilter = new QueryFilterClass();
    queryFilter.WhereClause = filterClause;
    IColor selectColor = Local.ColorToIColor( System.Drawing.Color.OrangeRed );
    ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
    fillSymbol.Color = selectColor;
    ISimpleLineSymbol outlineSymbol = new SimpleLineSymbolClass();
    outlineSymbol.Color = selectColor;
    outlineSymbol.Width = 2;
    fillSymbol.Outline = outlineSymbol;
    fillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;
    featureSelection.SelectionSymbol = fillSymbol as ISymbol;
    featureSelection.SetSelectionSymbol = true;
    featureSelection.SelectFeatures( queryFilter, selectionResult, false );
    view.PartialRefresh( esriViewDrawPhase.esriViewGeoSelection, view.FocusMap, null );
}

This works. Is there a simpler way?

share|improve this answer
    
Not really.. this solution is just about the simplest hollow polygon fill as it gets. –  Petr Krebs Nov 22 '11 at 15:32
    
Is it a quirk of using ArcEngine that the default selection symbol is a solid fill? I have never seen that happen in ArcMap. –  blah238 Nov 22 '11 at 18:14
    
Does anyone know what the "default selection symbology" is? (It must have something to do with this because I noticed that after I ran the previous code even the SelectByShape() calls were using a filled selection. Using ILayerDescription can I set this one for the whole layer (and thus remove the symbol definition from the above code? - Of course, what actions would reset the default selection?) –  Chaz Nov 22 '11 at 20:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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