<s> import os , sys , math , traceback , types <EOL> import arcpy <EOL> from arcpy import da <EOL> from arcpy import env <EOL> from arcpy import sa <EOL> deleteme = [ ] <EOL> debug = True <EOL> GCS_WGS_1984 = arcpy . SpatialReference ( "<STR_LIT>" ) <EOL> ccmFactorList = [ ] <EOL> inputAOI = arcpy . GetParameterAsText ( <NUM_LIT:0> ) <EOL> inputVehicleParameterTable = arcpy . GetParameterAsText ( <NUM_LIT:1> ) <EOL> inputVehicleType = str ( arcpy . GetParameterAsText ( <NUM_LIT:2> ) ) <EOL> inputElevation = arcpy . GetParameterAsText ( <NUM_LIT:3> ) <EOL> inputSlope = arcpy . GetParameterAsText ( <NUM_LIT:4> ) <EOL> outputCCM = arcpy . GetParameterAsText ( <NUM_LIT:5> ) <EOL> inputVegetation = arcpy . GetParameterAsText ( <NUM_LIT:6> ) <EOL> inputVegetationConversionTable = arcpy . GetParameterAsText ( <NUM_LIT:7> ) <EOL> min_max = arcpy . GetParameterAsText ( <NUM_LIT:8> ) <EOL> inputSoils = arcpy . GetParameterAsText ( <NUM_LIT:9> ) <EOL> inputSoilsTable = arcpy . GetParameterAsText ( <NUM_LIT:10> ) <EOL> wet_dry = arcpy . GetParameterAsText ( <NUM_LIT:11> ) <EOL> inputSurfaceRoughness = arcpy . GetParameterAsText ( <NUM_LIT:12> ) <EOL> inputSurfaceRoughnessTable = arcpy . GetParameterAsText ( <NUM_LIT> ) <EOL> commonSpatialReference = arcpy . GetParameter ( <NUM_LIT> ) <EOL> commonSpatialReferenceAsText = arcpy . GetParameterAsText ( <NUM_LIT> ) <EOL> try : <EOL> if debug == True : arcpy . AddMessage ( "<STR_LIT>" + str ( time . strftime ( "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> scratch = env . scratchGDB <EOL> if debug == True : arcpy . AddMessage ( "<STR_LIT>" + str ( scratch ) ) <EOL> env . overwriteOutput = True <EOL> env . resample = "<STR_LIT>" <EOL> env . compression = "<STR_LIT>" <EOL> env . extent = arcpy . Describe ( inputAOI ) . Extent <EOL> env . mask = inputAOI <EOL> calcCellSize = None <EOL> GridSize = <NUM_LIT> <EOL> if commonSpatialReferenceAsText == '<STR_LIT>' : <EOL> commonSpatialReference = arcpy . Describe ( inputAOI ) . spatialReference <EOL> arcpy . AddWarning ( "<STR_LIT>" + str ( commonSpatialReference . name ) ) <EOL> calcCellSize = max ( arcpy . Describe ( inputAOI ) . Extent . width , arcpy . Describe ( inputAOI ) . Extent . height ) / GridSize <EOL> elif commonSpatialReference . type == "<STR_LIT>" : <EOL> inputAOIExtent = arcpy . Describe ( inputAOI ) . extent <EOL> newAOIExtent = inputAOIExtent . projectAs ( commonSpatialReference ) <EOL> calcCellSize = max ( newAOIExtent . width , newAOIExtent . height ) / GridSize <EOL> else : <EOL> arcpy . AddError ( "<STR_LIT>" ) <EOL> raise <EOL> if calcCellSize == <NUM_LIT:0.0> : <EOL> arcpy . AddError ( "<STR_LIT>" ) <EOL> raise <EOL> env . spatialReference = commonSpatialReference <EOL> env . outputCoordinateSystem = commonSpatialReference <EOL> arcpy . AddMessage ( "<STR_LIT>" + str ( calcCellSize ) ) <EOL> env . cellSize = calcCellSize <EOL> intersectionList = [ ] <EOL> arcpy . AddMessage ( "<STR_LIT>" ) <EOL> vehicleTable = { } <EOL> vehicleRows = arcpy . da . SearchCursor ( inputVehicleParameterTable , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:name>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> for vehicleRow in vehicleRows : <EOL> oid = vehicleRow [ <NUM_LIT:0> ] <EOL> classname = str ( vehicleRow [ <NUM_LIT:1> ] ) <EOL> name = str ( vehicleRow [ <NUM_LIT:2> ] ) <EOL> weight = float ( vehicleRow [ <NUM_LIT:3> ] ) <EOL> maxkph = float ( vehicleRow [ <NUM_LIT:4> ] ) <EOL> onslope = float ( vehicleRow [ <NUM_LIT:5> ] ) <EOL> offslope = float ( vehicleRow [ <NUM_LIT:6> ] ) <EOL> vehicleTable [ name ] = [ classname , name , weight , maxkph , onslope , offslope ] <EOL> del vehicleRows <EOL> if debug == True : arcpy . AddMessage ( "<STR_LIT>" + str ( vehicleTable ) ) <EOL> vehicleParams = vehicleTable [ inputVehicleType ] <EOL> if debug == True : arcpy . AddMessage ( "<STR_LIT>" + str ( vehicleParams ) ) <EOL> arcpy . AddMessage ( "<STR_LIT>" ) <EOL> slopeClip = os . path . join ( scratch , "<STR_LIT>" ) <EOL> outSlope = sa . ExtractByMask ( inputSlope , inputAOI ) <EOL> outSlope . save ( slopeClip ) <EOL> deleteme . append ( slopeClip ) <EOL> arcpy . AddMessage ( "<STR_LIT>" ) <EOL> reclassSlope = os . path . join ( os . path . dirname ( scratch ) , "<STR_LIT>" ) <EOL> if debug == True : arcpy . AddMessage ( "<STR_LIT>" + str ( reclassSlope ) ) <EOL> if debug == True : arcpy . AddMessage ( str ( time . strftime ( "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> outCon = sa . Con ( sa . Raster ( slopeClip ) > float ( vehicleParams [ <NUM_LIT:5> ] ) , float ( vehicleParams [ <NUM_LIT:5> ] ) , sa . Raster ( slopeClip ) ) <EOL> outCon . save ( reclassSlope ) <EOL> deleteme . append ( reclassSlope ) <EOL> arcpy . AddMessage ( "<STR_LIT>" ) <EOL> elevClip = os . path . join ( env . scratchGDB , "<STR_LIT>" ) <EOL> outElev = sa . ExtractByMask ( inputElevation , inputAOI ) <EOL> outElev . save ( elevClip ) <EOL> deleteme . append ( elevClip ) <EOL> constNoEffect = os . path . join ( env . scratchGDB , "<STR_LIT>" ) <EOL> outConstNoEffect = sa . CreateConstantRaster ( <NUM_LIT:1.0> , "<STR_LIT>" , env . cellSize , arcpy . Describe ( inputAOI ) . Extent . projectAs ( env . outputCoordinateSystem ) ) <EOL> outConstNoEffect . save ( constNoEffect ) <EOL> deleteme . append ( constNoEffect ) <EOL> f1 = os . path . join ( env . scratchFolder , "<STR_LIT>" ) <EOL> if debug == True : <EOL> arcpy . AddMessage ( str ( time . strftime ( "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> arcpy . AddMessage ( "<STR_LIT>" + str ( slopeClip ) ) <EOL> slopeAsRaster = sa . Raster ( reclassSlope ) <EOL> outF1 = ( float ( vehicleParams [ <NUM_LIT:5> ] ) - slopeAsRaster ) / ( float ( vehicleParams [ <NUM_LIT:4> ] ) / float ( vehicleParams [ <NUM_LIT:3> ] ) ) <EOL> outF1 . save ( f1 ) <EOL> ccmFactorList . append ( f1 ) <EOL> deleteme . append ( f1 ) <EOL> arcpy . AddMessage ( "<STR_LIT>" ) <EOL> f2 = os . path . join ( env . scratchFolder , "<STR_LIT>" ) <EOL> if debug == True : arcpy . AddMessage ( str ( time . strftime ( "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> curvature = os . path . join ( scratch , "<STR_LIT>" ) <EOL> curveSA = sa . Curvature ( elevClip ) <EOL> curveSA . save ( curvature ) <EOL> deleteme . append ( curvature ) <EOL> if debug == True : arcpy . AddMessage ( str ( time . strftime ( "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> focalStats = os . path . join ( scratch , "<STR_LIT>" ) <EOL> window = sa . NbrCircle ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> fstatsSA = sa . FocalStatistics ( curvature , window , "<STR_LIT>" ) <EOL> fstatsSA . save ( focalStats ) <EOL> deleteme . append ( focalStats ) <EOL> maxRasStat = float ( str ( arcpy . GetRasterProperties_management ( focalStats , "<STR_LIT>" ) ) ) <EOL> fsRasStat = sa . Raster ( focalStats ) <EOL> if debug == True : <EOL> arcpy . AddMessage ( "<STR_LIT>" + str ( maxRasStat ) + "<STR_LIT>" + str ( type ( maxRasStat ) ) ) <EOL> arcpy . AddMessage ( "<STR_LIT>" + str ( fsRasStat ) + "<STR_LIT>" + str ( type ( fsRasStat ) ) ) <EOL> f2Calc = ( maxRasStat - fsRasStat ) / maxRasStat <EOL> f2Calc . save ( f2 ) <EOL> deleteme . append ( f2 ) <EOL> ccmFactorList . append ( f2 ) <EOL> if inputVegetation != None and arcpy . Exists ( inputVegetation ) == True : <EOL> f3t = os . path . join ( scratch , "<STR_LIT>" ) <EOL> f3 = os . path . join ( os . path . dirname ( scratch ) , "<STR_LIT>" ) <EOL> arcpy . AddMessage ( "<STR_LIT>" ) <EOL> vegetation = os . path . join ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if debug == True : arcpy . AddMessage ( str ( time . strftime ( "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> arcpy . Clip_analysis ( inputVegetation , inputAOI , vegetation ) <EOL> deleteme . append ( vegetation ) <EOL> arcpy . JoinField_management ( vegetation , "<STR_LIT>" , inputVegetationConversionTable , "<STR_LIT>" ) <EOL> if min_max == "<STR_LIT>" : <EOL> arcpy . PolygonToRaster_conversion ( vegetation , "<STR_LIT>" , f3t ) <EOL> else : <EOL> arcpy . PolygonToRaster_conversion ( vegetation , "<STR_LIT>" , f3t ) <EOL> outF3T = sa . Con ( sa . IsNull ( f3t ) , constNoEffect , f3t ) <EOL> outF3T . save ( f3 ) <EOL> deleteme . append ( f3t ) <EOL> deleteme . append ( f3 ) <EOL> ccmFactorList . append ( f3 ) <EOL> if inputSoils != None and arcpy . Exists ( inputSoils ) == True : <EOL> f4t = os . path . join ( scratch , "<STR_LIT>" ) <EOL> f4 = os . path . join ( os . path . dirname ( scratch ) , "<STR_LIT>" ) <EOL> arcpy . AddMessage ( "<STR_LIT>" ) <EOL> clipSoils = os . path . join ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if debug == True : arcpy . AddMessage ( str ( time . strftime ( "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> arcpy . Clip_analysis ( inputSoils , inputAOI , clipSoils ) <EOL> deleteme . append ( clipSoils ) <EOL> arcpy . JoinField_management ( clipSoils , "<STR_LIT>" , inputSoilsTable , "<STR_LIT>" ) <EOL> if wet_dry == "<STR_LIT>" : <EOL> arcpy . PolygonToRaster_conversion ( clipSoils , "<STR_LIT>" , f4t ) <EOL> else : <EOL> arcpy . PolygonToRaster_conversion ( clipSoils , "<STR_LIT>" , f4t ) <EOL> deleteme . append ( f4t ) <EOL> outF4T = sa . Con ( sa . IsNull ( f4t ) , constNoEffect , f4t ) <EOL> outF4T . save ( f4 ) <EOL> deleteme . append ( f4 ) <EOL> ccmFactorList . append ( f4 ) <EOL> if inputSurfaceRoughness != None and arcpy . Exists ( inputSurfaceRoughness ) == True : <EOL> f5t = os . path . join ( scratch , "<STR_LIT>" ) <EOL> f5 = os . path . join ( os . path . dirname ( scratch ) , "<STR_LIT>" ) <EOL> arcpy . AddMessage ( "<STR_LIT>" ) <EOL> clipRoughness = os . path . join ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if debug == True : arcpy . AddMessage ( str ( time . strftime ( "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> arcpy . Clip_analysis ( inputSurfaceRoughness , inputAOI , clipRoughness ) <EOL> arcpy . JoinField_management ( clipRoughness , "<STR_LIT>" , inputRoughnessTable , "<STR_LIT>" ) <EOL> intersectionList . append ( clipRoughness ) <EOL> arcpy . PolygonToRaster_conversion ( clipRoughness , "<STR_LIT>" , f5t ) <EOL> deleteme . append ( f5t ) <EOL> outF5T = sa . Con ( sa . IsNull ( f5t ) , constNoEffect , f5t ) <EOL> outF5T . save ( f5 ) <EOL> deleteme . append ( f5 ) <EOL> ccmFactorList . append ( f5 ) <EOL> if debug == True : arcpy . AddMessage ( "<STR_LIT>" + str ( ccmFactorList ) + str ( time . strftime ( "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> tempCCM = os . path . join ( env . scratchFolder , "<STR_LIT>" ) <EOL> targetCCM = "<STR_LIT>" <EOL> if len ( ccmFactorList ) == <NUM_LIT:2> : <EOL> if debug == True : arcpy . AddMessage ( str ( time . strftime ( "<STR_LIT>" + str ( ccmFactorList ) + "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> targetCCM = sa . Raster ( ccmFactorList [ <NUM_LIT:0> ] ) * sa . Raster ( ccmFactorList [ <NUM_LIT:1> ] ) <EOL> elif len ( ccmFactorList ) == <NUM_LIT:3> : <EOL> if debug == True : arcpy . AddMessage ( str ( time . strftime ( "<STR_LIT>" + str ( ccmFactorList ) + "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> targetCCM = sa . Raster ( ccmFactorList [ <NUM_LIT:0> ] ) * sa . Raster ( ccmFactorList [ <NUM_LIT:1> ] ) * sa . Raster ( ccmFactorList [ <NUM_LIT:2> ] ) <EOL> elif len ( ccmFactorList ) == <NUM_LIT:4> : <EOL> if debug == True : arcpy . AddMessage ( str ( time . strftime ( "<STR_LIT>" + str ( ccmFactorList ) + "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> targetCCM = sa . Raster ( ccmFactorList [ <NUM_LIT:0> ] ) * sa . Raster ( ccmFactorList [ <NUM_LIT:1> ] ) * sa . Raster ( ccmFactorList [ <NUM_LIT:2> ] ) * sa . Raster ( ccmFactorList [ <NUM_LIT:3> ] ) <EOL> elif len ( ccmFactorList ) == <NUM_LIT:5> : <EOL> if debug == True : arcpy . AddMessage ( str ( time . strftime ( "<STR_LIT>" + str ( ccmFactorList ) + "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> targetCCM = sa . Raster ( ccmFactorList [ <NUM_LIT:0> ] ) * sa . Raster ( ccmFactorList [ <NUM_LIT:1> ] ) * sa . Raster ( ccmFactorList [ <NUM_LIT:2> ] ) * sa . Raster ( ccmFactorList [ <NUM_LIT:3> ] ) * sa . Raster ( ccmFactorList [ <NUM_LIT:4> ] ) <EOL> else : <EOL> if debug == True : arcpy . AddMessage ( "<STR_LIT>" + str ( ccmFactorList ) + str ( time . strftime ( "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> arcpy . AddError ( "<STR_LIT>" + str ( ccmFactorList ) ) <EOL> raise <EOL> targetCCM . save ( tempCCM ) <EOL> arcpy . CopyRaster_management ( tempCCM , outputCCM ) <EOL> arcpy . SetParameter ( <NUM_LIT:5> , outputCCM ) <EOL> if debug == True : arcpy . AddMessage ( "<STR_LIT>" + str ( time . strftime ( "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> if debug == True : arcpy . AddMessage ( "<STR_LIT>" ) <EOL> for i in deleteme : <EOL> if debug == True : arcpy . AddMessage ( "<STR_LIT>" + str ( i ) ) <EOL> if arcpy . Exists ( i ) : <EOL> arcpy . Delete_management ( i ) <EOL> pass <EOL> if debug == True : arcpy . AddMessage ( "<STR_LIT>" ) <EOL> except arcpy . ExecuteError : <EOL> if debug == True : arcpy . AddMessage ( "<STR_LIT>" + str ( time . strftime ( "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> tb = sys . exc_info ( ) [ <NUM_LIT:2> ] <EOL> tbinfo = traceback . format_tb ( tb ) [ <NUM_LIT:0> ] <EOL> arcpy . AddError ( "<STR_LIT>" + tbinfo ) <EOL> msgs = arcpy . GetMessages ( ) <EOL> arcpy . AddError ( msgs ) <EOL> print ( msgs ) <EOL> except : <EOL> if debug == True : arcpy . AddMessage ( "<STR_LIT>" + str ( time . strftime ( "<STR_LIT>" , time . localtime ( ) ) ) ) <EOL> tb = sys . exc_info ( ) [ <NUM_LIT:2> ] <EOL> tbinfo = traceback . format_tb ( tb ) [ <NUM_LIT:0> ] <EOL> pymsg = "<STR_LIT>" + tbinfo + "<STR_LIT>" + str ( sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> msgs = "<STR_LIT>" + arcpy . GetMessages ( ) + "<STR_LIT:\n>" <EOL> arcpy . AddError ( pymsg ) <EOL> arcpy . AddError ( msgs ) <EOL> print ( pymsg + "<STR_LIT:\n>" ) <EOL> print ( msgs ) </s>
