Select to view content in your preferred language

CodedValueDomain

3220
1
01-24-2013 09:53 PM
Ariharan
Deactivated User
Hi all,
           Have you ever came across this issue? I have a QueryResult to be displayed in list for Selection Query. All the unique values of each field will be listed out in the listbox. Used the ArcGIS Server(10.1 Version) Map service  for querying and the data source is retrieved through ArcSDE which is stored in SQL. The problem is When i used to display the domain description using the below code which results from query, its shows the domain as null. But, the same Map service shows the domain description and value in ArcMap. In my case, it always display the domain value as the field value, which executes the else part. Can i have the domain value for the queryresults as featureset? Is there any solution for this?

private void QueryTask_ExecuteCompleted(object sender, QueryEventArgs args)
        {
                         
                FeatureSet featureSet = args.FeatureSet;
                IEnumerable<Graphic> Objenumerator = featureSet.Features.Distinct<Graphic>();
                IList<Graphic> lst = Objenumerator.ToList<Graphic>();
            
               //Load the values based on Domain or individual values
                if (FieldName != null)//FieldName is a property which is used to mention specific filed
                {
                    LstFieldValue.Items.Clear();//LstFieldValue is the list box.
                   
                   
                    IList<Field> lstField = featureSet.Fields.ToList();
                  
                        Field field = featureSet.Fields.FirstOrDefault(x => x.Name == FieldName);
                                                
                            //If domain exist
                            if (field.Domain != null && field.Domain is Domain)
                            {
                                MessageBox.Show(field.Name.ToString() + " is a type of " + field.Domain.GetType().ToString());
                                if (field.Domain is CodedValueDomain)
                                {
                                    CodedValueDomain cvd = field.Domain as CodedValueDomain;
                                    foreach (var item in cvd.CodedValues)
                                    {
                                        string strDomain = item.Key.ToString() + " - " + item.Value.ToString();
                                        LstFieldValue.Items.Add(strDomain);
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("The domain exist, but not coded value." );
                                }
                            }
                        
                            //If domain not exist
                            else
                            {
                                MessageBox.Show("The field " + field.Name.ToString() + " dont have any domain values.");
                                foreach (Graphic ObjGrap in lst)
                                {
                                    if (ObjGrap.Attributes[SelectedFieldName.ToString()].ToString().Trim() != null)
                                    {
                                        if (!LstFieldValue.Items.Contains(ObjGrap.Attributes[SelectedFieldName.ToString()].ToString()))
                                        {
                                            LstFieldValue.Items.Add(ObjGrap.Attributes[SelectedFieldName.ToString()].ToString());
                                        }
                                    }

                                }
                          }
                    }
                else
                    MessageBox.Show("No features retrieved..");
        }

Looking for a solution, your timely help will be useful.

Thanks,
Ariharan.A
0 Kudos
1 Reply
Ariharan
Deactivated User
The issue is in the below portion of code:

private void QryTask_ExecuteCompleted(object sender, QueryEventArgs args)
{
        FeatureSet featureSet = args.FeatureSet;

        Field field = featureSet.Fields.FirstOrDefault(x => x.Name == FieldName);

        /////////////////////////Issue ////////////////////////////////////////////
        if (field.Domain != null && field.Domain is Domain)   //Error: Domain is null
        {
             if (field.Domain is CodedValueDomain)
                {
                      CodedValueDomain cvd = field.Domain as CodedValueDomain;
                      foreach (var item in cvd.CodedValues)
                      {
                           string strDomain = item.Key.ToString() + " - " + item.Value.ToString();
                           LstFieldValue.Items.Add(strDomain);
                      }
                 }
         }
}


Is the domain only applicable for the featurelayer? It wont be appended to the result of QueryTask which return a FeatureSet Object?

Thanks,
Ariharan.A
0 Kudos