【ArcGIS自定义脚本工具】批量裁剪中国多省份NDVI影像

文章目录

  • 一、功能介绍
  • 二、脚本代码
  • 三、工具参数
  • 四、工具界面
  • 五、使用例
    • 1、输入
    • 2、参数设置
    • 3、输出

系列文章目录:ArcGIS自定义脚本编程


一、功能介绍


二、脚本代码

#!/usr/bin/python# -*- coding: UTF-8 -*-import arcpyfrom arcpy import envimport osimport timeimport sysreload(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 = 1for 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, "0", "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、输出

来源:https://www.icode9.com/content-4-856051.html

(0)

相关推荐