Original ArcMap custom Scripting tool Authoring
In the early stages of cartography, the general need to do some data collation, layer merging, cutting and other work. While there are tools available in ArcMap, it takes a bit of skill to use them. such as batch cropping, although it can be achieved, but the results will be renamed to [layer name]_clip, so for the configuration of the entire area of MXD, it is very unfriendly to cut part of the range of data separately, for the follow-up work means the need to separate the cropped data to rename, remove the suffix _ Clip can only set the data source uniformly.
To solve this problem can be very quickly write a Python script to achieve. But the script for the average person is more troublesome, each use needs to adjust the script parameters, error-prone. ArcGIS allows you to import scripts into a tool so that you can work with your data in the same way as regular tools in the ArcMap interface.
This is an example of preserving the layer's original name and deleting the layer with empty data in bulk cropping. The code is as follows:
#coding =GBK
#这个工具是使用一个图层去裁剪指定数据库或文件夹的数据 and delete the cropped, empty layer
Clipfeats = arcpy. Getparameterastext (0) #用于裁剪的图层
inputwork=arcpy. Getparameterastext (1) #输入的要裁剪的数据
Workpath = arcpy. Getparameterastext (2) #裁剪后输出的位置
Arcpy.env.workspace = Inputwork
Featureclasses = arcpy. Listfeatureclasses ()
For FC in Featureclasses:
outfeat = workpath+u "\ \" +FC
Arcpy.analysis.Clip (FC, Clipfeats,outfeat) #裁剪数据并输出
#检查是否有空的要素, if it is empty, delete the data
Arcpy.env.workspace = Workpath
Featureclasses = arcpy. Listfeatureclasses ()
For FC in Featureclasses:
desc = arcpy. Describe (FC)
result=arcpy. Getcount_management (FC)
me = result.getoutput (0)
if int (me) ==0:
arcpy. Delete_management (FC)
The authoring tool is very simple, as long as the parameters are set up, which is the preceding few lines of arcpy. Getparameterastext (0)
The index number that follows is very important, and it determines the position of the parameter in the tool.
First create a new toolbox, add a script in the Toolbox
Make some necessary description of the script, as shown in
Select the corresponding script that is written well
Next is the most important parameter setting, where the order of the parameters is maintained in the order in which the parameters in the preceding code are obtained.
The display name is the display description of the tool call, the data type must correspond to the parameter, for example, the data to be cropped is a featureclass, it can be set to a feature class or a layer, and the other two parameters are all points to the input path or the output path, can be set to "Workspace or feature DataSet"
Such as
Once you are done, you can simply double-click the Script tool to execute.
By arcpy a few lines of code, and implement a custom advanced cropping function, with some regular scripts, the alignment of input and output parameters for a separate rewrite, set as a script tool, you can achieve more fast and friendly operation.
ArcMap Custom Scripting Tool Authoring