Python遥感图像处理应用篇:Arcpy遥感图像LWSI指数计算批量处理

Posted 空中旋转篮球

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python遥感图像处理应用篇:Arcpy遥感图像LWSI指数计算批量处理相关的知识,希望对你有一定的参考价值。

1.使用数据MOD09A1

2.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)
这里选择第2波段和第6波段进行计算。

3.Modis数据整理

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

 

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

# -*- coding: utf-8 -*-
import os,arcpy
from arcpy.sa import *
#存放文件夹的位置
NIR_path = r'H:\\NDVITest02'#近红外波段存放文件夹
Swir_path = r'H:\\NDVITest06'#Swir波段存放文件夹
path =r'H:\\NDVITestOut'#输出结果存放文件夹

# 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 "-----------------------------------------------------------"
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"
    Swirraster = Swir_path +'\\\\'+raster[:-5]+"6.tif"
    LWSIoutPath = resultDataPath+'\\\\'+ raster[:-24]+ "_LWSI.tif"
    print(NIRraster)
    # Converted to floating-point data
    arcpy.Float_3d(NIRraster, "floatNIRBand.tif")
    arcpy.Float_3d(Swirraster, "SwirBand.tif")
    #后续操作在workspace中进行不需要设置具体路径
    #计算LWSI上下式
    arcpy.Minus_3d("floatNIRBand.tif", "SwirBand.tif", "LWSIfenzi.tif")
    arcpy.Plus_3d("floatNIRBand.tif", "SwirBand.tif", "LWSIfenmu.tif")
    #计算LWSI
    arcpy.Divide_3d("LWSIfenzi.tif", "LWSIfenmu.tif", LWSIoutPath)#计算LWSI
    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)
print "Finish!"

 

以上是关于Python遥感图像处理应用篇:Arcpy遥感图像LWSI指数计算批量处理的主要内容,如果未能解决你的问题,请参考以下文章

Python遥感图像处理应用篇:Arcpy批量计算比值植被指数RVI

Python遥感图像处理应用篇(十三):Arcpy批量计算绿度归一化植被指数GNDVI

Python遥感图像处理应用篇(十三):Arcpy批量计算绿度归一化植被指数GNDVI

Python遥感图像处理应用篇(二十五):Python+GDAL 波段组合

Python遥感图像处理应用篇(二十五):Python+GDAL 波段组合

Python遥感图像处理--开篇