Select to view content in your preferred language

How to manage multiple results from Asynch geoprocessing tool?

2258
14
Jump to solution
08-23-2012 05:15 AM
BrianMulcahy
Occasional Contributor
I have a geoprocessing tool that is returning both a GPDataFile and a GPFeatureRecordSetLayer. How would I access both of these results?

I know how to do it in C#/Silverlight but I am new to Javascript and don't have a handle on all of the nomenclature for it yet.

Here is the C#/Silverlight Code
private void GeoprocessorTask_JobCompleted(object sender, JobInfoEventArgs e)         {             if (e.JobInfo.JobStatus != esriJobStatus.esriJobSucceeded)             {                 MessageBox.Show("Geoprocessor service failed" );                 ProcessingTextBlock.Text = "";                  ProcessingTextBlock.Visibility = Visibility.Collapsed;                                  GraphicsLayer graphicsLayer = Map.Layers["Results"] as GraphicsLayer;                 GraphicsLayer startLayer = Map.Layers["MyGraphicsLayer"] as GraphicsLayer;                 graphicsLayer.ClearGraphics();                 startLayer.ClearGraphics();                 this.SpreadModel.IsOpen = !this.SpreadModel.IsOpen;              }             else              {                 Geoprocessor geoprocessorTask = sender as Geoprocessor;                 geoprocessorTask.GetResultDataCompleted += (s1, ev1) =>                     {                                                                       if (ev1.Parameter is GPFeatureRecordSetLayer)                         {                             GraphicsLayer graphicsLayer = Map.Layers["Results"] as GraphicsLayer;                              GPFeatureRecordSetLayer gpLayer = ev1.Parameter as GPFeatureRecordSetLayer;                                  foreach (Graphic graphic in gpLayer.FeatureSet.Features)                             {                                                                                                     graphic.Symbol = LayoutRoot.Resources["MyGreenFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;                                                                   graphicsLayer.Graphics.Add(graphic);                                                   }                          }                         if (ev1.Parameter is GPDataFile)                         {                             GPDataFile gpdata = ev1.Parameter as GPDataFile;                             Uri uri = new Uri(gpdata.Url);                             btndownload.NavigateUri = uri;                              urltodownload = uri;                                                           geoprocessorTask.GetResultDataAsync(e.JobInfo.JobId, "RelativeSpread");                                                      }                      };                  geoprocessorTask.GetResultDataAsync(e.JobInfo.JobId, "Outfile");                               }         }


Basically would like to take my C# code and convert it to Javascript /Dojo.
0 Kudos
14 Replies
__Rich_
Deactivated User
I don't think I understand. I only have one task giving me two results. How do I access the results without firing the getResultData twice, once for each result?

Thanks for your help I really do appreciate it.


Ah, that might be me - only skim-reading the code, let me check again.  (not doing too well with this stuff today!)
0 Kudos
BrianMulcahy
Occasional Contributor
Ah, that might be me - only skim-reading the code, let me check again.  (not doing too well with this stuff today!)


Here is my geoprocessing code

 function SpreadModel1(){
            
                if (map.graphics.graphics.length === 0) {
                    alert('Please place your starting point');
                    return;
                }
                //get starting point
                var features = [];
                features.push(map.graphics.graphics[0]);
                var featureSet = new esri.tasks.FeatureSet();
                featureSet.features = features;
                //get Break Values
                var box0 = dijit.byId("dbv1");
                gp = new esri.tasks.Geoprocessor("http://blah/ArcGIS/rest/services/APHIS/SpreadModel1/GPServer/APHIS%20Group1");
                
                
                
                var params = {
                    "Input_Layer": dijit.byId('spreadmodel1layers').value,
                    "Start_locations": featureSet,
                    "Default_break_values": box0.attr("value")
                }
                
                esri.show(loading);
                gp.submitJob(params, completeCallback, statusCallback, function(error){
                    alert(error);
                    esri.hide(loading);
                });
            }
0 Kudos
__Rich_
Deactivated User
Nothing obvious leaps out, the only thing I've spotted so far is a missing semi colon!

gp.getResultData(jobInfo.jobId,"Outfile",downloadFile)


Perhaps someone with sharper eyes can spot an issue, I've tried re-jigging the sample to run multiple concurrent getDataResult() requests and can't recreate an issue so far.

Do both callbacks actually get invoked?
0 Kudos
BrianMulcahy
Occasional Contributor
Nothing obvious leaps out, the only thing I've spotted so far is a missing semi colon!

gp.getResultData(jobInfo.jobId,"Outfile",downloadFile)


Perhaps someone with sharper eyes can spot an issue, I've tried re-jigging the sample to run multiple concurrent getDataResult() requests and can't recreate an issue so far.

Do both callbacks actually get invoked?


well it was working with the deferred statement.

So now that I commented out the deferred statement and went back to just the simple getResultData, it works now.......
I am in awe about why it didn't work before, as both callbacks were getting invoked and I could see everything running without error.

I think I am just going to call it a week.

Thanks for the help.
0 Kudos
__Rich_
Deactivated User
Ok, so everything's working as it should with no extra workarounds e.g. waiting?

If so, cool!

Time for a beer!

Hope I helped a bit 🙂
0 Kudos