Raster Calculations with Spatial Analyst

683
1
05-18-2013 04:33 AM
JonathanHodel
New Contributor III
I am trying to run NDVI calculations with Arcpy.  My script is running but ArcGIS crashes each time I try to run it.  Here is the part of the script with the problem:

for raster in rasterList:
        try:
                #Define the inputs
                arcpy.AddMessage('Calculating NDVI for ' + raster)
                NIR = raster + "\Band_1"
                Red = raster + "\Band_2"

                #Define outputs �?? Note:  These will need to be deleted if you need to run this script again
                NIR_out = "NIR.tif"
                Red_out = "Red.tif"
               
                #Copy raster and map algebra �?? makes new rasters of Red and NearIR
                arcpy.AddMessage('exporting raster bands for calculation')
                arcpy.CopyRaster_management(NIR, NIR_out)
                arcpy.AddMessage('NIR band exported successfully')
                arcpy.CopyRaster_management(Red, Red_out)
                arcpy.AddMessage('Red band exported successfully')

                #Create Numerator and Denominator rasters as variables and NDVI output (note that arcpy.sa.Float returns a floating point raster)
                result = "NDVI.tif"
                NIRfloat = float(NIR)
                Redfloat = float(Red)
                Num = Raster(NIRfloat) - Raster(Redfloat)
0 Kudos
1 Reply
DanPatterson_Retired
MVP Emeritus
I am assuming you imported the spatial analyst.
float should be capitalized
what of the arcpy.AddMessage lines get displayed?
0 Kudos