Python遥感图像处理应用篇(一):Arcpy遥感图像NDVI指数计算批量处理

1.使用数据MOD09A1

MOD09A1数据网上有很多介绍,这里不做详细说明了。通过MRT工具处理完之后,包含以下数据:

即主要包含1-7波段数据以及其他一些数据。空间分辨率为500m,时间分辨率为8day。

2.Modis波段主要应用领域

这里直接从其它地方复制而来可供大家参考一下:

Python遥感图像处理应用篇(一):Arcpy遥感图像NDVI指数计算批量处理_第1张图片

3.NDVI指数计算公式

直接列出公式

来一段波段数据的英文说明:

The MODIS sensor has 36 spectral bands, seven ofwhich are designed for the study of vegetation and landsurfaces: blue (459–479 nm), green (545–565 nm), red(620–670 nm), near infrared (NIR1: 841–875 nm; NIR2:1230–1250 nm), and shortwave infrared (SWIR1: 1628–1652 nm, SWIR2: 2105–2155 nm). Daily global imageryis provided at spatial resolutions of 250-m (red andNIR1) and 500-m (blue, green, NIR2, SWIR1, SWIR2)

从说明中可以看出,Nir是NIR1: 841–875 nm; NIR2:1230–1250 nm两个,这里采用第一个,即modis的第2波段。Red是 red(620–670 nm),即第1波段,采用这两个波段即可计算NDVI指数。

4.Modis数据整理

把MOD09A1处理出来的数据分别按照波段对应放在两个文件夹里面:

NDVITset01:

Python遥感图像处理应用篇(一):Arcpy遥感图像NDVI指数计算批量处理_第2张图片

NDVITest02:

Python遥感图像处理应用篇(一):Arcpy遥感图像NDVI指数计算批量处理_第3张图片

5.使用Arcpy进行NDVI指数计算代码

废话不多说,直接上代码:

# -*- coding: utf-8 -*-
import os,arcpy,datetime
from arcpy.sa import *

#存放文件夹的位置
Red_path = r'H:\NDVITest01'#红色波段存放文件夹
NIR_path = r'H:\NDVITest02'#近红外波段存放文件夹
path =r'H:\NDVIOUT'#输出结果存放文件夹

# set the intermediate data folder
intermediateDataPath = path+"\\"+"IntermediateData"
# set result data folder
resultDataPath = path+"\\"+"Result"

# determine if the folder exists
if os.path.exists(intermediateDataPath):
    print "IntermediateData floder exists"
else:
    # create a intermediate data floder
    arcpy.CreateFolder_management(path, "IntermediateData")    
if os.path.exists(resultDataPath):
    print "Result floder exists"
else:   
    # create a result floder
    arcpy.CreateFolder_management(path, "Result")

print "Under calculation......"

arcpy.env.workspace = Red_path  #所在文件夹
rasters = arcpy.ListRasters("*", 'tif')  #栅格数据格式设置
for raster in rasters:
    print(raster)
    # set workspace
    arcpy.env.workspace = intermediateDataPath
    arcpy.env.overwriteOutput = True
    # Check out the ArcGIS 3D Analyst extension license
    arcpy.CheckOutExtension("3D")
    NIRraster = NIR_path +'\\'+raster[:-5]+"2.tif"
    NDVIoutPath = resultDataPath+'\\'+ raster[:-24]+ "_NDVI.tif"
    print(NIRraster)
    # Converted to floating-point data
    arcpy.Float_3d(Red_path+'\\'+ raster, "floatRedBand.tif")
    arcpy.Float_3d(NIRraster, "floatNIRBand.tif")
    #计算NDVI分子
    arcpy.Minus_3d("floatNIRBand.tif", "floatRedBand.tif", "outminus.tif")
    #计算NDVI分母
    arcpy.Plus_3d("floatNIRBand.tif", "floatRedBand.tif", "NDVIfenmu.tif")
    #计算NDVI
    arcpy.Divide_3d("outminus.tif", "NDVIfenmu.tif", NDVIoutPath)#计算NDVI
    print(raster+"  has done")  
print("All done")
#清理workspace中的缓存数据        
for i in os.listdir(intermediateDataPath):
    path_file = os.path.join(intermediateDataPath,i)
    if os.path.isfile(path_file):
        os.remove(path_file)

6.运行结果

Python遥感图像处理应用篇(一):Arcpy遥感图像NDVI指数计算批量处理_第4张图片

Python遥感图像处理应用篇(一):Arcpy遥感图像NDVI指数计算批量处理_第5张图片

Python遥感图像处理应用篇(一):Arcpy遥感图像NDVI指数计算批量处理_第6张图片

IntermediateData文件夹下已清理干净

Result下位计算结果

Python遥感图像处理应用篇(一):Arcpy遥感图像NDVI指数计算批量处理_第7张图片

arcmap打开看一下:

Python遥感图像处理应用篇(一):Arcpy遥感图像NDVI指数计算批量处理_第8张图片

7.总结

这样整个计算就完成了!

 

 

 

你可能感兴趣的:(#,Python遥感图像处理,NDVI批量计算arcpy)