Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

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 import ZonalStatisticsAsTable
from time import gmtime, strftime

# Check out ArcGIS Spatial Analyst extension license
# 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" 
    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?

The Toolbox

Script Tool Parameters

Script Tool Parameters

Model Tool Parameters

Model Tool Parameters


share|improve this question
Comments? Questions? Anything? – Baskinomics Jan 11 '12 at 20:38
Do you need the output as a record set? I'm wondering if it might help to add an extract or feature copy on the end of your model to get an output of gdb or shape file? – Steve Jan 12 '12 at 0:40
Yes the intended output is a RecordSet, as it will be exposed as an output parameter of a geoprocessing task on ArcGIS server which can be consumed via the REST API. I get the output on the server itself, i.e. I can run the GP task and it puts the output recordset of the script in a unique job folder. The issue is that my script tool/model as it is currently constructed does not allow me to access the output via the REST API. See the link I posed to the REST endpoint, and there are only two input parameters but not an output parameter. When I run it, I cannot consume the result. – Baskinomics Jan 12 '12 at 2:10
Have you tried adding a return to your py script to return either the RecordSet or the path to the RecordSet? – Steve Jan 12 '12 at 12:06
What features did you enable when you published? I'm not sure, but might Data Access be required in order to access the RecordSet? – Steve Jan 12 '12 at 13:33
up vote 8 down vote accepted

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
    arcpy.SetParameter(0, arcpy.RecordSet(foo))
    ##Note that this also works
    #r = arcpy.CreateObject("RecordSet")
    #arcpy.SetParameter(0, r)

Your url to the resource is going to follow this pattern:

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

share|improve this answer
This accomplished the first part of getting the output parameter; I'm running into some server issues so I'll let you know if it works or not, award you the bounty. Thanks! – Baskinomics Jan 12 '12 at 22:13
Yeah, I've been down this road before so if you get stuck feel free to comment further. – valveLondon Jan 12 '12 at 22:30
Where do we set the [nameOfOutputParameter]? I have now=arcpy.SetParameter(0,r). Thanks. – Justin Mar 9 '12 at 18:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.