Select to view content in your preferred language

Query Related Tables: How do I add my data back to my graphic so it can be rendered?

805
2
12-03-2012 05:29 AM
BrianMulcahy
Occasional Contributor
So I have a feature class and some tables . My feature class is related to my tables by a relationship id. I query my feature class to get all my objectids that I then use for a relationship query. After receiving the results of my relationship query I am then stumped on what to do with these results so I can use them to render my original feature class.


Here is my code which works but doesn't currently do anything with the results it gets from the Relationship query

  private void View_Click(object sender, RoutedEventArgs e)
        {

            queryTask = new QueryTask(QueryLayer.Url);
            queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
            queryTask.ExecuteRelationshipQueryCompleted += QueryTask_ExecuteRelationshipQueryCompleted;
            queryTask.Failed += QueryTask_Failed;


            ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
            query.ReturnGeometry = true;
            query.Where = "1=1";
            query.OutSpatialReference = Map.SpatialReference;
            query.OutFields.AddRange(new string[] { "OBJECTID", "COUNTY"});
           

            queryTask.ExecuteAsync(query);






        }

        private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;
            GraphicsLayer graphicsLayer = Map.Layers["ResultGraphicsLayer"] as GraphicsLayer;
           List<int> objectid = new List<int>();

            foreach (Graphic g in args.FeatureSet.Features)
            {
                g.Symbol = LayoutRoot.Resources["ClipFeaturesFillSymbol"] as Symbol;
                graphicsLayer.Graphics.Add(g);
                objectid.Add(Convert.ToInt32(g.Attributes["OBJECTID"]));
                g.Select();
          
            }



           
            string yearselected;
            yearselected = "Year_" + Years.Text;

            int relateID = new int();
            relateID = (Convert.ToInt32(Commoditieslist.SelectedValue));
            
            RelationshipParameter relationshipParameters = new RelationshipParameter()
        {

            ObjectIds = objectid,
            OutFields = new string[] {"County", yearselected },
            RelationshipId = relateID,
            ReturnGeometry = true,
            OutSpatialReference = Map.SpatialReference
        };

            queryTask.ExecuteRelationshipQueryAsync(relationshipParameters);



        }

        private void QueryTask_Failed(object sender, TaskFailedEventArgs args)
        {
            MessageBox.Show("Query execute error: " + args.Error);
        }

        private void QueryTask_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e)
        {
          
           
            GraphicsLayer graphicsLayer = Map.Layers["ResultGraphicsLayer"] as GraphicsLayer;
           
            
            RelationshipResult pr = e.Result;

            
            
            if (pr.RelatedRecordsGroup.Count == 0)
            {
                RelatedRowsDataGrid.ItemsSource = null;
            }
            else
            {
                foreach (var pair in pr.RelatedRecordsGroup)
                {
                   
                    RelatedRowsDataGrid.ItemsSource = pair.Value;
                    Array graphicsArray = pair.Value.ToArray();
                    //This is where I am stuck
                    

                }
            }

            
           

        }


My goal is to query my related table so that I can then render my graphics by code with the values I received from that relationship.
Is there a way to add attributes to my graphic?

I was thinking I may just do a geoprocessing task that uses a join to join the related table to the feature class, but I wanted to see if I could do it this way first.
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
Is there a way to add attributes to my graphic?


Yes you can add attributes with values coming from your related tables.

graphic.Attributes["myNewAttribute"] = myValue;
0 Kudos
BrianMulcahy
Occasional Contributor
Yes you can add attributes with values coming from your related tables.

graphic.Attributes["myNewAttribute"] = myValue;


So with the code I provided above would I do it in my for each statement?

Also will the myvalue be the pair.Value?
0 Kudos