I have an application that I am testing out. But first a little back information
My Steps:
I created a simple Python script that creates a new point in a FeatureClass. (see below)
I then add this script to a toolbox
I then set the parameters for the Classification, X and Y in the properties (Classifcation=string, XY are set to double)
I can run this with hard coded values via IDLE and it works fine as seen below
Next:
Seeing that the script works in IDLE I publish a GP Service from the process I just ran to my ArcGIS Server.
I can run the GP Service from our ArcGIS Server and it runs fine.
Finally:
I then reference this from AppStudio and attempt to run it with hard coded values as seen below
1. I can get it to run and create a new point THIS WORKS
2. BUT the XY coordinates I feed it don't appear where they should. If I use the EXACT same ones that I use in the script below they don't show up in the same place as the points added .
The data in SDE is WGS 84 decimal degrees.
MY ISSUE:
If I hard code the XY in the script and run from IDLE it works fine
If I add the exact same Coordinates from the GP Service that I published in ArcGIS Service it works fine
If I hard code the exact same Coordinates as seen below in AppStudio it puts the points at roughly (-78, 39)
I dont see where and how to coordinates I am submitting in the job are being converted from (-77.43153, 37.527056) to (-78, 39)
Funny thing is if I export the data and calculate XY for the points the ones done through AppStudio are truncated and have no Sig Figs, while the points added in the Service and Script via IDLE have sig figs.
Very confused. Seems the sig figs are being dropped but then again the XY corrds are goin from 77 to 78 and 37 to 39?
I know this is a lot to digest but figure someone might have seen this before?
import arcpy
from arcpy import env
import os
#varXCoord = arcpy.GetParameterAsText(4)
#varYCoord = arcpy.GetParameterAsText(5)
#varClassification = arcpy.GetParameterAsText(6)
varClassification = "New Classification"
varYCoord = "37.527056"
varXCoord = "-77.43153"
fc = 'xE.DBO.xxx'
workspace = arcpy.env.workspace = r'C:\Users\x\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\x@xxxxxxx.sde'
## Start an edit session. Must provide the workspace.
edit = arcpy.da.Editor(workspace)
edit.startEditing(False, False)
## Start an edit operation
edit.startOperation()
row_values = [( varXCoord ,varYCoord, varClassification)]
print(row_values)
cursor = arcpy.da.InsertCursor(fc,['SHAPE@X', 'SHAPE@Y', 'Classification'])
for row in row_values:
cursor.insertRow(row)
del cursor
## Stop the edit operation.
edit.stopOperation()
## Stop the edit session and save the changes
edit.stopEditing(True)
GeoprocessingTask {
id: insertCursorTask
url: "https://xxx.xx.xxxx.xx/arcgis/rest/services/xxx/InsertCursor/GPServer/InsertCursor/submitJob"
function insertFunction() {
var varClassification = "New Classification";
var xlocation = -77.43153;
var ylocation = 37.527056;
var gpParametersInsert = ArcGISRuntimeEnvironment.createObject("GeoprocessingParameters",
{executionType: Enums.GeoprocessingExecutionTypeSynchronousExecute});
var inputsI = {};
inputsI["classification"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varClassification});
inputsI["SHAPE@X"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: xlocation });
inputsI["SHAPE@Y"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: ylocation });
//var inputresults = inputs;
gpParametersInsert.inputs = inputsI;
// Create the job that handles the communication between the application and the geoprocessing task
insertCursorJob = insertCursorTask.createJob(gpParametersInsert);
console.log("gp job: " + JSON.stringify(insertCursorJob));
insertCursorJob.start();
}
Solved! Go to Solution.
It has to be on the QML side of things....If I manually enter data into the GP Service I published it works fine....its not until I push from AppStudio that it breaks....right now it just puts them off the coast of Africa....no matter what data I send to it....
I can change the XY to anything I want and it still puts them off Africa
The Parameters seen below are all string except the X and Y
I reviewed the links you sent and nothing stands out to me....
var varItem = "shooter";
var varPublicPrivate = "public";
var varCaseNum = "77";
var varComments = "comments jump jump up and get down";
var varClassification = "Boating";
var xlocation = -96.43153;
var ylocation = 39.527056;
var gpParametersInsert = ArcGISRuntimeEnvironment.createObject("GeoprocessingParameters",
{executionType: Enums.GeoprocessingExecutionTypeAsynchronousSubmit});
var inputsI = {};
inputsI["Item"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varItem});
inputsI["PublicPrivate"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varPublicPrivate});
inputsI["CaseNum"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varCaseNum});
//inputsI["Comments"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varComments});
inputsI["Comments"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: xlocation + " " + ylocation});
inputsI["SHAPE@X"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingDouble", {value: xlocation});
inputsI["SHAPE@Y"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingDouble", {value: ylocation});
inputsI["classification"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varClassification});
//var inputresults = inputs;
gpParametersInsert.inputs = inputsI;
// Create the job that handles the communication between the application and the geoprocessing task
insertCursorJob = insertCursorTask.createJob(gpParametersInsert);
insertCursorJob.start();
Execution Type: esriExecutionTypeAsynchronous
Parameters:
Parameter: Item
Data Type: GPString
Display Name Item
Description: Item
Direction: esriGPParameterDirectionInput
Default Value:
Parameter Type: esriGPParameterTypeOptional
Category:
Parameter: PublicPrivate
Data Type: GPString
Display Name PublicPrivate
Description: PublicPrivate
Direction: esriGPParameterDirectionInput
Default Value:
Parameter Type: esriGPParameterTypeOptional
Category:
Parameter: CaseNum
Data Type: GPString
Display Name CaseNum
Description: PublicPrivate
Direction: esriGPParameterDirectionInput
Default Value:
Parameter Type: esriGPParameterTypeOptional
Category:
Parameter: Comments
Data Type: GPString
Display Name Comments
Description: Comments
Direction: esriGPParameterDirectionInput
Default Value:
Parameter Type: esriGPParameterTypeOptional
Category:
Parameter: SHAPE_X
Data Type: GPDouble
Display Name SHAPE@X
Description: SHAPE@X
Direction: esriGPParameterDirectionInput
Default Value:
Parameter Type: esriGPParameterTypeOptional
Category:
Parameter: SHAPE_Y
Data Type: GPDouble
Display Name SHAPE@Y
Description: SHAPE@Y
Direction: esriGPParameterDirectionInput
Default Value:
Parameter Type: esriGPParameterTypeOptional
Category:
Parameter: classification
Data Type: GPString
Display Name classification
Description: classification
Direction: esriGPParameterDirectionInput
Default Value:
Parameter Type: esriGPParameterTypeOptional
Category:
If the point shows that it is off the coast of Africa, that means it is 0,0 (meaning conversion issue from loosely-type javascript variable to GeoProcessingDouble Runtime object) or spatial reference related issues.
I would recommend creating the Runtime Point object first out of the lat/long you have, with Spatial Reference value included. Then pass the x and y value from the Point object properties, and I think type to use is GeoprocessingDouble.
Trying really hard with this....this is all new to me...QML etc....
So I don't want the user to click the screen I just want to get the center of the screen and use those coordinates...
So I set this up on the map view to push XY coordinates to a global variable "currentLocation" every time the map moves.
My thought was that I could take those variables and push them to the GP Tool and the python script to create a new point via python insert cursor.
MapView{
id: mapView
onVisibleAreaChanged: {
var center = visibleArea.extent.center;
// Display center point
var test = visibleArea.spatialReference.wkText;
console.log(test);
var test4 = visibleArea.extent.center.x;
console.log(test4);
var test5 = visibleArea.extent.center.y;
console.log(test5);
var centercoord = CoordinateFormatter.toLatitudeLongitude(mapView.currentViewpointCenter.center, Enums.LatitudeLongitudeFormatDecimalDegrees, 6);
var ylocation = centercoord.substring(0,9);
var xlocation = centercoord.substring(12,21);
currentLocationX = xlocation
currentLocationY = ylocation
currentLocation = "x: -" + currentLocationX + " y: " + currentLocationY
}
I call this function from a button right now....
I am trying to create a point object as you suggested from the "centercoord" variable that I can return in WGS84 BUT there is no - on the X value
centercoord variable set to console.log gives me this: qml: Decimal Degrees : 38.116531N 077.625811W
I am then trying to pass those values to the GP Tool but VERY VERY Confused...
I don think I should be trying to pass a GeoprocessingFeatures if I am only trying to capture those values in the GP Tool as parameters??????? I think I need them as string values??????
ANY help would be most appreciated.
GeoprocessingTask {
id: insertCursorTask
url: "https://vafwisdev.dgif.virginia.gov/arcgis/rest/services/DGIF_Tools/LECAInsertCursor/GPServer/InsertCursor/submitJob"
function insertFunction() {
var varItem = "shooter";
var varPublicPrivate = "public";
var varCaseNum = "77";
var varComments = "comments jump jump up and get down";
var varClassification = "Boating";
var centercoord = CoordinateFormatter.toLatitudeLongitude(mapView.currentViewpointCenter.center, Enums.LatitudeLongitudeFormatDecimalDegrees, 6);
console.log("Decimal Degrees : " + centercoord);
// Create a new feature collection using WGS84 as the OUTPUT
var inputFeatures = ArcGISRuntimeEnvironment.createObject("FeatureCollectionTable", {
geometryType: Enums.GeometryTypePoint,
spatialReference: SpatialReference.createWGS84()
});
// Create a new feature from the feature collection table. It will not have a coordinate location (x,y) yet
var inputFeature = inputFeatures.createFeature();
// Assign a physical location to the new point feature based upon where the user clicked on the map view
//inputFeature.geometry = mapView.currentViewpointCenter.center;
inputFeature.geometry = centercoord;
var inputsI = {};
inputsI["Item"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varItem});
inputsI["PublicPrivate"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varPublicPrivate});
inputsI["CaseNum"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varCaseNum});
//inputsI["Comments"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varComments});
inputsI["Comments"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: xlocation + " " + ylocation});
inputsI["SHAPE@XY"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingFeatures", { features: inputFeatures });
inputsI["classification"] = ArcGISRuntimeEnvironment.createObject("GeoprocessingString", {value: varClassification});
gpParametersInsert.inputs = inputsI;
// Create the job that handles the communication between the application and the geoprocessing task
insertCursorJob = insertCursorTask.createJob(gpParametersInsert);
//insertCursorJob.start();
Jay,
I think there's another approach that we have not explored, and it could be a simpler solution.
How about calling the GP Service directly using NetworkRequest? Not using the GeoProcessingTask Object from ArcGIS Runtime.
Ideally, the GP service is just like a restful web service endpoint, with parameters.
Below are documentation links on NetworkRequest,
- Guide - Network requests—AppStudio for ArcGIS | ArcGIS
- API Reference - NetworkRequest QML Type | ArcGIS
Thank you,
Erwin
If I proceed down this path is there a way to receive a call back stating that the update was successful or if it failed?
Yes, we can receive the response, as outlined in the guide doc, Network requests—AppStudio for ArcGIS | ArcGIS
still think I need to focus on your comment
If the point shows that it is off the coast of Africa, that means it is 0,0 (meaning conversion issue from loosely-type javascript variable to GeoProcessingDouble Runtime object) or spatial reference related issues.
if I set the XY parameter as text or double it works fine from the rest endpoint submit.
If I do this from App Studio it does not work...how can the variable be destroyed on submit from appstudio???
If does not work when I send from the AppStudio app....although I am in the desktop mode....I have noticed that somethings don't work properly from the desktop mode...I am going to test from an actual installed application on a device....
If I am sending a string from the AppStudio app what can be the conversion failure???
Im not getting this....it should work the way I have it....uggggggg
Using NetworkRequests object should mimic the REST endpoint submit.
Im not seeing how to pass variables to the GP tool and then how to extract them to variables in the python script?
Would it be as easy as something like this?
Just wondering how I would grab this JSON on the GP side as I am specifying Parameters in the properties of the GP Tool.....
NetworkRequest {
id: uploadRequest
url: "http://MY GP SERVICE URL"
method: "POST"
headers.referrer: "https://www.arcgis.com/home/index.html"
headers.userAgent: "Mozilla/5.0"
onReadyStateChanged: {
if ( readyState === NetworkRequest.DONE ) {
result.text = responseText
}
}
onError: result.text = errorText + ", " + errorCode
}
ColumnLayout {
Button {
id:upload
text: "Upload Request"
Layout.margins: 2
Layout.fillWidth: true
onClicked: {
uploadRequest.send({adds:"[{\"attributes\":{\"description\":\"Networkrequest Sample\",\"Comments\":\"some comment\",\"timestamp\":null},\"geometry\":{\"paths\":[[-11542803.322978519,3129176.1574580222]],\"spatialReference\":{\"latestWkid\":3857,\"wkid\":102100}}}]", f:"json"});
}
}