I've created a python script that I've published as a geoprocessing service. The python script takes as input an SGID, a unique id associated with a land parcel, landuse indicating crop fields irrigated and non-irrigated. The map is exported to a jpeg image for each SGID supplied to the python script. I've added arcpy.SetParameter(3, output_jpeg) at line 52 to return the output jpeg to the geoprocessing service.
<SPAN class="string token">'''
Created on 12 Sep 2016
Generate a JPEG
for a land parcel
indicating the irrigation
status based on SGID
@author: PeterW
'''</SPAN>
<SPAN class="comment token"># import site-packages and modules</SPAN>
<SPAN class="keyword token">import</SPAN> math
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token"># set arguments</SPAN>
input_sgid <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
input_mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
output_folder <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># set environment settings</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="comment token"># function to export map document to jpeg based on sgid</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">vandv_ddp_jpegs</SPAN><SPAN class="punctuation token">(</SPAN>input_mxd<SPAN class="punctuation token">,</SPAN> input_sgid<SPAN class="punctuation token">,</SPAN> output_folder<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">""" export map document to jpeg based on sgid """</SPAN>
mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN>input_mxd<SPAN class="punctuation token">)</SPAN>
df <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListDataFrames<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
lyrs <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListLayers<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> df<SPAN class="punctuation token">)</SPAN>
elm_title <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListLayoutElements<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"TEXT_ELEMENT"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"sgkey"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
sqlquery <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{0} = {1}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"SGID"</SPAN><SPAN class="punctuation token">,</SPAN> input_sgid<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>lyrs<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Cadastre_lyr"</SPAN><SPAN class="punctuation token">,</SPAN> sqlquery<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Cadastre_lyr"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"SGID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SHAPE@"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> scur1<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># @UndefinedVariable</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> scur1<SPAN class="punctuation token">:</SPAN>
elm_title<SPAN class="punctuation token">.</SPAN>text <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
SGID <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
def_query1 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{0} = {1}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"SGID"</SPAN><SPAN class="punctuation token">,</SPAN> SGID<SPAN class="punctuation token">)</SPAN>
lyrs<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> def_query1
lyrs<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> def_query1
df<SPAN class="punctuation token">.</SPAN>extent <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>extent
df<SPAN class="punctuation token">.</SPAN>scale <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN>math<SPAN class="punctuation token">.</SPAN>ceil<SPAN class="punctuation token">(</SPAN>df<SPAN class="punctuation token">.</SPAN>scale<SPAN class="operator token">/</SPAN><SPAN class="number token">5000</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">*</SPAN><SPAN class="number token">5000</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>RefreshActiveView<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
output_jpeg <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{0}\\{1}.jpg"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>output_folder<SPAN class="punctuation token">,</SPAN> SGID<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Exporting SGID {0} jpeg"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>SGID<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ExportToJPEG<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> output_jpeg<SPAN class="punctuation token">,</SPAN> resolution<SPAN class="operator token">=</SPAN><SPAN class="number token">150</SPAN><SPAN class="punctuation token">)</SPAN>
lyrs<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>
lyrs<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SetParameter<SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN> output_jpeg<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ExecuteError<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>GetMessages<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
vandv_ddp_jpegs<SPAN class="punctuation token">(</SPAN>input_mxd<SPAN class="punctuation token">,</SPAN> input_sgid<SPAN class="punctuation token">,</SPAN> output_folder<SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Within the ArcToolbox parameter settings, I've set the output parameter Output JPEG as a Raster Dataset Data Type and Parameter Type as Derived and Output.

I then ran the python script locally, in order to publish the result as a geoprocessing service.


I copied the REST URL: http://172.16.1.16:6080/arcgis/rest/services/Geoprocessing_VandV/ExportToJPEG/GPServer into my browser in order to execute it.

The output raster returned is renamed adding "_ags_" prefix, and saved out as TIFF format. and if I rerun the geoprocessing service for the same SGID, it doesn't overwrite the raster but adds a suffix "1".

<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"results"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"paramName"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Output_JPEG"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"dataType"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"GPRasterDataLayer"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"value"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"url"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2F172.16.1.16%3A6080%2Farcgis%2Frest%2Fdirectories%2Farcgisoutput%2FGeoprocessing_VandV%2FExportToJPEG_GPServer%2F_ags_935814.tif" target="_blank">http://172.16.1.16:6080/arcgis/rest/directories/arcgisoutput/Geoprocessing_VandV/ExportToJPEG_GPServer/_ags_935814.tif</A><SPAN>"</SPAN></SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"format"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"tif"</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Is there a way to prevent this from happening. I need the raster to be jpeg's not tiff's and the name cant' be changed it needs to match the SGID. The rasters also need to be overwritten if they exist as the data is constantly being updated so the jpegs need to reflect the updates each time they are rerun as they are being imbeded into a SSRS report that is being sent out to the owners of the land parcels.

I've tried saving the output as a string rather, but unfortunately the path is not returned as a URL but as an absolute path that can't be used by the SSRS report request. Any help will be appreciated.
Python ; Geoprocessing ; ArcGIS for Server ; https://community.esri.com/community/developers/web-developers/arcgis-rest-api