Select to view content in your preferred language

The NDVI Python function doesn't provide any output

1242
6
10-21-2021 04:39 PM
MaryamBarzegar
Emerging Contributor

Hi, does the NDVI Python function actually work? It doesn't retrieve any output for me.

 

https://pro.arcgis.com/en/pro-app/2.7/arcpy/image-analyst/ndvi.htm 

0 Kudos
6 Replies
JayantaPoddar
MVP Esteemed Contributor

If you are using a standalone python script, you could use a similar script as the following

# Import system modules
import arcpy
from arcpy.ia import *

# Set the analysis environments
arcpy.env.workspace = "C:/arcpyExamples/data"

# Set the local variables
in_raster = "landsat8.tif"

# Execute NDVI function
out_ndvi_raster = NDVI(in_raster, 5, 4)

# Save the output
out_ndvi_raster.save("C:/arcpyExamples/outputs/NDVI.tif")

 



Think Location
0 Kudos
DanPatterson
MVP Esteemed Contributor

Did you save the raster?

Raster—ArcGIS Pro | Documentation

by "retrieve " do you mean it doesn't create one, or you don't see one?


... sort of retired...
0 Kudos
MaryamBarzegar
Emerging Contributor

Thank you @JayantaPoddar and @DanPatterson but I saved the raster and I have exactly the same code but it doesn't produce anything and I don't get any errors either. Does this work with any satellite image? Mine is WorldView 2

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

I assume you have Image Analyst Extension for ArcGIS Pro.

Bands are different for WorldView 2.

Maybe you could try Band 7 (NIR1) and Band 5 (Red).

Also ensure you are providing an existing workspace which contains the composite image (containing multiple bands), the correct image name and existing output path.

If you still have confusion, please share the screenshot of the folder containing the Worldview 2 image(s) in Windows Explorer, and also the script you have so far.

 



Think Location
0 Kudos
MaryamBarzegar
Emerging Contributor

Are you sure I need Image Analyst extension? Raster functions don't need Image Analyst extension. When I use the NDVI tool, I can create an NDVI image and I don't have Image Analyst extension. Also, I think at least it needs to give me an error if Image Analyst extension is the issue

0 Kudos
DanPatterson
MVP Esteemed Contributor