Quantcast
Viewing all articles
Browse latest Browse all 190

Calculating NDVI using QGIS Python Console

I'm going to calculate NDVI using band 4 and band 3 of Landsat 5.

The code I wrote:

import os, reimport processingfrom osgeo import gdalinput_B4 = r'C:\Users\test\LT05_L2SP_114034_19850820_20200918_02_T1_SR_B4.TIF'input_B3 = r'C:\Users\test\LT05_L2SP_114034_19850820_20200918_02_T1_SR_B3.TIF'outfile = r'C:\Users\test_raster_cal\test1.tif'processing.run("gdal:rastercalculator", {'INPUT_A': input_B4,'BAND_A':1,'INPUT_B': input_B3, 'BAND_B':1,'FORMULA':'(A-B)/(A+B)','NO_DATA':None,'RTYPE':5,'OPTIONS':'','EXTRA':'','OUTPUT':outfile })

In the picture below, test_cal is made using the QGIS Raster Calculator ToolTest1 is a code that I wrote.

Image may be NSFW.
Clik here to view.
enter image description here

Image may be NSFW.
Clik here to view.
enter image description here

Image may be NSFW.
Clik here to view.
enter image description here

Image may be NSFW.
Clik here to view.
enter image description here

[QGIS Raster Calculator Tool]

Image may be NSFW.
Clik here to view.
enter image description here

[My code]

Image may be NSFW.
Clik here to view.
enter image description here

When using the QGIS Tool, the value is between -1 and 1, and the NDVI made with the code I wrote is about 0 to 65.

How do I modify the code to calculate the NDVI properly?


Viewing all articles
Browse latest Browse all 190

Trending Articles