""" Spatial Data Modeller for ESRI* ArcGIS 9.2 Copyright 2007 Gary L Raines, Reno, NV, USA: production and certification Don L Sawatzky, Spokane, WA, USA: Python software development """ """# --------------------------------------------------------------------------- # MSLarge.py # Created on: Sat May 26 2007 07:12:03 AM # (generated by ArcGIS/ModelBuilder) # Usage: MSLarge # Description: # The MS Large function is u(x) = 1 - (b * s) / (x - (a * m) + (b * s)). # Where m = the mean, s = the standard deviation, # a = a multiplier of the mean, and b = a multiplier of the standard deviation. #The user is asked to provide the multipliers, a and b. # --------------------------------------------------------------------------- """ # Import system modules import sys, string, os, arcgisscripting, trace # Create the Geoprocessor object gp = arcgisscripting.create() # Check out any necessary licenses gp.CheckOutExtension("spatial") # Load required toolboxes... #gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx") try: # Script arguments... Evidence = gp.GetParameterAsText(0) FM_MS_Large = gp.GetParameterAsText(3) if FM_MS_Large == "": FM_MS_Large = (Evidence + "_MSLrg")[:13] #gp.AddMessage("FM_MS_Large=%s"%(FM_MS_Large)) A = gp.GetParameter(1) B = gp.GetParameter(2) #gp.AddMessage("A=%s, B=%s"%(A,B)) # Local variables... BandCol_Stats = os.path.join(gp.ScratchWorkspace, "bandcol_stats.txt") # Process: Band Collection Statistics... gp.BandCollectionStats_sa(Evidence, BandCol_Stats, "BRIEF") fin = open(BandCol_Stats,'r') for i in range(6): fin.readline() tokens = fin.readline().split() fin.close() #gp.AddMessage('%s'%tokens) Mean = float(tokens[3]) StDev = float(tokens[4]) #gp.AddMessage("Mean=%s, StDev=%s"%(Mean,StDev)) # Process: Single Output Map Algebra... # u(x) = 1 - (b * s) / (x - (a * m) + (b * s)) # "con([Evidence] > A * Mean, 1 - ((B * StDev) / ([Evidence] - (A * Mean) + (B * StDev))),0)" Expression = "con([%s] > %s * %s, 1 - ((%s * %s) / ([%s] - (%s * %s) + (%s * %s))),0)" \ %(Evidence,A,Mean,B,StDev,Evidence,A,Mean,B,StDev) #gp.AddMessage( Expression) gp.SingleOutputMapAlgebra_sa(Expression, FM_MS_Large) gp.SetParameterAsText(3,FM_MS_Large) except: gp.AddError("Error in Execution" + gp.GetMessages()) gp.AddMessage("Exit MS Large.")