1

I have some features which at the time of validation found to having incorrect attributes' values.

How do I highlight those features in the map?

Here is what I tried:

    public void HighlightInvalidFeatures(List<IFeature> featureList, IActiveView activeView, IMap map)
                {
                    Dictionary<IFeatureClass, List<int>> uniqueFeatureClasses = new Dictionary<IFeatureClass, List<int>>();
                    IFeatureClass esriFeatureClass = null;
                    IEnumLayer enumLayer = null;

                    IFeatureLayer esriFLayer = null;
                    IQueryFilter esrifilter = null;
                    ILayer esriLayer = null;
                    ISelectionSet selectionSet = null;
                    ISelectionSet selectionSet2 = null;
                    // IDataset dataset = null;

                    int[] ojectIDArr = new int[10000];
                    List<int> objList = new List<int>();
                    int count = 0;
                    try
                    {

                        foreach (var feature in featureList)
                        {
                            esriFeatureClass = feature.Table as IFeatureClass;

                            if (!uniqueFeatureClasses.ContainsKey(esriFeatureClass))
                                uniqueFeatureClasses.Add(esriFeatureClass, new List<int>());

                            uniqueFeatureClasses[esriFeatureClass].Add(feature.OID);
                        }

                        // Getting the current map object
                        IMap mapInstance = map;

                        // Clear the current selection
                        mapInstance.ClearSelection();


                        enumLayer = mapInstance.get_Layers(null, true);

                        //create and add the layers
                        foreach (var pair in uniqueFeatureClasses)
                        {
                            for (int iter = 0; iter < pair.Value.Count; iter++)
                            {
                                objList.Add(pair.Value[iter]);
                                count++;
                            }
                        }
                        // Converting the Object ID List to an array
                        ojectIDArr = objList.ToArray();

                        foreach ( var pair in uniqueFeatureClasses )
                        {
                            // Create the FeatureLayer
                            esriFLayer = new FeatureLayerClass();
                            esriFLayer.FeatureClass = pair.Key;
                            esriFLayer.Name = pair.Key.AliasName;

                            esriLayer = null;

                            esrifilter = new QueryFilter();
                            esrifilter.WhereClause = pair.Key.OIDFieldName + " IN (" + String.Join(",", pair.Value) + ")";

                            while ((esriLayer = enumLayer.Next()) != null)
                            {
                                // Check for Valid Features
                                if (esriLayer.Valid)
                                {
                                    // Check if the featureClass is matching with the featureClass passed
                                    if (esriFLayer.FeatureClass == (esriLayer as IFeatureLayer).FeatureClass)
                                    {
                                        esriFLayer = (esriLayer as IFeatureLayer);
                                        selectionSet = (esriFLayer as IFeatureSelection).SelectionSet;
                                        selectionSet.AddList(count, ref ojectIDArr[0]);
                                        selectionSet.Combine(selectionSet, esriSetOperation.esriSetUnion, out selectionSet2);

                                    }
                                }
                            }

But only the last features are selected and previous selection is discarded.

I have searched here: http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeodatabase/ISelectionSet_Example.htm

Your Answer

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

Browse other questions tagged or ask your own question.