2

I was selecting features using IFeatureSelection interface like as below.

IFeatureLayer2 featLayer = layer as IFeatureLayer2;
IFeatureSelection featureSelection = featLayer as IFeatureSelection;
featureSelection.SelectFeatures(spatialFilter, ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultNew, false);

I selected all the features in the map as I used the spatial filter to the full map extent. But what I did not come across there are various enum options like esriSelectionResultEnum.esriSelectionResultAdd. I was thinking that this add narrows down the search more like it would filter out more records as like this.

 //IQueryFilter2 qFilter = new QueryFilterClass();
                    //qFilter.WhereClause = "WORKORDERID != null";
                    //featureSelection.SelectFeatures(qFilter, ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultAdd, false);

This immediate above snippet did not work for me But I am not very sure and I did not find much document on what scenario these options work and it would be great if it can be explained with snippet.

3

The values for esriSelectionResultEnum are layed out here

esriSelectionResultNew: Makes a new selection. Anything that was selected that you didn't select will be deselected.

esriSelectionResultAdd: Append new items to your current select. Does not deselect any previously selected item.

esriSelectionResultSubtract: Removes items from your current selection. Will not select any previously unselected features.

esriSelectionResultAnd: Will select a subset of the currently selected items.

esriSelectionResultXOR: XOR with the current selection. See the table in the documentation link above.

IFeatureLayer2 featLayer = layer as IFeatureLayer2;
IFeatureSelection featureSelection = featLayer as IFeatureSelection;
featureSelection.SelectFeatures(spatialFilter, ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultNew, false);

 IQueryFilter2 qFilter = new QueryFilterClass();
                qFilter.WhereClause = "WORKORDERID IS NOT NULL";
                featureSelection.SelectFeatures(qFilter, ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultAdd, false);

Now everything will be selected from both queries. Also the proper syntax for the WhereClause in your comment is "WORKORDERID IS NOT NULL". When searching for NULL values you use "IS" and "IS NOT".

1
  • Thanks Danielm for sharing the understanding, Can you please share a small snippet for this. I tried to do the selection of all the structures in my map, then I try to add splice_closure to the selection set. Is that the scenario may be the add can be applied. Correct me if wrong
    – royan
    Apr 24 '18 at 14:54
2

Are you aware that a spatial filter can have a where clause as well?

If you add the line

spatialFilter.WhereClause = "WORKORDERID <> null"; // it's SQL, not equals is <> not != 

then your results will be filtered to only those that satisfy the spatial and the attribute limitations of the spatial filter.

There is also an enum for ISpatialFilter.SearchOrder which instructs the filter on how to query, either by location first with esriSearchOrder.esriSearchOrderSpatial or by attributes first with esriSearchOrder.esriSearchOrderAttribute; the order of search can make a difference with very large datasets but for very small datasets it's probably not worth changing from the default by location first.

1
  • Thanks Stimson for pointing out the thing. I did this as we do in if statement in a hurry it seems when I read your comment and revisit the code. Yes, I corrected that <>.
    – royan
    Apr 24 '18 at 9:19

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.