atwesigye_ICRC

Publishing a Python script as a geoprocessing service. Needs help.

Discussion created by atwesigye_ICRC on May 2, 2019
Latest reply on Jul 15, 2019 by atwesigye_ICRC

Hi, I am tryng to publish a relatively simple python script as a geoprocessing service. The tool works well when executed locally.  It also publishes correctly, but I get the following error when the geoprocessing service executes:

 

 

I would like someone to help identify what errors I may have my code, which is attached to this message.

Also, here are the parameters of my script-

 

 

Thanks.

 

# -*- coding: utf-8 -*-

#-------------------------------------------------------------------------------
import arcpy
# input feature for querying the statistics(feature set)
userInPutFc = arcpy.GetParameterAsText(0)
if userInPutFc == '#' or not userInPutFc:
    userInPutFc = "\\\\xxx\\Server Objects\\ArcGISGeoprocessing\\Script_ZonalStatistic_Solar\\Data\\Temp\\sotemp.lyr" # provide a default value if unspecified
# final = arcpy.GetParameterAsText(1)
final = "\\\\xxx\\Server Objects\\ArcGISGeoprocessing\\Script_ZonalStatistic_Solar\\Data\\Temp.gdb\\ZonalSolarOutput"  # provide a default value if unspecified

# work space
arcpy.env.workspace = "\\\\xxx\\Server Objects\\Data\\Raster\\Solar"
arcpy.env.overwriteOutput=True

# Input rasters array
input_data_array = []
# Exclude data from the analysis
exluded_data = ["PVGIS4_SARAH_YearlyAverageGlobalIrradianceHorizontalSurface", "PVGIS4_SARAH_YearlyAverageGlobalIrradianceOptimallyInclinedSurface", "PVGIS4_SARAH_YearlyAverageGlobalIrradianceOnTwoAxisSunTrackingSurface", "PVGIS4_SARAH_YearlyOptimalInclinationAngleForAnEquatorFacingPlane", "SolarGIS_OPTA_OptimumTiltToMaximizeYearlyYield"]
# List of geodatabases in the current workspace
workspaceGDBs = arcpy.ListWorkspaces("*GIS*", "FileGDB")
arcpy.AddMessage(workspaceGDBs)
# extract all the rasters into the input_data_array
for database in workspaceGDBs:
    arcpy.env.workspace = database
    databaseName = (database.split("\\")[-1]).split(".")[-2]
    if databaseName == "PVGIS":
        for fd in arcpy.ListDatasets("*_Yearly*","Raster"):
            if fd not in exluded_data:
                input_data_array.append(database + "\\" + fd)
    if databaseName == "SolarGIS":
        for fd in arcpy.ListDatasets("*","Raster"):
            if fd not in exluded_data:
                input_data_array.append(database + "\\" + fd)
arcpy.AddMessage("Finished obtaining data from the raster sources")

arcpy.env.overwriteOutput=True

# Create a new environment

out_c = "in_memory" + "\\" + "output_copy"
arcpy.CopyFeatures_management(userInPutFc, out_c)

arcpy.CalculateField_management(out_c, "Feature_no", "0", "PYTHON_9.3", "")
# Recalculate extent based on the feature
arcpy.RecalculateFeatureClassExtent_management(out_c)
# Feature extents
vectorExtent = arcpy.Describe(userInPutFc).extent
vectorExtentXMin = vectorExtent.XMin
vectorExtentYMin = vectorExtent.YMin
vectorExtentXMax = vectorExtent.XMax
vectorExtentYMin = vectorExtent.YMax

# Checkout the extension for using in statistics
arcpy.CheckOutExtension("Spatial")

arcpy.AddMessage("Started processing statistics")

table = []
count = 0
OI = arcpy.Describe(out_c)
field = OI.fields
zone_field = "Feature_no"

arcpy.AddMessage("The zone field is: " + zone_field)

for raster in input_data_array:
    rasterLayerName = arcpy.Describe(raster).name
    arcpy.AddMessage("Processing statistics with: " + rasterLayerName)
    # Raster extents
    rasterExtent = arcpy.Describe(raster).extent
    rasterExtentXMin = rasterExtent.XMin
    rasterExtentYMin = rasterExtent.YMin
    rasterExtentXMax = rasterExtent.XMax
    rasterExtentYMax = rasterExtent.YMax
    # Compare vector and raster extents
    DXMin = rasterExtentXMin - vectorExtentXMin
    DYMin = rasterExtentYMin - vectorExtentYMin
    DXMax = rasterExtentXMax - vectorExtentXMax
    DYMax = rasterExtentYMax - vectorExtentYMin

    # Check if the features share extents
    if DXMin < 0 and DYMin < 0 and DXMax > 0 and DYMax > 0:
        out_t = "in_memory" + "\\" + "output_table" + str(count)
        arcpy.sa.ZonalStatisticsAsTable(out_c, zone_field, raster, out_t, "DATA", "SUM")
        arcpy.AddField_management(out_t, "SourceLayer", "TEXT")
        arcpy.CalculateField_management(out_t, "SourceLayer", "'" + rasterLayerName + "'", "PYTHON_9.3", "")
        table.append(out_t)
        count = count + 1

# final = "\\\\xxx\\Server Objects\\ArcGISGeoprocessing\\Script_ZonalStatistic_Solar\\Data\\Temp.gdb\\ZonalOutput"
arcpy.Merge_management(table, final)

arcpy.AddMessage("Merged the output table")

fieldList = arcpy.ListFields(final)
for field_of_interest in fieldList:
    if field_of_interest.name == "SUM":
        arcpy.AlterField_management(final, field_of_interest.name, 'SUM_kWh_kWp', 'SUM_kWh_kWp')
    if field_of_interest.name == "AREA":
        arcpy.AlterField_management(final, field_of_interest.name, 'AREA_SquareMeters', 'AREA_SquareMeters')
arcpy.AddMessage("Updated the table fields")

arcpy.SetParameterAsText(1, final)

arcpy.AddMessage(final)

Outcomes