Select to view content in your preferred language

Search to populate an array (C#)

635
2
01-31-2011 09:50 AM
JoannaLaroussi
Emerging Contributor
I try to use IFeatureCursor and Search in order to select from my feature class some values. I need to select multiple rows, which will be later saved in my array and exported to pdf.  I have problem with this line:
            IFeatureCursor pedCursor2 = selectionASet.Search(null, true);
Error 1 No overload for method 'Search' takes 2 arguments
Does anyone has idea how to fix it? Thanks a lot!

Here is  a bigger chunk of the code to add some context
public void pedAISelectionSet(IFeatureClass featureClassPed)
        {

            IDataset dataset = (IDataset)featureClassPed;

            //Set up query filter and use it to create the selection set
            IQueryFilter queryAPedFilter = new QueryFilterClass();

            string distanceAWhereClause = "\"S_" + optCode + "\" = " + "'A'";
            queryAPedFilter.WhereClause = distanceAWhereClause;
            //use the query filter to select features
            ISelectionSet selectionASet = featureClassPed.Select(queryAPedFilter, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, dataset.Workspace);
            int pedASelectionCount = selectionASet.Count;

            //getting the values for each field and saving it into variables
            IFields pedAFields = featureClassPed.Fields;
            int distanceAField = pedAFields.FindField("S_00000");
            int streetAField = pedAFields.FindField("Street");
            int fromALeftField = pedAFields.FindField("FromLeft");
            int toALeftField = pedAFields.FindField("ToLeft");
            int fromARightField = pedAFields.FindField("FromRight");
            int toARightField = pedAFields.FindField("ToRight");

            //cursor
            IFeatureCursor pedCursor = featureClassPed.Update(queryAPedFilter, false);
            IFeature pedFeature = pedCursor.NextFeature();

            //saving variables
            string streetAValue = pedFeature.get_Value(streetAField).ToString();
            string fromALeftValue = pedFeature.get_Value(fromALeftField).ToString();
            string toALeftValue = pedFeature.get_Value(toALeftField).ToString();
            string fromARightValue = pedFeature.get_Value(fromARightField).ToString();
            string toARightValue = pedFeature.get_Value(toARightField).ToString();

            //building an array
            IFeatureCursor pedCursor2 = selectionASet.Search(null, true);
           
            IFeature pedFeature2 = pedCursor2.NextFeature();
            pedArrayA = new List<String[]>();
            string streetValue, fromLeftValue, toLeftValue, fromRightValue, toRightValue;
            while (pedFeature != null)
            {
                streetAValue = pedFeature2.get_Value(streetAField).ToString();
                fromALeftValue = pedFeature2.get_Value(fromALeftField).ToString();
                toALeftValue = pedFeature2.get_Value(toALeftField).ToString();
                fromARightValue = pedFeature2.get_Value(fromARightField).ToString();
                toARightValue = pedFeature2.get_Value(toARightField).ToString();
                string[] local = new string[5] { streetAValue, fromALeftValue, toALeftValue, fromARightValue, toARightValue };
                pedArrayA.Add(local);
                pedFeature2 = pedCursor2.NextFeature();
            }
        }
0 Kudos
2 Replies
AnnaForrest
Emerging Contributor

            IFeatureCursor pedCursor2 = selectionASet.Search(null, true);
Error 1 No overload for method 'Search' takes 2 arguments
Does anyone has idea how to fix it? Thanks a lot!


Like the error message says, it doesn't have 2 arguments.  It has 3.  See here: http://edndoc.esri.com/arcobjects/8.3/componenthelp/esricore/ISelectionSet_Search.htm

You need to write:
IFeatureCursor pedCursor2; 
selectionASet.Search(null, true, pedCursor2);
0 Kudos
JoannaLaroussi
Emerging Contributor
You need to write:
IFeatureCursor pedCursor2; 
selectionASet.Search(null, true, pedCursor2);


Thanks a lot for your response! I tried to change:
IFeatureCursor pedCursor2;
            selectionASet.Search(null, true, pedCursor2);

            IFeature pedFeature2 = pedCursor2.NextFeature;

            pedArrayA = new List<String[]>();
            string streetValue, fromLeftValue, toLeftValue, fromRightValue, toRightValue;
            while (pedFeature != null)
            {
                streetAValue = pedFeature2.get_Value(streetAField).ToString();
                fromALeftValue = pedFeature2.get_Value(fromALeftField).ToString();
                toALeftValue = pedFeature2.get_Value(toALeftField).ToString();
                fromARightValue = pedFeature2.get_Value(fromARightField).ToString();
                toARightValue = pedFeature2.get_Value(toARightField).ToString();
                string[] local = new string[5] { streetAValue, fromALeftValue, toALeftValue, fromARightValue, toARightValue };
                pedArrayA.Add(local);
                pedFeature2 = pedCursor2.NextFeature();
            }

But I am receiving following errors:
Error 1 The best overloaded method match for 'ESRI.ArcGIS.Geodatabase.ISelectionSet.Search(ESRI.ArcGIS.Geodatabase.IQueryFilter, bool, out ESRI.ArcGIS.Geodatabase.ICursor)' has some invalid arguments
Error 2 Argument 3: cannot convert from 'ESRI.ArcGIS.Geodatabase.IFeatureCursor' to 'out ESRI.ArcGIS.Geodatabase.ICursor'
Error 3 Cannot convert method group 'NextFeature' to non-delegate type 'ESRI.ArcGIS.Geodatabase.IFeature'. Did you intend to invoke the method?

After this I tried change to ICursor, but this also doesn�??t work
ICursor pedCursor2;
            selectionASet.Search(null, true, out pedCursor2);

            IFeature pedFeature2 = pedCursor2.NextRow;

            pedArrayA = new List<String[]>();
            string streetValue, fromLeftValue, toLeftValue, fromRightValue, toRightValue;
            while (pedFeature != null)
            {
                streetAValue = pedFeature2.get_Value(streetAField).ToString();
                fromALeftValue = pedFeature2.get_Value(fromALeftField).ToString();
                toALeftValue = pedFeature2.get_Value(toALeftField).ToString();
                fromARightValue = pedFeature2.get_Value(fromARightField).ToString();
                toARightValue = pedFeature2.get_Value(toARightField).ToString();
                string[] local = new string[5] { streetAValue, fromALeftValue, toALeftValue, fromARightValue, toARightValue };
                pedArrayA.Add(local);
                pedFeature2 = pedCursor2.NextRow();
            }
Error 1 Cannot convert method group 'NextRow' to non-delegate type 'ESRI.ArcGIS.Geodatabase.IFeature'. Did you intend to invoke the method?
Error 2 Cannot implicitly convert type 'ESRI.ArcGIS.Geodatabase.IRow' to 'ESRI.ArcGIS.Geodatabase.IFeature'. An explicit conversion exists (are you missing a cast?)
Do you have some more ideas?
0 Kudos