Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

Below is the NDVI equation,

NDVI = (NIR — VIS)/(NIR + VIS)

With the help of python, I'm trying to calculate the NDVI equation.

I've tried this:

inRaster = ('Landsat.tif')

out_NDVI_file = ('NDVI.tif')

red = arcpy.Describe(inRaster+'/Band_3')

NIR = arcpy.Describe(inRaster+'/Band_4')

num = arcpy.sa.Float(NIR-red)

denom = arcpy.sa.Foat(NIR+red)

NDVI = arcpy.sa.Divide(num, denom)

NDVI.Save(out_NDVI_file)

But, I'm getting this error message,

Traceback (most recent call last):

  File "F:\abc\def.py", line 32, in <module>

    num = arcpy.sa.Float(NIR-red)

TypeError: unsupported operand type(s) for -: 'geoprocessing describe data object' and 'geoprocessing describe data object'

Can anyone tell me, where I'm going wrong?

1 Answer

0 votes
by (26.4k points)

Try replacing,

red = arcpy.Describe(inRaster+'/Band_3')

NIR = arcpy.Describe(inRaster+'/Band_4')

with

red = arcpy.sa.Raster(inRaster+'/Band_3')

NIR = arcpy.sa.Raster(inRaster+'/Band_4')

Join python course to learn python in details to gain more knowledge.

Browse Categories

...