【ArcGIS自定义脚本工具】批量设为空函数脚本

一、功能介绍
【ArcGIS自定义脚本工具】批量设为空函数脚本_第1张图片
对设为空函数工具的介绍,可以查看这篇博客:常用的Arcmap内置工具(一)

二、脚本代码

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import arcpy
from arcpy import env
from arcpy.sa import *

raster_path = arcpy.GetParameterAsText(0)
condition = arcpy.GetParameterAsText(1)
new_dir_name = arcpy.GetParameterAsText(2)


def setN_batch(new_dir_name, new_prefix = "setN_"):
    env.workspace = raster_path
    raster_list = arcpy.ListRasters()
    for inraster in raster_list:
        outraster = "\\" + new_dir_name + "\\" + new_prefix + inraster
        arcpy.gp.SetNull_sa(inraster, inraster, outraster, condition)
        arcpy.AddMessage("Step2:"+ str(new_prefix) + inraster[:] + "has done.")
        arcpy.SetProgressorPosition()
    arcpy.AddMessage("Step2:Completed")


arcpy.ResetProgressor()

dir_name = new_dir_name
out_path = raster_path + "\\" + dir_name
os.makedirs(out_path)
arcpy.AddMessage("Step1:Creating new folder named " + str(dir_name))
arcpy.AddMessage("Step1:Completed")
if arcpy.CheckExtension("Spatial") == "Available":
    setN_batch(dir_name)
else:
    arcpy.AddMessage("Error!!! Spatial Analyst is unavailable")

三、工具参数
【ArcGIS自定义脚本工具】批量设为空函数脚本_第2张图片
【ArcGIS自定义脚本工具】批量设为空函数脚本_第3张图片

四、工具界面
【ArcGIS自定义脚本工具】批量设为空函数脚本_第4张图片

你可能感兴趣的:(ArcGIS自定义脚本编程,ArcGIS,自定义脚本,ArcGIS自定义脚本,批量设为空函数)