Select to view content in your preferred language

Can spatial query be used in multi-layers query?

3584
13
11-08-2010 09:50 AM
DanDong
Deactivated User
Hi all,

Right now I can do spatial query in one map layer. I have a question about whether I can use spatial query on six map layers. The process is when I draw a polygon, this polygon will cut six layers, each layer will return one column of attributes (like layer1 return the county name, layer2 return the population, layer3...)

in ESRI demo, it design layer 5 is the target layer:
QueryTask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" + "Demographics/ESRI_Census_USA/MapServer/5");

Can i design other layers as the target layers? If so, what should I do? Thanks for all of you.
0 Kudos
13 Replies
JenniferNery
Esri Regular Contributor
In this example: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Identify

Query is performed on the map service itself, which can contain several sub layers.  Is this what you need?
0 Kudos
DanDong
Deactivated User
In this example: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Identify

Query is performed on the map service itself, which can contain several sub layers.  Is this what you need?



Thanks Jennifer, Identify really can solve this question. In addition, can I use a loop in spatial query to do the query task on six layers?
0 Kudos
JenniferNery
Esri Regular Contributor
You cannot do Async calls in one iteration.  You need to make one Async call at a time, after the previous Async call has returned.
0 Kudos
DanDong
Deactivated User
You cannot do Async calls in one iteration.  You need to make one Async call at a time, after the previous Async call has returned.


Do you mean this sentence?
queryTask.ExecuteAsync(query)
0 Kudos
JenniferNery
Esri Regular Contributor
Yes, that is correct.
0 Kudos
DanDong
Deactivated User
Yes, that is correct.


So badically, I should make a loop for querytask, each time in the loop, just one queryTask.ExecuteAsync(query) was executed. Am I thinking in the correct way?
0 Kudos
JenniferNery
Esri Regular Contributor
What I mean to say is that you sure can make multiple queries but keep in mind that you cannot make multiple asynchronous calls sequentially, you need to wait for one to complete before you can call another.

In other words, this would fail:
   identifyTask.ExecuteAsync(identifyParams1);
   identifyTask.ExecuteAsync(identifyParams2);


So for example you have a list of url's to query on, you need to keep track on what has been queried and what has not been queried yet. After the QueryTask ExecultCompleted fires, that is the only time you can call another query.
0 Kudos
DanDong
Deactivated User
What I mean to say is that you sure can make multiple queries but keep in mind that you cannot make multiple asynchronous calls sequentially, you need to wait for one to complete before you can call another.

In other words, this would fail:
   identifyTask.ExecuteAsync(identifyParams1);
   identifyTask.ExecuteAsync(identifyParams2);


So for example you have a list of url's to query on, you need to keep track on what has been queried and what has not been queried yet. After the QueryTask ExecultCompleted fires, that is the only time you can call another query.


Thank you Jennifer! Yeah, I see that 🙂

Then can i use a switch for this, like those below. k is the Id of the layer, say if k=0, give the url of layers.ElementAt(0) to querytask. Then do the query and return different attribute field, for k=0, return "TRS" field, display them in the featuregrid. After this query completed, in the loop, k will be 1, and in the switch, give the url of layers.ElementAt(1) to querytask.

Am I right? Or I make a mistake again 🙂

private void SpatialQuery(object sender, RoutedEventArgs e)
        {
                   
            for (int j = 0; j < 2; j++)
            {

                spatialQ(j);
            }
        }

private void spatialQ(int k)
        {
           
            switch (k)
            {
                
                case 0:
                    
                    QueryTask queryTask = new QueryTask((layers.ElementAt(0) as FeatureLayer).Url);
                    queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
                    MessageBox.Show("k="+ k);
                    queryTask.Failed += QueryTask_Failed;
                    Query query = new ESRI.ArcGIS.Client.Tasks.Query();
                    query.OutFields.AddRange(new string[] { "TRS" });
                    ESRI.ArcGIS.Client.Geometry.Polygon queryGeometry = new ESRI.ArcGIS.Client.Geometry.Polygon();
                    queryGeometry.Rings.Add(pPointCollection);
                    query.Geometry = queryGeometry;
                    query.ReturnGeometry = true;
                    queryTask.ExecuteAsync(query);
                    break;

                case 1:
                    
                    QueryTask queryTask1 = new QueryTask((layers.ElementAt(1) as FeatureLayer).Url);
                    queryTask1.ExecuteCompleted += QueryTask_ExecuteCompleted1;
                    MessageBox.Show("k="+ k);
                    queryTask1.Failed += QueryTask_Failed;
                    Query query1 = new ESRI.ArcGIS.Client.Tasks.Query();
                    QueryDetailsDataGrid.DataContext = "null";
                    //query1.OutFields.AddRange(new string[] { "NAME_CNTY" });
                    ESRI.ArcGIS.Client.Geometry.Polygon queryGeometry1 = new ESRI.ArcGIS.Client.Geometry.Polygon();
                    queryGeometry1.Rings.Add(pPointCollection);
                    query1.Geometry = queryGeometry1;
                    query1.ReturnGeometry = true;
                    queryTask1.ExecuteAsync(query1);
                    break;
            }
        }
0 Kudos
JenniferNery
Esri Regular Contributor
The best way to know if it works is to try your code 😛

But one thing noticeable here is that you are still calling ExecuteAsync() successively without knowing if the first one has completed or still in process. The next ExecuteAsync() call must be done after the first one is completed (in the ExecuteCompleted eventhandler).

Try out your current code and you should see a run-time error. It's best to see the error to understand what's going on 🙂
0 Kudos