Getting results from submitJob:

5273
16
04-28-2010 01:26 PM
DorothyMortenson
Deactivated User
Hello,
I have a gp.submitJob that works, as in it goes and runs the job as expected. It creates several GIS files. (this works if I just run the gp.submitJob(params)).

Now I want to get the results to come back (get a specific featureclass, called wshed_results.gdb\wshed_1)

I don't really know what I'm doing, but here is what I have so far.  I am getting a "1067: Implicit coercion of a value of type Function to an unrelated type mx.rpc:IResponder." error.

Any ideas on what I really should be doing?
Dorothy

//===============
...
                    gp.submitJob(params, completeCallback, statusCallback);
                   
                }



private function statusCallback(jobInfo):void
{
  Alert.show(jobInfo.jobStatus);
}
private function completeCallback(jobInfo):void
{
  gp.getResultData(jobInfo.jobId, result.value.features, displayResult);

}

private function displayResult(result, messages):void
{
    var features = result.value.features;
    var graphic:Graphic = new Graphic(features);
     for each (var graphic:Graphic in event.executeResult.parameterValues[0].value.features)
     {
      graphic.symbol = watershedSimpleFill;
       myGraphicsLayer.add(graphic);
     }

/================
Tags (2)
0 Kudos
16 Replies
seanlo
by
Emerging Contributor
Ok, I'll table that question for now.

I made a test model builder that now works and shows the results when testing the rest service.  it does not show up in my map application, however.

What does the rest of your code look like, as it pertains to the ArcGISDynamicMapServiceLayeror a GraphicsLayer?
Did you have to create a special ArcGISDynamicMapServiceLayer for this?

Thank you.
Dorothy



No you just add the map service result as a layer to the main map. The map service result is already a layer btw, so you just add it to the main map with the code i showed above.
0 Kudos
DorothyMortenson
Deactivated User
I think I'm close...

I have a geoprocessing service (as a toolbox, not as a result map service).
It works as a service. I get two output files: one is a feature class, the other is a text file.

(My problem earlier was I wrote these files to a specific directory instead of the scratchworkspace).

When I run my Flex application, I can get the text file to popup, but I still cannot get the feature class to draw.

I tried the tool in ArcMap - it works, but the resulting feature class is not turned on (checked).

Anything else I should try in my Flex application? In theory, this should work with a toolbox, right?


var imageParameters:ImageParameters = new ImageParameters();
var myImageLayer:GPResultImageLayer = gp.getResultImageLayer(event.jobInfo.jobId,"wshed_1_select",imageParameters)
myImageLayer.alpha = 1;
Map.addLayer(myImageLayer);
0 Kudos
AaronBarkhurst
Emerging Contributor
Dorothy,

I ran into the exact same problem and tried everything to get this figured out. As it would turn out, it was  projection issue. At the end of my model, I had to run the shapefile through the project tool and put it into WGS 84. I also had to set the map document to WGS 84 and then republish. It was after I did these steps that my GP service results finally displayed in our Flex application. Hope that helps.

Aaron
0 Kudos
DorothyMortenson
Deactivated User
I had thought that might be the case, however, I am not doing any projections. I also set the spatial reference:

<esri:Geoprocessor id="gp"
url="http://geiser.wrd.state.or.us/owrd_gis/rest/services/junk9a/GPServer/Junk4b"
concurrency="last"
outputSpatialReference="{Map.spatialReference}"
processSpatialReference="{Map.spatialReference}" />

I did a little test to see if I'm even getting an object in Flex and it does not appear to be so. But I don't know if this code is accurate:

var imageParameters:ImageParameters = new ImageParameters();
var myImageLayer:GPResultImageLayer = gp.getResultImageLayer(event.jobInfo.jobId,"wshed_1_select",imageParameters)
var obj:Object = gp.getResultImageLastResult;
Alert.show(String(obj));
Alert.show(String(myImageLayer));

myImageLayer.alpha = 1;
Map.addLayer(myImageLayer);


The object comes back as null
The myImageLayer comes back as GPResultImageLayer224

Does that mean anything to anyone?

My service is live right now, if that might show some insight.

http://geiser.wrd.state.or.us/owrd_gis/rest/services/junk9a/GPServer/Junk4b
0 Kudos
DorothyMortenson
Deactivated User
I got some help from ESRI.  Here is an entire script that works. Some things I learned:
* You do not have to have a map service for the results. It will go right onto your ArcGISDynamicMapServiceLayer.
* There's two kinds of listeners you need: One to check to see if the job is done; the other to do something about it when it is done.
* Here's what you need to do to set up the output.
- In ArcCatalog, right click on your tool to bring up the Properties.
- You will need to specify what your output will be, say result_wshed.  I set this to a Feature Class.
- I used these settings:
    -- Type = Required
    -- Direction = Output
    -- MultiValue = No
    -- Default = %scratchworkspace%\scratch.gdb\result_wshed
    -- Environment = (I left blank)
    -- Filer = None
    -- Obtained from (I left blank)
    -- Symbology = (pointed to where a file was in the scratch workspace, tho I don't think it's necessary).

I also had an output file that was a text file.  I set this to a Text File. Settings are similar except
    -- Default = %scratchworkspace%\analysis_report.txt

Within Python, you bring in these as they are a parameter.  I did my usual geoprocessing and when I was done, I copied the data to these output files in the scratchworkspace. I may change that, as I don't want to do any more processing than needed, but it works for now.

Here's some bits from Python:

    # Script arguments...
    xcoord_ft   = sys.argv[1]
    ycoord_ft   = sys.argv[2]
    WRD_ID      = sys.argv[3]
    stream_name = sys.argv[4]
    stream_code = sys.argv[5]
    basin       = sys.argv[6]
    basin_num   = sys.argv[7]
    huc_code    = sys.argv[8]
    peak_region = sys.argv[9]

    # These two are parameters for the output...
    result_wshed = sys.argv[10]
    analysis_report = sys.argv[11]

    <geoprocessing code here....>

    # Copies the report to the scratch workspace
    shutil.copyfile(output_report, analysis_report)

    # Copies the result watershed to the scartch workspace
    gp.copy_management(wshed_1,result_wshed)


Now for the MXML that made it work...

======================================

<?xml version="1.0" encoding="utf-8"?>
<mx:Application   
      xmlns:mx="http://www.adobe.com/2006/mxml"   
      xmlns:esri="http://www.esri.com/2008/ags"   
      layout="absolute">
          
      <mx:Script>
            <![CDATA[
             import com.esri.ags.Graphic;
             import mx.rpc.events.FaultEvent;
             import mx.rpc.AsyncResponder;
               import mx.controls.Alert;                 
               import com.esri.ags.SpatialReference;
               import com.esri.ags.events.GeoprocessorEvent;
               import com.esri.ags.tasks.FeatureSet;
               import com.esri.ags.tasks.ParameterValue;
                 
             private function RunTask():void
             { 
                 var outSR:SpatialReference = new SpatialReference(2992);
                 var processSR: SpatialReference = new SpatialReference(2992);
                 var params:Object = {
                       "xcoord_ft": "1000"
                 };
                 gp.outputSpatialReference = outSR;
                 gp.processSpatialReference = processSR;               
                 gp.submitJob(params);                          
             }
             
               private function onFault(fe:FaultEvent, token:Object = null):void
               {
                Alert.show(fe.toString());
               }
                 
            private function onJobComplete(event:GeoprocessorEvent):void
            {           
            gp.addEventListener(GeoprocessorEvent.GET_RESULT_DATA_COMPLETE, onGetResult);
            gp.getResultData(event.jobInfo.jobId, "wshed_1_select");
            var jobIDNumber:String = new String(event.jobInfo.jobId);
                  var jobURL:String    =   new String("http://<your server here>/arcgisjobs/junk9a_gpserver/" + String(jobIDNumber) + "/scratch/analysis_report.txt");
                  var request:URLRequest = new URLRequest(String(jobURL))
                  var loader:URLLoader = new URLLoader();
                  navigateToURL(request);  
            }
                  
            private function onGetResult(event:GeoprocessorEvent):void
            {
             var pv:ParameterValue = event.parameterValue;
              var fs:FeatureSet = pv.value as FeatureSet;
              if (fs != null)
              {
               for each(var graphic:Graphic in fs.features){
                graphic.symbol = sfs_default;
                myGraphicsLayer.add(graphic);
               }
              }                
              else
              {
               Alert.show("nothing to return");
              }
            } 
            ]]>
      </mx:Script>
     
      <esri:SimpleFillSymbol id="sfs_default"/>

      <mx:Button x="10" y="10" label="Run GP" click="RunTask()"/>
      <esri:Map id = "map" x = "50" y="50">     
            <esri:ArcGISDynamicMapServiceLayer
                  url="http://navigator.state.or.us/ArcGIS/rest/services/basemap/MapServer"/>
            <esri:GraphicsLayer id="myGraphicsLayer"/>
      </esri:Map>
     
      <esri:Geoprocessor       
            id="gp" fault="onFault(event)" jobComplete="onJobComplete(event)"      
            url="http://<your server here>/rest/services/junk9a/GPServer/Junk4b"                 
            />
     
</mx:Application>

======================================

Thanks everyone!  Good luck with your projects!

Dorothy
0 Kudos
seanlo
by
Emerging Contributor
Glad to hear that you managed to solve the problem! Sorry for the slow reply.. been busy with two projects. T_T
0 Kudos
SubramanianSwaminathan
Occasional Contributor
@Dorothy-

Could you please share more of your python script related to the gp script tool?

I have a simple ExporttoPDF python script which I have converted onto a gp service on ArcGIS Server. SubmitJob executes successfully and the pdf file is created in the local drive.

I do not know how to copy the local file into the scratch workspace of the job and set it as output parameter so that I can access the output through a Flex application similar to you what you do.

Thanks
Subu
0 Kudos