Select to view content in your preferred language

Returning multiple results from a geoprocessing task

2675
3
05-16-2013 01:08 PM
AngelGonzalez
Frequent Contributor
I have  Geoprocessing Task (submitted Async) which runs on the server (10.1SP1) without any issues. The results/outputs from this geoprocessing task is basically two features layers and two tables(GPRecordSet). (see pic below). Using the "Clip Features" sample http://resources.arcgis.com/en/help/silverlight-api/samples/start.htm#ClipFeatures I am able to get to one of the features and add it to my SL app.

My problem is how do I reference the second feature layer so I can also add it to the map? In addition I need to also read the two tables and bring them "in" to the SL application.  The following code :

geoprocessorTask.GetResultDataAsync(e.JobInfo.JobId, "out_directions"); 


only allows me to reference only one output form my geoprocessing Task.

How do you go about accessing the additional outputs  of a gpTask? I have seen some samples using a "if else" stmt checking to see if the output is a type of GPFeatureRecordSetLayer or GPRecordSet but what happens if you have more than one type of these outputs like I have. I want to take the first output and do something then take in the second output and so something so on and so on. Does anyone has some sample code on how to do this?

Thanks
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor

Code:

geoprocessorTask.GetResultDataAsync(e.JobInfo.JobId, "out_directions");
only allows me to reference only one output form my geoprocessing Task.

How do you go about accessing the additional outputs  of a gpTask?


I think you can execute sequentially GetResultDataAsync for all your output parameters. i.e in the Handler, get the parameter name and execute again GetResultDataAsync  for the next parameter (untile the last one)
0 Kudos
AngelGonzalez
Frequent Contributor
I tried the following code but only the first call of GetResultDataAsync completes(message box appears for the parameter called), therefore you cannot   "execute sequentially GetResultDataAsync". I switched the order of the GetResultDataAsync, "out_directions" first and then "out_stops" second and the correct message box appears for the called parameter but I cannot get both to appear.

Am I doing something wrong or is this not possible?

void geoprocessorTask_JobCompleted(object sender, JobInfoEventArgs e)
        {
            Geoprocessor geoprocessorTask = sender as Geoprocessor;
            geoprocessorTask.GetResultDataCompleted += new EventHandler<GPParameterEventArgs>(geoprocessorTask_GetResultDataCompleted);
            

            geoprocessorTask.GetResultDataAsync(e.JobInfo.JobId, "out_stops");

            geoprocessorTask.GetResultDataAsync(e.JobInfo.JobId, "out_directions");
           
        }


 void geoprocessorTask_GetResultDataCompleted(object sender, GPParameterEventArgs e)
        {
            if (e.Parameter.Name == "out_stops" )
            {
                MessageBox.Show("out_stops");
                
            }


            // For Out Direction
            // if (e.Parameter is GPFeatureRecordSetLayer)
            if (e.Parameter.Name == "out_directions")
            {
                 MessageBox.Show("out_directions");

            }
         }
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I tried the following code but only the first call of GetResultDataAsync completes(message box appears for the parameter called), therefore you cannot   "execute sequentially GetResultDataAsync".


That�??s what I was failing to say clearly�?� execute the second GetResultDataAsync when the first one is completed, i.e in the geoprocessorTask_GetResultDataCompleted Handler.

In short:
   1) call your first GetResultDataAsync
   2) in the Handler get the parameter name
   3) execute your specific code for this parameter name
   4) call again GetResultDataAsync for the next parameter (until the last one)
0 Kudos