arcpy批量按条件设置空值

arcpy批量按条件设置空值,并且将空值设为0。

import os
import re
import arcpy
from arcpy import env
from arcpy.sa import *
import os

arcpy.env.workspace = r'D:\LST_8day_eartdata'

def GetRaster(file_path, out_path):
    n = 0
    files = os.listdir(file_path)
    for file in files:
        type = file.split(".")
        if type[1] == "tif":
            import arcpy
            print(file)
            pattern = '.tif$'
            file_out = re.split(pattern, file)[0]+ "_0.tif"
            
            raster = os.path.join(file_path, file)
            out_raster = os.path.join(out_path, file_out)
            #Set local variables
            inRaster = raster
            inFalseRaster = inRaster
            whereClause = "value< 0" # and "value< -10 or value > 0"

            #Check out the ArcGIS Spatial Analyst extension license
            arcpy.CheckOutExtension("Spatial")

            # Execute SetNull
            outSetNull = SetNull(inRaster, inFalseRaster, whereClause)

            outCon = Con(IsNull(outSetNull),0, outSetNull)
            
            #save
            outCon.save(out_raster)
            
            n = n+1
    print (str(n)+" rasters are processed !!!")


if __name__ ==  "__main__":
    data_path = r'D:\LST_8day_eartdata\merge_DN'
    out_path = r'D:\LST_8day_eartdata\tif'
    GetRaster(data_path, out_path)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值