【ArcGIS自定义脚本工具】批量裁剪栅格(多对多)
文章目录一、功能介绍二、脚本代码三、工具参数四、工具界面系列文章目录:ArcGIS自定义脚本编程一、功能介绍二、脚本代码#!/usr/bin/python# -*- coding: UTF-8 -*-三、工具参数四、工具界面......
·
系列文章目录: ArcGIS自定义脚本编程
一、功能介绍
二、脚本代码
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import arcpy
from arcpy import env
import os
import time
import sys
reload(sys)
sys.setdefaultencoding('utf8')
tifs = arcpy.GetParameterAsText(0)
masks = arcpy.GetParameterAsText(1)
out_dir = arcpy.GetParameterAsText(2)
tifs = tifs.split(";")
masks = masks.split(";")
names = [os.path.splitext(os.path.basename(mask))[0] for mask in masks]
size = len(tifs) * len(masks)
num = 1
for i, mask in enumerate(masks):
# create a new folder named by mask's name
new_folder = out_dir + os.sep + names[i]
if not os.path.exists(new_folder):
os.mkdir(new_folder)
else:
arcpy.AddMessage("Folder {0} already exists. Please check it.".format(new_folder))
for tif in tifs:
s = time.time()
cliped_tif = os.path.join(new_folder, "{0}_{1}".format(names[i],os.path.split(tif)[1]))
if not os.path.exists(cliped_tif):
arcpy.Clip_management(tif, "#", cliped_tif, mask, "#", "ClippingGeometry")
e = time.time()
arcpy.AddMessage("{0}/{1} | {2} Completed, time used {3}s".format(num, size, cliped_tif, e - s))
else:
e = time.time()
arcpy.AddMessage("{0}/{1} | {2} already exists.".format(num, size, cliped_tif))
num += 1
三、工具参数
四、工具界面
五、使用例
1、输入
2、参数设置
3、输出
更多推荐
已为社区贡献15条内容
所有评论(0)