1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
import math import arcpy import os from arcpy import sa from arcpy.sa import * from time import strftime arcpy.CheckOutExtension("Spatial") arcpy.env.overwriteOutput = True print("Program start time:"+strftime("%m/%d/%Y %H:%M"))
Inputpath="E://waterL8data"
projectFilePath="E://waterL8data//AEA_WGS_1984.prj"
Zone="E://waterL8data//province.shp"
arcpy.env.workspace="E://waterL8data//test"
finalwaterName="finalwater.tif"
allFilesOrFoldersList = os.listdir(Inputpath) for FileOrFolder in allFilesOrFoldersList: FileOrFolder_path = os.path.join(Inputpath, FileOrFolder) if os.path.isdir(FileOrFolder_path): FolderPath=FileOrFolder_path allFilesList = os.listdir(FolderPath) for file in allFilesList: fileFullPath=os.path.join(FolderPath, file) if file[-6:] == "B3.TIF": green = arcpy.Raster(fileFullPath) elif file[-6:] == "B6.TIF": Mir = arcpy.Raster(fileFullPath) MNDVI=(green-Mir)*1.0/(green+Mir) MNDVIcor=Con((MNDVI>0.05) & (Mir<7200),1,2) outputPath=FileOrFolder+".tif" arcpy.CopyRaster_management(MNDVIcor, outputPath, "", 0, "") print(FolderPath+"CopyRaster success")
rasters=[] for raster in arcpy.ListRasters("*.tif"): rasters.append(raster) arcpy.MosaicToNewRaster_management(rasters, str(arcpy.env.workspace), "water.tif", "","8_BIT_UNSIGNED", "30", "1", "MINIMUM","FIRST") print("Mosaic success")
water= "water.tif" arcpy.ProjectRaster_management(water, "water_rep.tif",projectFilePath, "NEAREST", "30","#", "#", "#") print("ProjectRaster success")
ExtractByMask("water.tif",Zone).save(finalwaterName) print("ExtractByMask success")
print("program end time:"+strftime("%m/%d/%Y %H:%M"))
|