环境:pycharm 解释器:Arcgis10.4自带的python2.7
批量裁剪栅格:
# -*-coding:utf-8-*-
import arcpy
import os
arcpy.env.workspace = r"C:\Users\Desktop\jjjj" # 设置工作空间
shppath = r"C:\Users\Desktop\jjjj\区划.shp" # 裁剪要素路径
rasterpath = r"C:\Users\Desktop\jjjj\广东.tif" # 被裁剪的栅格数据路径
savepath = r"C:\Users\Desktop\jjjj\result" # 保存路径
def cli(shppath, rasterpath, savepath):
with arcpy.da.SearchCursor(shppath, ["市", "SHAPE@"]) as cursor: # 获取各个区域的名称及裁剪范围
for row in cursor:
mask = row[1]
outpath = os.path.join(savepath, str(row[0].encode("utf-8")) + ".tif")
arcpy.Clip_management(rasterpath, "#", outpath, mask, "0", "ClippingGeometry") # 使用裁剪栅格函数
print str(row[0].encode("utf-8")) + ".tif" + "裁剪成功"
c