2014-06-05 4 views
1

저는 ArcMap (10.1)에서 실행되는 스크립트를 작성하기 위해 Python을 사용하는 방법을 배우고 있습니다. 아래 코드는 사용자가 쉐이프 파일이 위치한 폴더를 선택한 다음 쉐이프 파일을 통해 "landuse"로 시작하는 쉐이프 파일 만의 값 테이블을 만듭니다.Python에서 값 테이블 (ArcPy)에 행을 추가하려면 어떻게합니까?

값이 인수에서 선택되고 폴더를 코드에 직접 넣을 수 없기 때문에 값 테이블에 행을 추가하는 방법을 잘 모르겠습니다. for 루프에서

#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(??) 

답변

2

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 
: 여기

는 분명히 도움이 될 수 있습니다 예입니다