AnsweredAssumed Answered

Geoprocessing Service: Will the following work?

Question asked by Playa on Nov 3, 2016

I need to publish my python script as a geoprocessing service, which I've never done before. The geoprocessing service needs to take as input the SSRS Url, extract the SGID value, generate a jpeg of the map linked to the SGID (Cadastre ID) and return the output jpeg path as an url that the SSRS can use to access the jpeg to insert it into the report template.

 

We currently have the following CMV viewer (V&V Mapper) that we are using. Our SQL Dev has written a SQL SSRS  report that is triggered when the following link (Tablemap) below is selected.

 

 

TableMap: MoreInfo

 

 

SSRS URL: "http://197.85.5.236:8080/ReportServer/Pages/ReportViewer.aspx?%2fVnV_BO%2fLanduseSummary&SGID=929102&rs:Format=PDF"

 

I've attached my python script below that as an input argument accepts the SSRS Url and extracts the SGID value using Python Urlparse module (i.e. I'm still using Python 2.7.8 and ArcGIS 10.3.1).

 

'''
Created on 12 Sep 2016

Generate a JPEG

for a Land Parcel

indicating the irrigation

status based on SGID

@author: PeterW
'''

# import site-packages and modules
import urlparse
import math
import arcpy

# set environment settings
arcpy.env.overwriteOutput = True

# set arguments
# example of incomming url from ssrs request:
# http://197.85.5.236:8080/ReportServer/Pages/ReportViewer.aspx?%2fVnV_BO%2fLanduseSummary&SGID=930016&rs:Format=PDF
input_sgid = arcpy.GetParameterAsText(0)
# fixed input mcd and output jpeg folder
input_mxd = r"D:\Python2\VandV\mxd\VandV_Letter_Maps_160928.mxd"
output_folder = r"Z:\Peter.Wilson\test"


# function to  extract sgid from sql ssrs url
def extract_sgid(input_sgid):
    sgid = urlparse.parse_qsl(urlparse.urlparse(input_sgid).query)[0][1]
    return sgid

sgid = extract_sgid(input_sgid)


# function to export map document to jpeg based on sgid
def vandv_ddp_jpegs(input_mxd, sgid, output_folder):
    """ export map document to jpeg based on sgid """
    mxd = arcpy.mapping.MapDocument(input_mxd)
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    lyrs = arcpy.mapping.ListLayers(mxd, "", df)
    elm_title = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "sgkey")[0]
    try:
        sqlquery = "{0} = {1}".format("SGID", sgid)
        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)
                arcpy.RefreshActiveView()
                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 = ""
    except arcpy.ExecuteError:
                print(arcpy.GetMessages(2))
   
    return output_jpeg

output_jpeg = vandv_ddp_jpegs(input_mxd, sgid, output_folder)

 

 

Any suggestions to achieve the following will be appreciated as I've never done the following before. Will the following accept the incoming url from the SSRS request and return the url path to the output jpeg.

Outcomes