Select to view content in your preferred language

How to store the spatial query results in a collection??

656
4
11-08-2010 09:55 AM
DanDong
Deactivated User
Hi all,

In the ESRI spatial query demo, when I draw a polygon on the map, a table is used to display the results. Since there are six layers waiting to be cut in my project, I was going to store the results from six layer into a array. But then my friend suggested me store them in a collection. So I am thinking
1. declare a class layer to store the results from one layer
Class layer{
                     string name;
                     double population;
                     ......
                   }
2. declare a collection to store the results from six layers. L1 is the first layer.
Collection <Layer> LayerCol = new Collection<>;
Layer L1 = new Layer(a, 100)
LayerCol.Add(L1);

I am not sure I am in the right way. In addition, right now the results from cutting one layer are displayed in the table. I am a little confused that where the results stored.  I mean I specify the attributes that I want to display, like county_name, population, and it displays the results in the user interface, but since I should store them in the collection or array, I should figure out the results are stored in which place and how can I store them in the collection or array. Could you give suggestions on that? Thank you very much 🙂
0 Kudos
4 Replies
DanDong
Deactivated User
any suggestions? 🙂
0 Kudos
JenniferNery
Esri Regular Contributor
Hmm I don't think you need to do all that.  A simpler approach would be to make use the Attributes property of each graphic.  Notice that in that sample, graphicsLayer.Graphics contain the features returned by the query.  Feature, in this sample is not only the Geometry but also the Attributes. You can make use of FeatureDataGrid and have it point to the GraphicsLayer that contain the results.

This might be related to what you are trying to achieve: http://forums.arcgis.com/threads/8309-How-to-perform-spatial-query-between-two-services...
0 Kudos
DanDong
Deactivated User
Hmm I don't think you need to do all that.  A simpler approach would be to make use the Attributes property of each graphic.  Notice that in that sample, graphicsLayer.Graphics contain the features returned by the query.  Feature, in this sample is not only the Geometry but also the Attributes. You can make use of FeatureDataGrid and have it point to the GraphicsLayer that contain the results.

This might be related to what you are trying to achieve: http://forums.arcgis.com/threads/8309-How-to-perform-spatial-query-between-two-services...


Thanks Jennifer, that really gives me many clues! Since I want to use that polygon to query six layers in different mapserver, so I made a little change to the codes.
I made a button to execute the query task. but
private void SpatialQuery(object sender, RoutedEventArgs e)
        {
            //make a loop here to do six spatial querys
            for (int j = 0; j < 2; j++)
            {
                //Graphicslayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
                //Graphicslayer.ClearGraphics();

                //I didn't use the combox
                QueryTask queryTask = new QueryTask((layers.ElementAt(j) as FeatureLayer).Url);
                queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
                queryTask.Failed += QueryTask_Failed;


                // Bind data grid to query results
                //Binding resultFeaturesBinding = new Binding("LastResult.Features");
                //resultFeaturesBinding.Source = queryTask;
                //QueryDetailsDataGrid.SetBinding(DataGrid.ItemsSourceProperty, resultFeaturesBinding);
                Query query = new ESRI.ArcGIS.Client.Tasks.Query();

                // Specify fields to return from query, if it is the first layer, return the TRS field
                switch (j)
                {
                    case 0:
                        query.OutFields.AddRange(new string[] { "TRS" });
                        break;
                    case 1:
                        query.OutFields.AddRange(new string[] { "NAME_CNTY" });
                        break;                   
                }
     
                //the polygon is added from points
                ESRI.ArcGIS.Client.Geometry.Polygon queryGeometry = new ESRI.ArcGIS.Client.Geometry.Polygon();
                queryGeometry.Rings.Add(pPointCollection);
                query.Geometry = queryGeometry;

                // Return geometry with result features
                query.ReturnGeometry = true;

                queryTask.ExecuteAsync(query);
            }  
        }


I didn't make change for the QueryTask_ExecuteCompleted part.
 private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            MessageBox.Show("Query succedded: " + args.FeatureSet);

            FeatureSet featureSet = args.FeatureSet;
            

            if (featureSet == null || featureSet.Features.Count < 1)
            {
                MessageBox.Show("No features retured from query");
                return;
            }

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            if (featureSet != null && featureSet.Features.Count > 0)
            {
                foreach (Graphic feature in featureSet.Features)
                {
                    feature.Symbol = LayoutRoot.Resources["ResultsFillSymbol"] as FillSymbol;
                    graphicsLayer.Graphics.Insert(0, feature);
                }
                //ResultsDisplay.Visibility = Visibility.Visible;
            }
        }



But when I run the prj, it can only return the NAME_CNTY field.
[ATTACH]3360[/ATTACH]
From the image, three counties are cut, so it is right to return three names, but it doesn't return the TRS field which should be returned first. And I think this loop do work, because this sentence "MessageBox.Show("Query succedded: " + args.FeatureSet)" pops up for tow time and you can see the Scroll bar appears in the featuregrid (when executing spatial query in the first layer, the polygon cut more features than that in the second layer).

I notice in that thread, seems every time it can only return the attribute from one layer, but we can change layer through the combox. My problem is like check all the layers in the combox and get the results, store them in a global collection. Because the results don't need to display in the user interface, they will later be written into XML, that's why i want to use a global collection to store the results. But right now, let the results display in the user interface is a best way to see whether it get the results or not.

I am not sure I am thinking in the right way. I appreciate your suggestion 🙂
0 Kudos
JenniferNery
Esri Regular Contributor
Like I said here, you cannot sequentially make Asynchronous calls, you need to wait for one to finish before you can call another. 🙂
Like I said in the other thread you started about
0 Kudos