AnsweredAssumed Answered

My code is not doing anything

Question asked by stashaestha1 on Dec 12, 2017
Latest reply on Dec 12, 2017 by Dan_Patterson

I have written a code to check if areas will be inundates when a certain value is added, the code doesn't give any errors but at the same time it does do anything.

Just says running code complete, I am not even sure what the problem is. My code is here

 

import arcpy
import os, sys, traceback, shutil
import numpy as np

arcpy.env.overwriteOutput = True

try:
     outputfolder = arcpy.GetParameterAsText(0)
     fc = arcpy.GetParameterAsText(1)
     inputraster = arcpy.GetParameterAsText(2)

     #check to see if the arcinfo license is on
     if arcpy.CheckExtension("Spatial") == "Available":
          arcpy.CheckOutExtension("Spatial")
     else:
          arcpy.AddError("Spatial analyst extension is not licensed.")
          sys.exit()

     #set the Progressor
     #arcpy.SetProgessor("step","Checking input requirements....",0,9,1)

     #Process :create an out put folder
     arcpy.CreateFileGDB_management(outputfolder,"output.gdb")
     outputgdb = outputfolder + "\\output.gdb"+ os.step

     #create path to store raster data
     clippedraster = outputfolder + "clippedraster"
     flooded = outputfolder +"floodedarea"

     #check to see if the inputs are in the same projection
     desccs_ras = arcpy.Describe(inputraster).SpatialReference
     desccs_fc = arcpy.Describe(fc).SpatialReference
     if desccs_ras.name == "Unknown" and desccs_fc.name == "Unknown":
          arcpy.AddMessage("Your data does not have a defined spatial reference")
     else:
          if desccs_ras.projectionName == desccs_fc.projectionName:
               ""
          else:
               arcpy.AddError("The input Data should be in the same projection")
               sys.exit()
          del desccs_fc,desccs_ras

     #remove the areas below sea level
     currentRaster = arcpy.Raster(inputraster)
     rastertoclip = Con(currentRaster>=0,currentRaster,1)

     #clip the raster data to the interested zone extend
     arcpy.Clip_management(rastertoclip,"#",clippedraster,fc,"#","ClippingGeometry","MAINTAIN_EXTENT")
     clip_raster = arcpy.Raster("in_memory")
     areasbelow = clip_raster <= 2
     areasbelow.save(flooded)

     md = arcpy.mapping.MapDocument("CURRENT")
     df = arcpy.mapping.ListDataFrames(md)[0]
     result = arcpy.MakeRasterLayer_management(flooded,"FloodedArea")
     layer = result.getOutput(0)
     arcpy.mapping.AddLayer(df, layer,"AUTO_ARRANGE")

except:
     tb = sys.exc_info()[2]
     tbinfo = traceback.format_tb(tb)[0]
     pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n    " + \
            str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"

Outcomes