Geoprocessing Service: jpeg map returned as html url

Discussion created by Playa on Oct 19, 2016

I need some advice and direction from the ESRI community. We have made use of the CMV Viewer for a project that we are involved in:



Each point refers to the landowners letter and map indicating the irrigated and non irrigated fields on a land parcel (farm portion) 


The output map is currently generated from a python script, accessing the data directly from the SDE SQL Enterprise Geodatabase based on an mxd that I setup and saved under the server.


Created on 12 Sep 2016

Generated a JPEG

for each Land Parcel

indicating the irrigation


@author: PeterW

# import site-packages and modules
import math
import arcpy

# set environment settings
arcpy.env.overwriteOutput = True

# set arguments
input_mxd = r"D:\Python2\VandV\mxd\VandV_Letter_Maps_160928.mxd"
output_folder = r"Z:\Peter.Wilson\VandV_Maps"

# function to generate jpeg for each cadastre indicating the irrigation status
def vandv_ddp_jpegs(input_mxd, output_folder):
    mxd = arcpy.mapping.MapDocument(input_mxd)
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    # cadastre and landuse layers
    lyrs = arcpy.mapping.ListLayers(mxd, "", df)
    elm_title = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "sgkey")[0]
    sgid_set = set()
    with arcpy.da.SearchCursor(lyrs[1], ["SGID"]) as scur1:  # @UndefinedVariable
        for row in scur1:
            # filter out landuse feature classes that don't have SGIDs
            if row[0]!= None:
    sgids = list(sgid_set)
    sqlquery = 'SGID IN (' + ','.join(map(str, sgids)) + ')'
    arcpy.MakeFeatureLayer_management(lyrs[0], "Cadastre_lyr", sqlquery)
    with arcpy.da.SearchCursor("Cadastre_lyr", ["SGID", "ID", "SHAPE@"]) as scur1:  # @UndefinedVariable
        for row in scur1:
            elm_title.text = row[1]
            SGID = row[0]
            def_query1 = "{0} = {1}".format("SGID", SGID)
            lyrs[0].definitionQuery = def_query1
            lyrs[1].definitionQuery = def_query1
            df.extent = row[2].extent
            df.scale = int(math.ceil(df.scale/5000)*5000)
            output_jpeg = "{0}\\{1}.jpg".format(output_folder, SGID)
            arcpy.AddMessage("Exporting SGID {0} jpeg".format(SGID))
            arcpy.mapping.ExportToJPEG(mxd, output_jpeg, resolution=150)
            lyrs[0].definitionQuery = ""
            lyrs[1].definitionQuery = ""

vandv_ddp_jpegs(input_mxd, output_folder)


The  output jpeg looks like the following:



What I need to do is convert my python script that it generates the output jpeg (map) using the rest services within the viewer and not accessing the data from the SDE SQL Geodatabase. The Geoprocessing service needs to use as input argument the land parcel ID and the output jpeg needs to be return as an HTML Url that can be consumed by the hyperlink "More Info" that triggers an SSRS (SQL Server Reporting Services) that generates the letter and needs to embed the jpeg thats returned as a Url.


The print Geoprocessing  Service almost does what I wan't , but I still need to handle the map template, and does the jpeg need to be saved to hard disk or could it be saved into memory and returned as an Url that the SSRS can use to embed into the letter.


I don't have any experience in JavaScript, so what do I need to learn to achieve the following. Any suggestions and sample Geoprocessing Services that achieve an similar result to guide me will be greatly be appreciated.