# -*- coding: utf-8 -*-
# @Time : 2020/12/10 19:16
# @Author : ZhangMin
import arcpy
import glob
import os
'''
批量裁剪:
对输入文件夹下的数据,根据shp文件,进行批量裁剪,结果存放于输出文件夹
需要修改:
'''
arcpy.CheckOutExtension('Spatial')
# 输出文件夹
outfile = r"H:\大论文\福建省\2008-2012Landsat5&7\30m分辨率修正版、\按潮区裁剪的影像".decode('utf-8')
# shp文件夹
shpmask = r"H:\大论文\福建省\1998-2002Landsat4&5\30m修正版\新潮区划分".decode('utf-8')
# 影像路径
rasters = r'H:\大论文\福建省\2008-2012Landsat5&7\30m分辨率修正版、\潮滩频率\20082012潮滩范围频率.tif'.decode('utf-8')
files = []
for shp in os.listdir(shpmask):
if os.path.splitext(shp)[1] == '.shp':
sourcefile = os.path.join(shpmask, shp)
files.append(sourcefile)
# print(sourcefile)
# 截断文件名
(filepath, tempfilename) = os.path.split(sourcefile)
(filename, extension) = os.path.splitext(tempfilename)
print(filename)
# 输出路径+文件名
outname = os.path.join(outfile, filename + ".tif")
print(outname)
# 裁剪
out_extract = arcpy.sa.ExtractByMask(rasters, sourcefile)
out_extract.save(outname)
Arcpy专题:批量裁剪影像
最新推荐文章于 2024-06-18 16:30:18 发布