Attribute Query

2025
3
09-24-2012 02:41 PM
ChristineZeller
New Contributor III
I'm working through a the attribute query example - http://resources.arcgis.com/en/help/silverlight-api/samples/start.htm#QueryWithoutMap

Basically after I do a query I would like to instead of throwing the data in a Data Grid I would just like to loop the the results.  I'm interested in one field (example in the SDK example take the field Region).  When all the records are returned from the query I would like to take all the values in the Region column, grab all the values and remove the duplicates and assign it to a string. 


So I want to try and do something like this but it is not working on.  I'm trying to get it into a list so I can but it in a long string so I can build a new query where based of the previous selection

    List<DataItem> _MitListdataItems = null;

             foreach (Graphic graphic in args.FeatureSet.Features)
                {
                    //Set Distinct
                 //list for Mitigation List Table
                 
                 _MitListdataItems.Add = (from g in args.FeatureSet.Features
                                                   orderby g.Attributes["SUB_REGION"].ToString()
                                                   select g.Attributes["SUB_REGION"]).Distinct();
}



I can do this but I don't know how to get me var list outside of my for loop I can't access it

  foreach (Graphic graphic in args.FeatureSet.Features)
                {
                   
                var list = (from g in args.FeatureSet.Features
                                                   orderby g.Attributes["SUB_REGION"].ToString()
                                                   select g.Attributes["SUB_REGION"]).Distinct();
                }



Can someone shed some light on where I should go...I've been stuck for awhile.

Thanks
Christine.
0 Kudos
3 Replies
vipulsoni
Occasional Contributor
I'm working through a the attribute query example - http://resources.arcgis.com/en/help/silverlight-api/samples/start.htm#QueryWithoutMap

Basically after I do a query I would like to instead of throwing the data in a Data Grid I would just like to loop the the results.  I'm interested in one field (example in the SDK example take the field Region).  When all the records are returned from the query I would like to take all the values in the Region column, grab all the values and remove the duplicates and assign it to a string. 


So I want to try and do something like this but it is not working on.  I'm trying to get it into a list so I can but it in a long string so I can build a new query where based of the previous selection

    List<DataItem> _MitListdataItems = null;

             foreach (Graphic graphic in args.FeatureSet.Features)
                {
                    //Set Distinct
                 //list for Mitigation List Table
                 
                 _MitListdataItems.Add = (from g in args.FeatureSet.Features
                                                   orderby g.Attributes["SUB_REGION"].ToString()
                                                   select g.Attributes["SUB_REGION"]).Distinct();
}



I can do this but I don't know how to get me var list outside of my for loop I can't access it

  foreach (Graphic graphic in args.FeatureSet.Features)
                {
                   
                var list = (from g in args.FeatureSet.Features
                                                   orderby g.Attributes["SUB_REGION"].ToString()
                                                   select g.Attributes["SUB_REGION"]).Distinct();
                }



Can someone shed some light on where I should go...I've been stuck for awhile.

Thanks
Christine.


Hi,

for your requirement to do "grab all the values and remove the duplicates and assign it to a string"

private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
               var enumGraphics = from g in args.FeatureSet
                                   orderby (g.Attributes[fieldname] as string) ascending
                                   select g;

                 int argsLen = args.FeatureSet.Features.Count;

                 string[] myStringArray = new string[argsLen];
                             
                int i =0;

                foreach (ESRI.ArcGIS.Client.Graphic gn in enumGraphics)
                {
                    string attrib = string.Format("{0}", gn.Attributes[fieldname]);

                    if (string.IsNullOrEmpty(attrib) | attrib == " ")
                    {
                        AttribFill = false;
                    }
                    else
                    {
                        myStringArray = gn.Attributes[fieldname].ToString();
                        AttribFill = true;
                    }
                    i++;
                }

                string[] unique = myStringArray.Distinct().ToArray(); // this is where you remove the duplicates...
               
                foreach(string s in unique) //this is the string you have with unique values of the particular column...
                {
                    if(!string.IsNullOrEmpty(s))
                    {
                         AttributesList.Items.Add(s);
                    }

                }
}
0 Kudos
ChristineZeller
New Contributor III
Thanks Vipul!
Can you tell me how/what I need to declare for AttributesList and AttibFill?
These are undefined and I'm not sure what they are.
THnaks
Christine
0 Kudos
vipulsoni
Occasional Contributor
Thanks Vipul!
Can you tell me how/what I need to declare for AttributesList and AttibFill?
These are undefined and I'm not sure what they are.
THnaks
Christine


Hi,

Attribfil is a bool variable. which is true if there is some values in the fields and not null or empty or whitespace.. and attributelist is a combobox which gets filled with the field values. I hope this helps..
0 Kudos