Custom Weighted Overlay Tool (Python) Not Automatically Adding Output to Map Document

1051
1
03-23-2022 07:09 PM
Labels (3)
by Anonymous User
Not applicable

I am attempting to develop a custom Weighted Overlay tool (via Python script). This tool is based on the utility of the Weighted Overlay (Spatial Analyst) tool. I would like for the 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 correctly creates the new layer, but the newly created output raster data layer is not automatically added to the map document. Is there something I can add to my script to accomplish this automatic addition?

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
1 Reply
RhettZufelt
MVP Frequent Contributor

you should be able to use arcpy.mapping to add the layer to the dataframe:

Add Layer

R_

0 Kudos