8

I have a script that needs to be published to ArcGIS Server as a geoprocessing service. This script computes a set of records in table form. I need to set an output parameter so that it returns the table (recordset).

So, to make sure I have a table (not a feature class), I am using arcpy.TableToTable_conversion(), outputting the table to the in_memory workspace. So, I know I have a table. I know that it has records, as I can perform an arcpy.GetCount and get the number of records.

I have the output parameter defined. Here's what it looks like:

arcpy.SetParameter(2, theTable)

No matter what I try this does not work. In my toolbox, the output parameter is set as a RecordSet. I've tried supplying a recordset object, the path to the in-memory feature class, and many other ideas.

How do you properly handle outputting a table to a recordset output using SetParameter for ArcGIS server?

2
  • Sounds like (from ESRI) that I cannot use the in-memory workspace for outputting recordsets. By the time the service goes to retrieve the items set in the SetParameter statement, the in-memory table has been deleted.
    – Kenton W
    Nov 29, 2011 at 19:33
  • 1
    Not sure who told you that, but thats untrue. You can use in_memory output. The only real time you can't use in_memory output is when you want to draw the result with a result map server
    – KHibma
    Nov 30, 2012 at 17:05

2 Answers 2

5

In my experience (and I'm more than happy to be corrected on this) when you build a geoprocessing service the argument you give for the output is not the object itself, but a reference to the object (the file path).

The data type just tells server how to interpret the data depending on how you run the tool (within an app it might automatically display the record-set, from SOAP you might get the record set as a data stream (though I'm not sure) and through REST you'll just get a link).

Basically you need to write your table to this file - ArcGIS server will automatically prepend a folder/jobid path to the front based on your output folder from when you added the model to server. e.g.

  1. Your output folder on the server might be C:/arcgisserver/arcgisoutput
  2. So on the server this folder becomes /arcgisoutput
  3. Then your output for your toolbox might be /arcgisoutput/tabletoolbox
  4. Your value for the output might be %scratchworkspace%/tablename.csv

Note the %scratchworkspace% allows ArcGIS server to sub in the output directories. See Key Concepts for Geoprocessing Services in the ESRI help.

So the server autotmatically creates a job id (UUID), makes a folder for you in output, and prepends this to your output argument. Write your data there and when you get it back from arcgis server you'll get a href link like: http://server_name/arcgisoutput/tabletoolbox/job_id/tablename.csv

You should now be able to access the file however you like (use urllib2.urlopen(path).read() in Python as a quick shortcut).

Hope all this is clear! -H

0

I am assuming that the recordset param has been set to derived in the parameter script.

I am also assuming that you may be publishing the tool either directly with a toolbox or through an mxd project. In my experience I've been more successful with tools published in mxd projects.

Sometimes I have resolved geoprocessing services issues by publishing a ModelBuilder model that was only a wrapper around the python script i.e. inside the model I had only the script and I exposed the script params outside the model.

1
  • I'm using a custom toolbox to publish the script as a service. When you set a parameter to Output, it is automatically changed to Derived.
    – Kenton W
    Nov 28, 2011 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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