Python遥感图像处理基础篇(三):arcpy遥感图像镶嵌批量处理_去除背景值

鉴于前面两篇中存在背景值干扰问题,这里采用CopyRaster方法赋值栅格数据并去除背景值

代码如下:

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

#读取和存放文件夹的位置
inputPath1 = r'H:\input1'#镶嵌数据文件夹1
inputPath2 =r'H:\input2'#镶嵌数据文件夹2
path=r'H:\outputMocaic'#输出结果存放文件夹

# start calculate time
startTime = datetime.datetime.now()
print startTime

# 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......")
print("Please do not close the window.")

#这段为数据处理代码
# function:按顺序拼接字符串,作为波段组合函数的的参数
def getInputRasterParam(files):
    ret = []
    print "需要镶嵌的影像数据1系列:"
    for file in files:  # 拼接其他的
         if file.endswith(".tif"):
            print file 
            ret.append(file)
    return ret
def getInputShapefileParam(files):
    ret = []
    print "需要镶嵌的影像数据2系列:"
    for file in files:  # 拼接其他的
         if file.endswith(".shp"):
            print file 
            ret.append(file)
    return ret

arcpy.env.workspace = resultDataPath  #被裁剪栅格影像所在文件夹
arcpy.env.overwriteOutput = True#允许覆盖已有数据
files1 = os.listdir(inputPath1)
files2 = os.listdir(inputPath2)
print "-----------------------------------------"
param1 = getInputRasterParam(files1)
param2 = getInputRasterParam(files2)
print "-----------------------------------------"
print "采用CopyRaster方法去除背景值"
for raster1 in param1:
    print raster1
    arcpy.CopyRaster_management(inputPath1+"\\"+raster1,intermediateDataPath+"\\"+raster1[:-4]+"_copy.tif","DEFAULTS","-3000","nodata","","","16_BIT_SIGNED")
for raster2 in param2:
    arcpy.CopyRaster_management(inputPath2+"\\"+raster2,intermediateDataPath+"\\"+raster2[:-4]+"_copy.tif","DEFAULTS","-3000","nodata","","","16_BIT_SIGNED")


print "Finish!"
endTime = datetime.datetime.now()
print "Time use: " + str((endTime - startTime).seconds)+ " (second)"
print "-----------------------------------------------------------"

运行结果:显示貌似是对的,但是图层列表中还存在-3000值,可能有异常值存在

Python遥感图像处理基础篇(三):arcpy遥感图像镶嵌批量处理_去除背景值_第1张图片

Python遥感图像处理基础篇(三):arcpy遥感图像镶嵌批量处理_去除背景值_第2张图片

你可能感兴趣的:(#,Python遥感图像处理,arcpy去除背景值)