I am publishing an ArcGIS geoprocessing service using a Python script tool and can't seem to figure out the correct output path to use. I would like to share the results as a map service, which means that, according to this documentation, I should not use the "in_memory/output_file" scheme.
So, my script writes to a permanent location on my server:
output_path = r"\\server\path\to\data\geodatabase.gdb"
output_layer = os.path.join(output_path, "Result")
arcpy.SetParameterAsText(1, output_layer)
But there are some issues that seem to remain.
-
Although the tool runs successfully in ArcMap, it fails after its published on the server with an error that says the output layer already exists.
-
Assuming I set the geoprocessing environments to overwrite the output, is this the behavior I want? What if there are multiple instances of the geoprocessing tool running… will they not conflict with each other when trying to read/write?
If I understand correctly, a new folder is created for each job, something like:
c:\arcgisserver\directories\arcgisjobs\%service%_gpserver\%jobid%\
I just can't figure out how I can define my output file to be placed there so that it can get pushed up in a temporary map service result.
Best Answer
Use the
arcpy.env.scratchGDB
instead - this will create thoseC:\arcgisserver\directories\arcgisjobs\scriptgp_gpserver\j002461f550fc4658a08dac98c7bd6672
gdb for each job. Use theSetParameter
, notSetParameterAsText
.The source script tool:
Notice the Feature Layer object created as the output - this is what you want to pass further, for instance, in web apps (you can test the service in Web App Builder - handy to test the GP tasks). So the script tool in the toolbox will have an output (derived) parameter of
Feature Layer
type.The published script tool (can be found at
C:\arcgisserver\directories\arcgissystem\arcgisinput\Script_good.GPServer\extracted\v101\ags_data
):Now you need to edit the
output_path
to bearcpy.env.scratchGDB
in the published script. No need to restart the service.Replace this row:
output_path = g_ESRI_variable_2
with this row:
output_path = arcpy.env.scratchGDB
When you run the published task in ArcMap, a layer will be added with the symbology you've specified right before the publishing. You will also see the scratch gdb created for each job (with the actual buffer polygons created).