Weighted Overlay Custom Tool (Python) Inclusion in Web AppBuilder Application Issue

696
2
03-23-2022 06:59 PM
Labels (1)
by Anonymous User
Not applicable

I am attempting to develop a custom Weighted Overlay tool (via Python script) to be included in a Web AppBuilder application. This tool is based on the utility of the Weighted Overlay (Spatial Analyst) tool. I would like for the Web App user to input only the layer weight values (0% - 100%) and be presented with the output weighted overlay raster layer. I have hard-coded the four input raster data layers, which is the goal. I have developed a script that works correctly within ArcMap, and I have published a geoprocessing service using this script. I have successfully added this geoprocessing service to my Web AppBuilder application (hosted through AGOL). However, the tool results in a general "Submitted. Executing... Failed." message after being run. I imagine this is an issue with my script.

Here is the script that I am using to publish this geoprocessing service:

# FireIncidentRiskAnalysis.py
# Usage: FireIncidentRiskAnalysis <Fire_Incident_Risk_Analysis>
# Description:
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *

arcpy.env.overwriteOutput = True
arcpy.env.workspace = arcpy.env.scratchGDB

StationProximity = arcpy.GetParameter(0)
if StationProximity == '#' or not StationProximity:
StationProximity = 25

Landuse = arcpy.GetParameter(1)
if Landuse == '#' or not Landuse:
Landuse = 25

HazardousSiteProximity = arcpy.GetParameter(2)
if HazardousSiteProximity == '#' or not HazardousSiteProximity:
HazardousSiteProximity = 25

HydrantProximity = arcpy.GetParameter(3)
if HydrantProximity == '#' or not HydrantProximity:
HydrantProximity = 25

# Script arguments
#Fire_Incident_Risk_Analysis = arcpy.GetParameterAsText(0)
#if Fire_Incident_Risk_Analysis == '#' or not Fire_Incident_Risk_Analysis:
Fire_Incident_Risk_Analysis = "C:\\CapstoneProject\\Project_Toolbox\\FireIncidentRiskAssessment\\FireIncidentRiskAssessment.gdb\\AnalysisOutput" # provide a default value if unspecified


# Local variables:
Proximity_to_Fire_Station_Raster = "ParcelsNearStationRaster"
Landuse_Raster = "LanduseReclass"
Hazardous_Material_Site_Buffer_Raster = "HazardousMaterialSites"
Fire_Hydrant_Buffer_Raster = "FireHydrantDistanceBuffers"

remapstation = RemapValue([[1,4],[2,3],[3,2],[4,1],["NODATA","NODATA"]])
remaplanduse = RemapValue([[1,4],[2,3],[3,2],[4,1],["NODATA","NODATA"]])
remaphazardous = RemapValue([[1,4],[2,3],[3,2],[4,1],["NODATA","NODATA"]])
remaphydrant = RemapValue([[1,5],[2,4],[3,3],[4,1],["NODATA","NODATA"]])

myWOTable = WOTable([[Proximity_to_Fire_Station_Raster, StationProximity, "VALUE", remapstation],
[Landuse_Raster, Landuse, "VALUE", remaplanduse],
[Hazardous_Material_Site_Buffer_Raster, HazardousSiteProximity, "VALUE", remaphazardous],
[Fire_Hydrant_Buffer_Raster, HydrantProximity, "VALUE", remaphydrant]], [1, 5, 1])

 

# Execute WeightedOverlay
WeightedOverlayOutput = WeightedOverlay(myWOTable)

arcpy.CopyRaster_management(WeightedOverlayOutput, Fire_Incident_Risk_Analysis)
#WeightedOverlayOutput.save(Fire_Incident_Risk_Analysis)

 

Any assistance would be greatly appreciated.

0 Kudos
2 Replies
by Anonymous User
Not applicable

I am attempting to develop a custom Weighted Overlay tool (via Python script) to be included in a Web AppBuilder application. This tool is based on the utility of the Weighted Overlay (Spatial Analyst) tool. I would like for the Web App user to input only the layer weight values (0% - 100%) and be presented with the output weighted overlay raster layer. I have hard-coded the four input raster data layers, which is the goal. I have developed a script that works correctly within ArcMap, and I have published a geoprocessing service using this script. I have successfully added this geoprocessing service to my Web AppBuilder application (hosted through AGOL). However, the tool results in a general "Submitted. Executing... Failed." message after being run. I imagine this is an issue with my script.

Here is the script that I am using to publish this geoprocessing service:

# FireIncidentRiskAnalysis.py
# Usage: FireIncidentRiskAnalysis <Fire_Incident_Risk_Analysis>
# Description:
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *

arcpy.env.overwriteOutput = True
arcpy.env.workspace = arcpy.env.scratchGDB

StationProximity = arcpy.GetParameter(0)
if StationProximity == '#' or not StationProximity:
StationProximity = 25

Landuse = arcpy.GetParameter(1)
if Landuse == '#' or not Landuse:
Landuse = 25

HazardousSiteProximity = arcpy.GetParameter(2)
if HazardousSiteProximity == '#' or not HazardousSiteProximity:
HazardousSiteProximity = 25

HydrantProximity = arcpy.GetParameter(3)
if HydrantProximity == '#' or not HydrantProximity:
HydrantProximity = 25

# Script arguments
#Fire_Incident_Risk_Analysis = arcpy.GetParameterAsText(0)
#if Fire_Incident_Risk_Analysis == '#' or not Fire_Incident_Risk_Analysis:
Fire_Incident_Risk_Analysis = "C:\\CapstoneProject\\Project_Toolbox\\FireIncidentRiskAssessment\\FireIncidentRiskAssessment.gdb\\AnalysisOutput" # provide a default value if unspecified


# Local variables:
Proximity_to_Fire_Station_Raster = "ParcelsNearStationRaster"
Landuse_Raster = "LanduseReclass"
Hazardous_Material_Site_Buffer_Raster = "HazardousMaterialSites"
Fire_Hydrant_Buffer_Raster = "FireHydrantDistanceBuffers"

remapstation = RemapValue([[1,4],[2,3],[3,2],[4,1],["NODATA","NODATA"]])
remaplanduse = RemapValue([[1,4],[2,3],[3,2],[4,1],["NODATA","NODATA"]])
remaphazardous = RemapValue([[1,4],[2,3],[3,2],[4,1],["NODATA","NODATA"]])
remaphydrant = RemapValue([[1,5],[2,4],[3,3],[4,1],["NODATA","NODATA"]])

myWOTable = WOTable([[Proximity_to_Fire_Station_Raster, StationProximity, "VALUE", remapstation],
[Landuse_Raster, Landuse, "VALUE", remaplanduse],
[Hazardous_Material_Site_Buffer_Raster, HazardousSiteProximity, "VALUE", remaphazardous],
[Fire_Hydrant_Buffer_Raster, HydrantProximity, "VALUE", remaphydrant]], [1, 5, 1])

 

# Execute WeightedOverlay
WeightedOverlayOutput = WeightedOverlay(myWOTable)

arcpy.CopyRaster_management(WeightedOverlayOutput, Fire_Incident_Risk_Analysis)
#WeightedOverlayOutput.save(Fire_Incident_Risk_Analysis)

 

Any assistance would be greatly appreciated.

0 Kudos
DanPatterson
MVP Esteemed Contributor

Code formatting ... the Community Version - Esri Community 

to make it easier to read


... sort of retired...