【ArcGIS自定义脚本工具】批量提取子数据集

tech2022-08-18  125

文章目录

一、功能介绍二、脚本代码三、工具参数四、工具界面


一、功能介绍


二、脚本代码

#!/usr/bin/python # -*- coding: UTF-8 -*- import os import arcpy import time in_path = arcpy.GetParameterAsText(0) out_path = arcpy.GetParameterAsText(1) subdataset_index = arcpy.GetParameterAsText(2) suffix = arcpy.GetParameterAsText(3) arcpy.env.overwriteOutput = 1 arcpy.CheckOutExtension("Spatial") arcpy.env.workspace = in_path arcpy.env.scratchWorkspace = in_path hdfList = arcpy.ListRasters('*', 'HDF') nums = len(hdfList) # number of hdf files num = 1 # current serial number if not os.path.exists(out_path): os.makedirs(out_path) for hdf in hdfList: s = time.time() raster_name = "{0}{1}{2}.{3}.tif".format(out_path, os.sep, '.'.join(hdf.split('.')[:3]), suffix) try: data1 = arcpy.ExtractSubDataset_management(hdf, raster_name, subdataset_index) e = time.time() arcpy.AddMessage("{0}/{1} | {2} Completed, time used {3}s".format(num, nums, hdf, e-s)) except: arcpy.AddMessage("{0}/{1} | {2} Errored".format(num, nums, hdf)) num += 1

三、工具参数


四、工具界面

最新回复(0)