Arcpy 批量用掩膜裁剪栅格

 这个代码是用来批量裁剪栅格的 就是ExtractByMask这个功能

import os
import glob
import arcpy
from arcpy import env
from arcpy.sa import *
import shutil
import datetime

arcpy.CheckOutExtension("spatial")

input_path = r"E:\DATA\\" # 输入路径

output_path = input_path + 'Extract' #输出路径

if os.path.exists(output_path): #如果没有建输出文件夹 会自动建
    shutil.rmtree(output_path)
    os.mkdir(output_path)
else:
    os.mkdir(output_path)
    
inMaskData = r"E:\DATA\geo\newRALUCC.tif" #掩膜文件 用shp也可以

arcpy.env.workspace = input_path
rasterList = arcpy.ListRasters("*","tif")
 
for raster in rasterList:
    print raster
    # Set local variables
    inRaster = raster
    #rd = arcpy.sa.Raster(inRaster)
    # Set the extent environment as the raster, very important for clip with different vector
    #arcpy.env.extent = rd.extent
    dir_path,inraster_name = os.path.split(inRaster) # 分离路径和输入栅格名称
    outraster_name = inraster_name
    out_raster = output_path + '\\' + outraster_name
    
    # Execute ExtractByMask
    outExtractByMask = ExtractByMask(inRaster, inMaskData)
    # Save the output
    out = out_raster
    outExtractByMask.save(out)

最后裁剪完的栅格 空值的地方是-3.4028235e+38(用matlab查看的) 不是nan

应该是arcgis的软件设置 空值是inf 就几乎等于-3.4028235e+38这个值了吧

如果还要继续处理 可以用matlab跑一边 这个代码我也有

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值