1、创建新 Python 脚本
# coding=utf-8 """----------------------------------------------------------------------------- Script Name: Clip Multiple Feature Classes Description: Clips one or more shapefiles from a folder and places the clipped feature classes into a geodatabase. Created By: Insert name here. Date: Insert date here. -----------------------------------------------------------------------------""" # Import ArcPy site-package and os modules import arcpy import os # Set the input workspace arcpy.env.workspace = arcpy.GetParameterAsText(0) # Set the clip featureclass clipFeatures = arcpy.GetParameterAsText(1) # Set the output workspace outWorkspace = arcpy.GetParameterAsText(2) # Set the XY tolerance clusterTolerance = arcpy.GetParameterAsText(3) try: # Get a list of the featureclasses in the input folder fcs = arcpy.ListFeatureClasses() for fc in fcs: # Validate the new feature class name for the output workspace. featureClassName = arcpy.ValidateTableName(fc, outWorkspace) outFeatureClass = os.path.join(outWorkspace, featureClassName) # Clip each feature class in the list with the clip feature class. # Do not clip the clipFeatures, it may be in the same workspace. if fc != os.path.basename(clipFeatures): arcpy.Clip_analysis(fc, clipFeatures, outFeatureClass, clusterTolerance) except Exception as err: arcpy.AddError(err) print err
该脚本将采用以下四个参数,以便实现通用:
用来定义待处理的那组要素类的输入工作空间
通过裁剪工具对输入要素类进行裁剪的区域的要素类
写入裁剪工具结果的输出工作空间
裁剪工具使用的 XY 容差
ValidateTableName() 函数用于确保输出名称对输出空间有效;os.path.basename()方法用于获取处理裁剪要素类的名称(不包含路径)。
本文出自 “IT技术学习与交流” 博客,谢绝转载!