7

I have published the following script tool (which is wrapped in a model, i.e. just the script tool and all of its parameters) to ArcGIS Server 10. The GP service succeeds when run, but I cannot determine how to access the final output of the GP service. The result is a RecordSet object, and I can view it in the arcgisjobs/job-id/ directory when viewing it on the server.

However, I cannot figure out how to access the result via the REST API. As you can see, the script tool doesn't have an output parameter. When viewing the GP service via the REST Directory there are only the two inputs. I have tried using SetParameterAsText and a Result object and adding an output parameter to both the ST and the model but without any success. So, the question is how do I modify the script and/or script tool/model properties to designate an output parameter so that it can be accessed via the REST API and subsequently consumed in a web application?

I have read through this related question but it has not helped.

The REST Endpoint: http://atlas.utc.edu/ArcGIS/rest/services/RRI/DE/GPServer/Decision%20Engine

The Python script:

#Import ArcPy site package module
import arcpy
from arcpy import env
from arcpy import Extent
from arcpy import Raster
from arcpy import RecordSet
from arcpy.sa import ZonalStatisticsAsTable
from time import gmtime, strftime

# Check out ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Set Environment Workspace
ws = env.workspace = WORKSPACE PATH

# Set Environment Raster Cell Size
cellSize = env.cellSize = 10
# Set Environment Processing Extent
processingExtent = Extent(602560.330672585, 3827530.65305605, 746490.330672585, 3966810.65305605)

environProcessingExtent = env.extent = processingExtent

# Strings representing rasters in the workspace
rasters = arcpy.GetParameterAsText(0).split(";")
# The dataset that defines the zones 
inZoneData = arcpy.GetParameterAsText(1)

# Determine Zone Dataset
if inZoneData == "Block Group":
    zoneField = "Value"
    zoneData = ws + "\\ToolData\\Data.gdb\\BG_Ras"
elif inZoneData == "Census Tract":
    zoneField = "TRACTCE10"
    zoneData = "\\ToolData\\Data.gdb\\CT_Ras" 
else:
    zoneField = ""

addedRaster = Raster(ws + "\\ToolData\\Data.gdb\\constantRaster")

# Process each raster string
for raster in rasters:
    addedRaster = addedRaster + Raster(ws + "\\ToolData\\Data.gdb\\" + raster)

# Execute Zonal Statistics
zonalTable = RecordSet(ZonalStatisticsAsTable(zoneData, zoneField, addedRaster, "%SCRATCHWORKSPACE%\\zontalTable", "DATA", "MAXIMUM")).save("%SCRATCHWORKSPACE%\\rszt")

Some relevant images?

Script Tool Parameters

Model Tool Parameters

Thanks.

8
+100

This worked for me:

  1. Set an output parameter of type RecordSet on the Script Tool and republish.
  2. Push your zonalStats into an in_memory/table. Or, if you need to write them out for whatever reason, copy the rows into an in_memory/table after you're done with the sa.
  3. SetOutputParameter in arcpy to be the Recordset.

    import arcpy
    foo="in_memory/foo"
    arcpy.management.CopyRows("C:/foo.dbf",foo)
    arcpy.SetParameter(0, arcpy.RecordSet(foo))
    
    ##Note that this also works
    #r = arcpy.CreateObject("RecordSet")
    #r.load(foo)
    #arcpy.SetParameter(0, r)
    

Your url to the resource is going to follow this pattern:
http://[nameofserver]/ArcGIS/rest/services/[NameOfGPToolBox]/GPServer/[NameOfGPScript]/jobs/[job-id]/results/[nameOfOutputParameter]

There might also be trouble with your virtual directory mapping to your arcgisserver/arcgisjobs directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["-item\"><a href=\"https://twitter.com/stackoverflow\" class=\"-link js-gps-track\" data-gps-track=\"footer.click({ location: 2, link: 32 })\">Twitter</a></li>\r\n                    <li class=\"-item\"><a href=\"https://linkedin.com/company/stack-overflow\" class=\"-link js-gps-track\" data-gps-track=\"footer.click({ location: 2, link: 33 })\">LinkedIn</a></li>\r\n                </ul>\r\n\r\n                <p class=\"mt-auto mb24\">\r\nsite design / logo &#169; 2019 Stack Exchange Inc; user contributions licensed under <a href=\"https://creativecommons.org/licenses/by-sa/3.0/\" class=\"js-gps-track\" data-gps-track=\"footer.click({ location: 2, link: 34 })\" rel=\"license\">cc by-sa 3.0</a>\r\n                            with <a href=\"https://stackoverflow.blog/2009/06/25/attribution-required/\"  class=\"js-gps-track\" data-gps-track=\"footer.click({ location: 2, link:35 })\" rel=\"license\">attribution required</a>.\r\n                    <span id=\"svnrev\">rev&nbsp;2019.8.20.34647</span>\r\n                </p>\r\n            </div>\r\n        </div>\r\n\r\n            </footer>\r\n            <script>StackExchange.ready(function () { StackExchange.responsiveness.addSwitcher(); })</scri"], "copyright__copyright__copyright": [" url to the resource is going to follow this pattern:\nhttp://[nameofserver]/ArcGIS/rest/services/[NameOfGPToolBox]/GPServer/[NameOfGPScript]/jobs/[job-id]/results/[nameOfOutputParameter]\n\nThere might also be trouble with your virtual directory mapping to your arcgisserver/arcgisjobs directory.\n\nYour Answer\n\nBy clicking \u201cPost Your Answer\u201d, you agree to our terms of service, privacy policy and cookie policy\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}