我正在尝试创建自己的工具以在ArcMap中使用但仍然遇到问题。我想创建一个缓冲区(我可以做)然后剪切缓冲区内的点。我遇到的问题是我无法弄清楚如何使用缓冲区作为我工具的剪辑部分的输入功能。
import arcpy
import os
from arcpyimmport env
env.workspace = "C:/LabData"
arcpy.env.overwriteOutput = True
In_lake = arcpy.GetParameterAsText(0)
Out_Buff = arcpy.GetParameterAsText(1)
Buffer_Distance = arcpy.GetParameterAstext(2)
in_cities = arcpy.GetParameterAsText(3)
cliped_cities = GetParameterAsText(4)
New_Table = arcpy.GetParameterAsText(5)
Join_Input = arcpy.GetParameteAsText(6)
# step 1 create a buffer around the lakes
arcpy.Buffer_analysis(In_Lake, Out_Buff, Buffer_Distance)
# Step 2 Clip all cities that fall within the buffer
arcpy.Clip_analysis( in_cities,out_Buff, clipped_cities)
# Step 3
arcpy.Statistics_analysis(clipped_cities, New_Table, statistics_fields,\
'Population SUM', 'CNTRY_NAME')
# Step 5
arcpy.AddField_management (New_Table, 'Country', 'TEXT')
] 1
答案 0 :(得分:0)
请仔细检查您的变量名称是否匹配--Python和ArcPy区分大小写。
In_Lake = arcpy.GetParameterAsText(0) ## was In_lake
Out_Buff = arcpy.GetParameterAsText(1)
Buffer_Distance = arcpy.GetParameterAstext(2)
in_cities = arcpy.GetParameterAsText(3)
clipped_cities = GetParameterAsText(4) ## was cliped_cities
New_Table = arcpy.GetParameterAsText(5)
Join_Input = arcpy.GetParameteAsText(6)
# step 1 create a buffer around the lakes
arcpy.Buffer_analysis(In_Lake, Out_Buff, Buffer_Distance)
# Step 2 Clip all cities that fall within the buffer
arcpy.Clip_analysis(in_cities, Out_Buff, clipped_cities) ## was out_Buff
除非您想保留湖泊缓冲区,否则它不一定需要是用户指定的输入参数。请考虑使用the in_memory workspace - 请注意,一旦工具执行完毕,其中的任何数据都将被删除。
Out_Buff = r'in_memory\lakeBuffer'
类似的策略可用于任何中间要素类或表,而您并不真正关心。但是,有时候让这些中间结果验证您的工具是否正在按照您的预期执行每一步都是有用的。