1

Python を使用して、ArcMap (10.1) で実行されるスクリプトを作成する方法を学んでいます。以下のコードでは、シェープファイルが配置されているフォルダーをユーザーが選択し、シェープファイルを調べて、「landuse」で始まるシェープファイルのみの値テーブルを作成します。

値が引数で選択されており、フォルダーをコードに直接配置できないため、値テーブルに行を追加する方法がわかりません。以下のコードを参照してください...

#imports
import sys, os, arcpy 

#arguments
arcpy.env.workspace = sys.argv[1] #workspace where shapefiles are located

#populate a list of feature classes that are in the workspace
fcs = arcpy.ListFeatureClasses()

#create an ArcGIS desktop ValueTable to hold names of all input shapefiles
#one column to hold feature names
vtab = arcpy.ValueTable(1)

#create for loop to check for each feature class in feature class list
for fc in fcs:
    #check the first 7 characters of feature class name == landuse
    first7 = str(fc[:7])
    if first7 == "landuse":
        vtab.addRow() #****THIS LINE**** vtab.addRow(??)
4

1 に答える 1

2

forループではfc、リスト内の各フィーチャ クラスの文字列としての名前になりますfcs。したがって、メソッドを使用するときは、引数としてaddRow渡します。fc

明確にするのに役立つ例を次に示します。

# generic feature class list
feature_classes = ['landuse_a', 'landuse_b', 'misc_fc']

# create a value table
value_table = arcpy.ValueTable(1)

for feature in feature_classes:       # iterate over feature class list
    if feature.startswith('landuse'): # if feature starts with 'landuse'
        value_table.addRow(feature)   # add it to the value table as a row

print(value_table)

>>> landuse_a;landuse_b
于 2014-06-05T18:11:23.943 に答える