Select to view content in your preferred language

Access Multiple Results from custom GP tool

1231
3
Jump to solution
04-15-2013 06:09 AM
ErikMartin
Frequent Contributor
Hi All,

I have a custom GP Service. It returns two results (esriGPParameterDirectionOutput) a FeatureSet of points (GPFeatureRecordSetLayer) and a RecordSet (GPRecordSet) of summary statistics about those points. I am successfully able to access and symbolize the points and bring the attributes into a datagrid. I'm not sure, though, how to access the second result. (which will go into a separate datagrid)

Here's what I have working so far -- just accessing the point results and displaying them. I left out the code to put the attributes into a datagrid, but that's working, too.

   protected function gp_jobCompleteHandler(event:GeoprocessorEvent):void
   {
    if (event.jobInfo.jobStatus == JobInfo.STATUS_SUCCEEDED)
    { 
     gp.addEventListener(GeoprocessorEvent.GET_RESULT_DATA_COMPLETE, onGetResult);
     gp.getResultData(gp.submitJobLastResult.jobId, "Result");
     var messages:Array = event.jobInfo.messages;
     var count:int = messages.length;
     var index:int = count-2;
     var message:String = messages[index].description;
     statusArea.appendText(message + "\n");
     statusArea.appendText("Drawing result graphics..." + "\n");
    }
    else
    {
     var messages1:Array = event.jobInfo.messages;
     var count1:int = messages1.length;
     var index1:int = count1-4;
     var message1:String = messages1[index1].description;
     statusArea.appendText(message + "\n");
     Alert.show("Geoprocessing Error:\n" + message1);
    }
   }


and then:

   protected function onGetResult(event : GeoprocessorEvent) : void
   {     
    myGraphicsLayer.renderer = ResultRenderer();
    var pv:ParameterValue = event.parameterValue;
   
    fs = new FeatureSet;
    fs = pv.value as FeatureSet;
    
    for each(var graphic:Graphic in fs.features)
    {
     graphic.addEventListener(MouseEvent.CLICK, graphic_clickHandler);
     graphic.addEventListener(MouseEvent.DOUBLE_CLICK, graphic_doubleClickHandler)
     myGraphicsLayer.add(graphic);
    } 
    map.addLayer(myGraphicsLayer);       
    
    var resultAttribute:Array = fs.attributes;
    resultAttributes= new ArrayCollection(resultAttribute);
    
    CursorManager.removeBusyCursor();

    
   
   }


Here's what I'm trying to do:
   protected function gp_jobCompleteHandler(event:GeoprocessorEvent):void
   {
    if (event.jobInfo.jobStatus == JobInfo.STATUS_SUCCEEDED)
    { 
     gp.addEventListener(GeoprocessorEvent.GET_RESULT_DATA_COMPLETE, onGetResult);
     gp.getResultData(gp.submitJobLastResult.jobId, "Result");
                                        gp.getResultData(gp.submitJobLastResult.jobId, "SummaryStats"); 
     var messages:Array = event.jobInfo.messages;
     var count:int = messages.length;
     var index:int = count-2;
     var message:String = messages[index].description;
     statusArea.appendText(message + "\n");
     statusArea.appendText("Drawing result graphics..." + "\n");
    }
    else
    {
     var messages1:Array = event.jobInfo.messages;
     var count1:int = messages1.length;
     var index1:int = count1-4;
     var message1:String = messages1[index1].description;
     statusArea.appendText(message + "\n");
     Alert.show("Geoprocessing Error:\n" + message1);
    }
   }


and then:

   protected function onGetResult(event : GeoprocessorEvent) : void
   {     
    myGraphicsLayer.renderer = ResultRenderer();
    var pv:ParameterValue = event.parameterValue;
                                var pv2:ParameterValue = event.parameterValue; // This seems wrong -- how do I tell it to take the second of the output parameters?
   
    fs = new FeatureSet;
    fs = pv.value as FeatureSet;
    
                                rs = new RecordSet; // This doesn't work.  "RecordSet" isn't an option
                                rs = pv2.value as RecordSet; // This obviously doesn't work either

    for each(var graphic:Graphic in fs.features)
    {
     graphic.addEventListener(MouseEvent.CLICK, graphic_clickHandler);
     graphic.addEventListener(MouseEvent.DOUBLE_CLICK, graphic_doubleClickHandler)
     myGraphicsLayer.add(graphic);
    } 
    map.addLayer(myGraphicsLayer);       
    
    var resultAttribute:Array = fs.attributes;
    resultAttributes= new ArrayCollection(resultAttribute);
    
                                var sumStatsAttribute = rs.attributes; // This obviously isn't working since 'rs' isn't working
    sumStatsAttributes = new ArrayCollection(sumStatsAttribute);

    CursorManager.removeBusyCursor();

   }


