Select to view content in your preferred language

Trouble with iOS geoprocessing tool

2836
3
11-12-2014 06:06 PM
ChrisMartin1
Deactivated User

Hello,

I have a server GP tool that runs well from the web REST interface as well as through JavaScript on another page.  However, I cannot get the iOS version to work.  The GP tool takes about 6 seconds to run, so I believe I need it to be asynchronous.  Here is my code:

// Build geoprocessor

    AGSGeoprocessor* geoprocessor = [AGSGeoprocessor geoprocessorWithURL:gpURL];

    geoprocessor.delegate = self;

  

    // Geoprocessor build parameters

    AGSGPParameterValue *pointX = [AGSGPParameterValue parameterWithName:@"Point_X" type:AGSGPParameterTypeDouble value:[NSNumber numberWithDouble:self.wgsPoint.x]];

    AGSGPParameterValue *pointY = [AGSGPParameterValue parameterWithName:@"Point_Y" type:AGSGPParameterTypeDouble value:[NSNumber numberWithDouble:self.wgsPoint.y]];

    AGSGPParameterValue *tile = [AGSGPParameterValue parameterWithName:@"File_Name" type:AGSGPParameterTypeString value:fullTileName];

   

    // GP Parameters to array

    NSArray *params = [NSArray arrayWithObjects:pointX, pointY,tile, nil];

    //Run GP tool with asych delay

    geoprocessor.interval = 10;

    [geoprocessor submitJobWithParameters:params];

}

//this is the delegate method that gets called when job completes successfully

- (void)geoprocessor:(AGSGeoprocessor *)geoprocessor operation:(NSOperation *)op didSubmitJob:(AGSGPJobInfo *)jobInfo {

   

    NSLog(@"Geoprocessing Job Submitted!");

}

//this is the delegate method that gets called when gp job completes successfully.

- (void)geoprocessor:(AGSGeoprocessor *) geoprocessor operation:(NSOperation *) op jobDidSucceed:(AGSGPJobInfo *) jobInfo {

   

    NSLog(@"Geoprocessing Job Succeeded!");

}

- (void)geoprocessor:(AGSGeoprocessor *) geoprocessor operation:(NSOperation *) op jobDidFail:(AGSGPJobInfo *) jobInfo {

   

    NSLog(@"Geoprocessing Job Failed!");

}

The query usually returns something like this:

{

"results": [

  {

  "paramName": "Solar_Value",

  "dataType": "GPString",

  "value": "21865.1328496\n39619.3044974\n84117.1905997\n126159.758433\n167013.891821\n175695.394165\n174199.414434\n143438.383851\n97395.6361771\n51997.4207866\n25002.0289475\n16517.4218279\n"

  },

  {

  "paramName": "Solar_Hours",

  "dataType": "GPString",

  "value": "271.56088993\n278.722662602\n356.971440711\n391.0648334\n448.550531915\n458.714285714\n457.440909091\n422.655603938\n370.273648649\n313.029113248\n271.510752688\n258.134615385\n"

  }

],

"messages": []

}

However, I can't get any of the delegates to fire.  What am I doing incorrectly?  Is there a better way to implement this?

Thank you so much for any help you can provide.  I've been running into a wall with this for a week now.

0 Kudos
3 Replies
Nicholas-Furness
Esri Regular Contributor

I think your instance of AGSGeoprocessor is going out of scope and so is being deallocated before the GP Tool finishes.

Try creating a class-level property instead:

     @property (nonatomic, strong) AGSGeoprocessor *geoprocessor;

And change the code to reference that property instead:

// Build geoprocessor

    self.geoprocessor = [AGSGeoprocessor geoprocessorWithURL:gpURL];

            self.geoprocessor.delegate = self;

         

          ...

    //Run GP tool with asych delay

    self.geoprocessor.interval = 10;

    [self.geoprocessor submitJobWithParameters:params];

}

Hopefully that'll get you rolling.

Nick

ChrisMartin1
Deactivated User

Thank you for taking the time to answer this.

Ive made the changes you suggested and I still do not get any results.  I figure at least the didSubmitJob should fire off and NSLog something.

I added this to the *.h file:

@property (nonatomic, strong) AGSGeoprocessor *geoprocessor;

and changed this in the *.m file:

    // Build geoprocessor

    self.geoprocessor = [AGSGeoprocessor geoprocessorWithURL:gpURL];

    self.geoprocessor.delegate = self;

  

    //Run GP tool with asych delay

    self.geoprocessor.interval = 10;

    [self.geoprocessor submitJobWithParameters:params];

Here is the github (*.m/*.h = MapViewController):

MN-Solar-iOS-App/MN Solar App at arcgis · andywalz/MN-Solar-iOS-App · GitHub

Is it possible I haven't formatted my delegates or called the right op?  I tried to call all of the ones that seemed reasonable to catch whatever return I could get.

Thank you!

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Your GP Service only has the Execute endpoint, so you should use the synchronous call:

    [self.geoprocessor executeWithParameters:params];

However, that still doesn't work for me, but I'm not convinced that I know how to get your GP Service to work. I'm unable to run it from the web interface. If using the above call doesn't work, can you give me some parameters that do work properly from the web interface here: Execute Task (Script)

Cheers,

Nick.

0 Kudos