2016-04-15 6 views
0

私はPythonの初心者です。 arcpy.GetParameterAsText関数を使用して、「ソースフォルダ」と「ジオデータベース」をArcGISツールボックスの入力パラメータにすることを試みています。ArcGIS/Pythonで入力パラメータを作成するにはどうすればよいですか?

私は2つのarcpy.GetParameterAsText機能をどこに置くべきかについて本当に分かりません。私はそれにワークスペースを設定したいですか?もし私がそれを行うならば、GDBファイルを作成する方法がわからなくても、その前のパスはありません。

# Set the workspace 
arcpy.env.workspace = "C:\\Users\\x\\Desktop\\Python_Scripting\\4\\Lesson4_Data\\Lesson4_Data" 

#Create the GDB 
arcpy.CreateFileGDB_management("C:\\Users\\x\\Desktop\\Python_Scripting\\4\\Lesson4_Data\\Lesson4_Data","lesson4a.gdb") 

# Set the feature class variables 
fclist = arcpy.ListFeatureClasses("","polygon") 
fctotal = arcpy.ListFeatureClasses() 

# Start the loop on all feature classes 
for fc in fclist: 
    fcdesc = arcpy.Describe(fc) 
    print fcdesc.basename + " is currently importing into the lesson4a.gdb." 
    arcpy.CopyFeatures_management (fc, "C:\\Users\\x\\Desktop\\Python_Scripting\\4\\Lesson4_Data\\Lesson4_Data\\lesson4a.gdb\\" + fcdesc.basename) 
    print fcdesc.basename + " is done importing into the lesson4a.gdb.\n" 

答えて

0

arcpy.GetParameterAsText(#)関数は、ArcGISツールから入力パラメータを読み取ります。

スクリプトとデバッグ中に、関数の入力変数をハードコードして、関数が機能していることを確認するのが最も簡単です。ツールが(本質的に)望むようになったら、ArcMap内にツールボックスとスクリプトツールを作成します。

ツール実行ダイアログから入力パラメータを受け入れるには、スクリプトツールを作成するときにを作成して(GetParameterAsText入力を受け入れるようにコードを変更する)必要があります。このための最善のウォークスルーは、実際にはArcGISのリソースセンターです。 Pythonスクリプト内

  • Setting script tool parameters
  • Adding a script tool
    • が、私は一般的に 入力パラメータ最初読んで - そのように、彼らはスクリプトのすべての残りの変数として利用可能です。インデックス値は、どのパラメータがどちらであるかを示します。

      # Input parameters 
      sourceFolder = arcpy.GetParameterAsText(0)  # first input parameter of script tool 
      geodatabaseName = arcpy.GetParameterAsText(1)  # second input parameter 
      
      # Set the workspace 
      arcpy.env.workspace = sourceFolder 
      
      #Create the GDB 
      arcpy.CreateFileGDB_management(sourceFolder, geodatabaseName) 
      
    関連する問題