Select to view content in your preferred language

Is there any QML API support for calling a geoprocessing service?

4807
17
Jump to solution
11-11-2015 11:03 PM
by Anonymous User
Not applicable

I can't find anything in the docs so thought it worth asking...

Is there any QML API support for calling a geoprocessing service?

Cheers

-Paul

0 Kudos
17 Replies
jaykapalczynski
Honored Contributor

I was able to do this....but don know if this is the correct way....its the only time that I have been able to get a string or Object into the parameters...

BUT it show s my string two times....hmmmmm....wicked confused but trying

var viewshedParameters = ArcGISRuntimeEnvironment.createObject("GeoprocessingParameters",
                        {executionType: Enums.GeoprocessingExecutionTypeSynchronousExecute
                    });

var ObjectID = "2067";
var Comments = "stupid";

var params44 = "{OBJECTID:" + ObjectID + ",comments:" + Comments + "}";

// Add an input location to the geoprocessing parameters
var inputs = {};
inputs["Input_Observation_Point"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", { value: params44 },
                     );

viewshedParameters.inputs = inputs;
viewshedParameters.objectName = "Parameter Name";
                    
// Create the job that handles the communication between the application and the geoprocessing task
viewshedJob = viewshedTask.createJob(viewshedParameters);

// start the job
viewshedJob.start();‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

qml: {"objectName":"","objectType":"GeoprocessingJob","error":null,"objects":{},"json":{"geoprocessingJob":{"needGpMapServiceUrl":false,"parameters":
{"executionType":"execute","parameters":
[{"dataType":"GPString","direction":"esriGPParameterDirectionInput","name":"Input_Observation_Point","value":"
{OBJECTID:2067,comments:stupid}"}],"returnM":false,"returnZ":false},
"url":"https://xx/arcgis/rest/services/Tools/Update/GPServer/NewScriptToRun"},"jobType":"geoprocessingJob","status":"notStarted"},
"unknownJson":{},"unsupportedJson":{},"jobType":4,"messages":
{},"serverJobId":"","progress":0,"jobStatus":0,"error":null,"credential":
{"objectName":"","objectType":"Credential","error":null,"objects":
{},"username":"","password":"","authenticationType":0,"referer":"","token":"","tokenExpiry"
:null,"tokenServiceUrl":"","oAuthClientInfo":null,"oAuthAuthorizationCode":"","oAuthRefreshToken":
"","pkcs12Info":null,"sslRequired":false,"authenticatingHost":"","objects":{}},"requestConfiguration":
{"objectName":"","objectType":"RequestConfiguration","error":null,"objects":
{},"timeoutInterval":60,"maxNumberOfAttempts":5,"forcePost":false,
"issueAuthenticationChallenge":true,"userHeaders":{}},"url":"","checkStatusTaskStatus":0,"objects":{},"result":null,"parameters":
{"objectName":"","objectType":"GeoprocessingParameters","error":null,"objects":
{},"executionType":1,"inputs":{"Input_Observation_Point":
{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":
{},"parameterType":9,"value":"
{OBJECTID:2067,comments:stupid}"}},"outputSpatialReference":null,
"processSpatialReference":null,"returnM":false,"returnZ":false}}‍‍‍‍‍‍‍‍‍‍‍‍
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
LucasDanzinger
Esri Frequent Contributor

Here is a simplified example from our unit tests that shows how  to create parameters, add gp string input, and input to the parameters. It is very similar to what you have, but I'm wondering about your "params44" variable - do you want that to be a JSON string?

var gpParameters = ArcGISRuntimeEnvironment.createObject("GeoprocessingParameters",
                        {executionType: Enums.GeoprocessingExecutionTypeSynchronousExecute
                    });

var inputs = {};

inputs["InputString"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: "string value"});


gpParameters.inputs = inputs;
0 Kudos
jaykapalczynski
Honored Contributor

How would I format the string so that I can parse it or write it to variables once I get to the GP Service that is lookin gfor input parameters...


varItem = arcpy.GetParameterAsText(0)
varPublicPrivate = arcpy.GetParameterAsText(1)
varCaseNum = arcpy.GetParameterAsText(2)

0 Kudos
LucasDanzinger
Esri Frequent Contributor

In this case, you have 3 parameters, so you should be able to add 3 different inputs to the input json.

var inputs = {};

inputs["Item"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: "string value"});

inputs["PublicPrivate"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: "string value"});

inputs["CaseNumber"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: "string value"});
0 Kudos
jaykapalczynski
Honored Contributor

ahhhhh...ok that makes sense....I thought I had to build the parameters and then add it but realize that adding multiple inputs is building that parameters set

I can manually run the script on the server and it updates

I can run the GP service in ArcGIS Server and it updates

I still cannot call it to make it work from AppStudio....

Any ideas where it might be braking.....its works from the script and the GP Service in ArcGIS Server???

GeoprocessingTask {
    id: viewshedTask
        url: "https://xx/arcgis/rest/services/x/x/GPServer/NewScriptToRun"

       function calculateViewshed() {
            var varObjectID = "2067";
            var varItem = "shooter";

            var gpParameters = ArcGISRuntimeEnvironment.createObject("GeoprocessingParameters",
            {executionType: Enums.GeoprocessingExecutionTypeSynchronousExecute});
           
            var inputs = {};
            inputs["Item"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varItem});
            inputs["ObjectID"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varObjectID});

            gpParameters.inputs = inputs;

            viewshedJob = viewshedTask.createJob(gpParameters);

            viewshedJob.start();‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

import arcpy
from arcpy import env
import os

# Geting user input for project name, status, type, submital date and planner name  
varObjectID = arcpy.GetParameterAsText(0) 
varItem = arcpy.GetParameterAsText(1) ‍‍‍‍‍‍‍

whereClause = "[OBJECTID] = '{0}'".format(varObjectID)

fc = 'BoatingIncidents'
workspace = arcpy.env.workspace = r'C:\Users\xx\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\x@x.sde'

# Start an edit session. Must provide the workspace.
edit = arcpy.da.Editor(workspace)

# Edit session is started without an undo/redo stack for versioned data
#  (for second argument, use False for unversioned data)
edit.startEditing(False, False)

# Start an edit operation
edit.startOperation()

# UPDATE a row in the Feacture Class
Ucursor = arcpy.da.UpdateCursor(fc,["OBJECTID","Item"],whereClause)
for row in Ucursor:  
    irow = (varObjectID, varItem)  
    Ucursor.updateRow(irow)  
arcpy.RefreshActiveView()  

# Stop the edit operation.
edit.stopOperation()

# Stop the edit session and save the changes
edit.stopEditing(True)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
jaykapalczynski
Honored Contributor

Im a bit confused here....I am returning a few results in AppStudio

When I am building my inputs {} I order them like this

I console.log two variables the "inputs" AND "gpParameters"

Look at the results below of each variable....the order in which they are being built is different...I think this is throwing off the values when they get to the Service?

Am I correct to assume that the order does not matter.....BUT the input name matters when it is liked up to the GP Service Parameters and the name assigned to them?

Where as, if my Input name is "Item" I need a corresponding GP Service Parameter named "Item"

Funny thing is that I have that but when I run the code nothing happens....

Is there anyway I can error trap this and alert something from the App Studio Side to the arcgis Server GP tool side...

I cant find anything to test from the Submit on the App Studio Side and test if the connection was made to the GP Service

var gpParameters = ArcGISRuntimeEnvironment.createObject("GeoprocessingParameters",
     {executionType: Enums.GeoprocessingExecutionTypeSynchronousExecute});


            var inputs = {};
            inputs["Item"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varItem});
            inputs["PublicPrivate"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varPublicPrivate});
            inputs["CaseNumber"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varCaseNum});
            inputs["Comments"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varComments});
            inputs["Classification"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varClassification});
            inputs["ObjectID"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varObjectID});
            inputs["lastEditor"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varlastEditUser});
            inputs["LastDate"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varEditedDate});
            //inputs["InputString"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varEditedDate});


            console.log("inputs: " + JSON.stringify(inputs));

            gpParameters.inputs = inputs;

            console.log("gp parameters: " + JSON.stringify(gpParameters));‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