Do I need a separate event listener for the SummaryStats table?

As always, any advice would be greatly appreciated.

Thanks,
-Erik
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ErikMartin
Frequent Contributor
In case this might help someone in the future, here's the solution I came up with.  I don't know if its the best or most efficient solution, but it works.  Essentially, I added a conditional in my onGetResult function to direct the flow based on the parameter name.  It then calls one of two separate functions for either symbolizing the result points or adding the summary stats to an array (for display in a data grid).  onGetResult is called twice -- once for each result returned.  Here's the completed code (the gp_jobCompleteHandler is unchanged)

protected function onGetResult(event : GeoprocessorEvent) : void {         if (event.parameterValue.paramName == "Result")  {   var pv1:ParameterValue = event.parameterValue;   symbolizeResults(pv1);  }    if (event.parameterValue.paramName == "SummaryStats")  {   var pv2:ParameterValue = event.parameterValue;   addSumStats(pv2);  } }   private function symbolizeResults(pv1:ParameterValue):void {  fs = new FeatureSet;  fs = pv1.value as FeatureSet;    for each(var graphic:Graphic in fs.features)  {   graphic.addEventListener(MouseEvent.CLICK, graphic_clickHandler);   graphic.addEventListener(MouseEvent.DOUBLE_CLICK, graphic_doubleClickHandler)   myGraphicsLayer.add(graphic);  }   map.addLayer(myGraphicsLayer);   zoomToGraphics();    var resultAttribute:Array = fs.attributes;  resultAttributes= new ArrayCollection(resultAttribute); }   private function addSumStats(pv2:ParameterValue):void {  rs = new FeatureSet;  rs = pv2.value as FeatureSet;        var sumStatsAttribute:Array = rs.attributes;  sumStatsAttributes = new ArrayCollection(sumStatsAttribute);  }

View solution in original post

0 Kudos
3 Replies
ErikMartin
Frequent Contributor
OK I think I've figured out 2 things.  First, ParameterValue looks like it takes the name of the FeatureSet.  Also the same link shows that the Flex Type for Record Set is Feature Set.  Based on these, it looks like my code in question should be:

   protected function onGetResult(event : GeoprocessorEvent) : void
   {     
    myGraphicsLayer.renderer = ResultRenderer();
    var pv:ParameterValue = event.parameterValue["Result"];
    var pv2:ParameterValue = event.parameterValue["SummaryStats"];
   
    fs = new FeatureSet;
    fs = pv.value as FeatureSet;
    
    rs = new FeatureSet;
    rs = pv2.value as FeatureSet;


   }


still not working yet, but optimistic...
0 Kudos
ErikMartin
Frequent Contributor
This solution I thought I had has not worked for me. I have also tried:

var pv:ParameterValue = event.parameterValue.paramName["Result"];
var pv2:ParameterValue = event.parameterValue.paramName["SummaryStats"];


Any advice would still be welcome. Thanks
0 Kudos
ErikMartin
Frequent Contributor
In case this might help someone in the future, here's the solution I came up with.  I don't know if its the best or most efficient solution, but it works.  Essentially, I added a conditional in my onGetResult function to direct the flow based on the parameter name.  It then calls one of two separate functions for either symbolizing the result points or adding the summary stats to an array (for display in a data grid).  onGetResult is called twice -- once for each result returned.  Here's the completed code (the gp_jobCompleteHandler is unchanged)

protected function onGetResult(event : GeoprocessorEvent) : void {         if (event.parameterValue.paramName == "Result")  {   var pv1:ParameterValue = event.parameterValue;   symbolizeResults(pv1);  }    if (event.parameterValue.paramName == "SummaryStats")  {   var pv2:ParameterValue = event.parameterValue;   addSumStats(pv2);  } }   private function symbolizeResults(pv1:ParameterValue):void {  fs = new FeatureSet;  fs = pv1.value as FeatureSet;    for each(var graphic:Graphic in fs.features)  {   graphic.addEventListener(MouseEvent.CLICK, graphic_clickHandler);   graphic.addEventListener(MouseEvent.DOUBLE_CLICK, graphic_doubleClickHandler)   myGraphicsLayer.add(graphic);  }   map.addLayer(myGraphicsLayer);   zoomToGraphics();    var resultAttribute:Array = fs.attributes;  resultAttributes= new ArrayCollection(resultAttribute); }   private function addSumStats(pv2:ParameterValue):void {  rs = new FeatureSet;  rs = pv2.value as FeatureSet;        var sumStatsAttribute:Array = rs.attributes;  sumStatsAttributes = new ArrayCollection(sumStatsAttribute);  }
0 Kudos