2016-04-18 68 views
0

我想創建自己的工具以在ArcMap中使用,但仍然遇到問題。我想創建一個緩衝區(我可以這樣做),然後剪切落在緩衝區中的點。我遇到的問題是我無法弄清楚如何使用緩衝區作爲我的工具的剪輯部分的輸入功能。在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') 

[Here is a picture of my tool in ArcMap] 1

回答

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' 

類似的策略可以用於,你真的不關心任何中間要素類或表。但是,有時可以使用這些中間結果來驗證您的工具是否按照您期望的每一步執行。

+0

謝謝, 這有助於解決我的問題 –