qml: inputs: {

"Item":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"shooter"},

"PublicPrivate":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"private"},

"CaseNumber":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"555"},

"Comments":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"stupid comment"},

"Classification":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"Boating"},

"ObjectID":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"2067"},

"lastEditor":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"jay"},

"LastDate":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"5/12/2019"}}

qml: gp parameters: {

"objectName":"","objectType":"GeoprocessingParameters","error":null,"objects":{},"executionType":1,"inputs":

{"CaseNumber":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"555"},

"Classification":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"Boating"},

"Comments":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"stupid comment"},

"Item":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"shooter"},

"LastDate":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"5/12/2019"},

"ObjectID":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"2067"},

"PublicPrivate":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"private"},

"lastEditor":{"objectName":"","objectType":"GeoprocessingString","error":null,"objects":{},"parameterType":9,"value":"jay"}},

"outputSpatialReference":null,"processSpatialReference":null,"returnM":false,"returnZ":false}

0 Kudos
LucasDanzinger
Esri Frequent Contributor

The order changes because JSON preserves order whereas the underlying data type in GeoprocessingParameters.input does not (QVariantMap). However, I don't believe the order should matter - to my knowledge, the REST request that comes in assigns the inputs via name and not index. I think something else must be going on here and the order is a red herring.

0 Kudos
jaykapalczynski
Honored Contributor

Turns out it was the service URL...I changed to the second one and it worked

I added the "submitJob" and it worked.....

"https://xx/arcgis/rest/services/xx/Update/GPServer/NewScriptToRun"
"https://xx/arcgis/rest/services/xx/Update/GPServer/NewScriptToRun/submitJob"