Geoprocessing service Resultats do not show

11-14-2017 06:24 AM
New Contributor


I created a geoprocessing service that I published it in our ArcGIS server. After,  I created a web map application with Web AppBuilder and using a geoprocessing widget I was able to call my GPS and execute it without any error.

The problem is that I can not see the results. I tried arcpy.AddMessage() and also acpy.MakeFeatureLayer_management() but no results. Regarding Addmessage, instead of calling mxd = arcpy.mapping.MapDocument, I just create some variable, did my calculation and add the results to and AddMessage()

Here is my code. At the bottom, my addMessage code.

import arcpy
import os
from arcpy import env

env.outputZFlag = "DISABLED" 
env.outputMFlag = "DISABLED"

mxdfile = "\\\\vsonkengis01\\Oceans\\Projects\\2017\\GPS\\AreaMCT\\Mxd\\AreaMCT.mxd"
mxd = arcpy.mapping.MapDocument (mxdfile)
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
# Set all the parameters
fClass1 = arcpy.GetParameterAsText(0)
fClass2 = arcpy.GetParameterAsText(1)
fClass3 = arcpy.GetParameterAsText(2)
fClass4 = arcpy.GetParameterAsText(3)
Union1 = "\\\\vsonkengis01\\Oceans\\Projects\\2017\\GPS\\AreaMCT\\Scratch\\Scratch.gdb\\Union1"
Union = "\\\\vsonkengis01\\Oceans\\Projects\\2017\\GPS\\AreaMCT\\Scratch\\Scratch.gdb\\Union"
Union_Diss = "\\\\vsonkengis01\\Oceans\\Projects\\2017\\GPS\\AreaMCT\\Scratch\\Scratch.gdb\\Union_Diss"
Union_Diss_inter = "\\\\vsonkengis01\\Oceans\\Projects\\2017\\GPS\\AreaMCT\\Scratch\\Scratch.gdb\\Union_Diss_inter"
Union_Diss_inters = "\\\\vsonkengis01\\Oceans\\Projects\\2017\\GPS\\AreaMCT\\Scratch\\Scratch.gdb\\Union_Diss_inters"
# Union
arcpy.Union_analysis ([fClass1, fClass2], Union1, "ONLY_FID")
arcpy.Union_analysis ([Union1, fClass3],Union, "ONLY_FID")
# Generalization
arcpy.Dissolve_management (Union, Union_Diss, "Diss","","MULTI_PART")
# Intersect
arcpy.Intersect_analysis([Union_Diss, fClass4], Union_Diss_inter,"ALL")
arcpy.Dissolve_management (Union_Diss_inter, Union_Diss_inters, "Name","","MULTI_PART")
arcpy.AddField_management(Union_Diss_inters, "TArea", "DOUBLE")
arcpy.AddField_management(Union_Diss_inters, "AreaEEZ", "DOUBLE")
arcpy.AddField_management(Union_Diss_inters, "PTArea", "DOUBLE")
arcpy.CalculateField_management(Union_Diss_inters, "AreaEEZ", exp, "PYTHON_9.3")
TArea = 0
urows = arcpy.UpdateCursor(Union_Diss_inters)
for row in urows:
    TArea += row.getValue("AreaEEZ")
del urows
urows = arcpy.UpdateCursor(Union_Diss_inters)
for row in urows:
    row.setValue("TArea", TArea)
    if row.getValue("Name")=="Atlantic and Arctic":
       row.setValue("PTArea", (row.getValue("AreaEEZ")/TArea)*100)
    if row.getValue("Name")=="Pacific":
       row.setValue("PTArea", (row.getValue("AreaEEZ")/TArea)*100) 
del urows
if arcpy.Exists("AreaMCT"):
arcpy.MakeFeatureLayer_management(Union_Diss_inters, "AreaMCT")
layer = arcpy.mapping.Layer("AreaMCT")
layer.visible = True
arcpy.mapping.AddLayer(df, layer, "TOP")‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


arcpy.AddMessage("Total Atrea Protected = " + str(TArea) + " km2")
arcpy.AddMessage("Area protected in Pacific EEZ = " + str(TAreaPacific) + " km2" )
arcpy.AddMessage("Percentage Area protected in Pacific EEZ = " + str(PTAreaPacific*100) + " %" )
arcpy.AddMessage("Area protected in Atlantic-Arctic EEZ = " + str(TAreaATArcti) + " km2" )
arcpy.AddMessage("Percentage Area protected in Atlantic-Arctic EEZ = " + str(PTAreaATArcti*100) + " %" )‍‍‍‍‍

An other question:

The GPS is related to a set of data. When I published the GPS, used a registered path for the data. So, the data is not copied to the server.

How can I load the data related to this GPS? do I have to publish a WMS the the same registed path and load it into t Web Map?

Thanks a lot

0 Kudos
2 Replies
Esri Esteemed Contributor

There are a number of things that you need to keep in mind:

  • When you publish a Python script tool as a GP service, ArcGIS Server will probably change parts of the script. I don't think the script you posted is the one that is present in the service directory of your GP service, right?
  • You are using the GP service in a widget in the WAB, but the script adds a layer to a mxd which is not saved by the script. You will never see a result this way. In case you want a result in the WAB, you should define another parameter for the script which contains the result. The widget will recognize that output and offer you to configure how the result should be visualized in your WAB.
  •  Messages will not be shown by the widget in WAB. You can however collect the messages into a string variable and define that as a output parameter of the script which will be shown in the WAB
  • Any changes to the parameters of a GP service, will require republishing of the service
  • I notice you are using hard coded paths to intermediate results. What do you think will happen when two users run the process at the same time? You should let the server manage these files for you.
0 Kudos
New Contributor

Thanks for your quick answer

I will follow you advises for sure

for the last point, I used before a relative path to the scratch workspace lake %scartchworkspace%/union for example. as part of the workflow, this union file has to be used in an other step. the problem that when the intermediate files like %scartchworkspace%/union were called in another step, I got a message like: There is no file named.. in the working space

How can I use intermediate files in other step?


0 Kudos