답변:
커서를 사용하여 테이블에서 데이터를 가져와 쉼표로 구분 된 텍스트 파일에 쓸 수 있습니다.
편집 : csv
파이썬 모듈을 사용하여 작업을 수행하기 위해보다 간결한 코드 블록을 추가하고 있습니다
arcpy.da 커서를 사용한 새로운 답변 :
import arcpy,csv
table =r'c:\path\to\table'
outfile = r'c:\path\to\output\ascii\text\file'
#--first lets make a list of all of the fields in the table
fields = arcpy.ListFields(table)
field_names = [field.name for field in fields]
with open(outfile,'wb') as f:
dw = csv.DictWriter(f,field_names)
#--write all field names to the output file
dw.writeheader()
#--now we make the search cursor that will iterate through the rows of the table
with arcpy.da.SearchCursor(table,field_names) as cursor:
for row in cursor:
dw.writerow(dict(zip(field_names,row)))
구식 커서를 사용한 새로운 답변 :
import arcpy,csv
table =r'c:\path\to\table'
outfile = r'c:\path\to\output\ascii\text\file'
#--first lets make a list of all of the fields in the table
fields = arcpy.ListFields(table)
field_names = [field.name for field in fields]
with open(outfile,'wb') as f:
w = csv.writer(f)
#--write all field names to the output file
w.writerow(field_names)
#--now we make the search cursor that will iterate through the rows of the table
for row in arcpy.SearchCursor(table):
field_vals = [row.getValue(field.name) for field in fields]
w.writerow(field_vals)
del row
이전 답변 :
import arcpy
table =r'c:\path\to\table'
outfile = r'c:\path\to\output\ascii\text\file'
#--first lets make a list of all of the fields in the table
fields = arcpy.ListFields(table)
i = 1
f = open(outfile,'w')
for field in fields:
#--write all field names to the output file
if i < len(fields):
f.write('%s,' % field.name)
i += 1
else:
f.write('%s\n' % field.name)
#--now we make the search cursor that will iterate through the rows of the table
rows = arcpy.SearchCursor(table)
for row in rows:
i = 1
for field in fields:
if i < len(fields):
f.write('%s,' % row.getValue(field.name))
i += 1
else:
f.write('%s\n' % row.getValue(field.name))
del rows
f.close()
with arcpy.da.SearchCursor(table) as cursor:
이어야합니다with arcpy.da.SearchCursor(table, field_names) as cursor:
"피처 속성 속성을 ASCII로 내보내기"를 원한다면 arcpy로 이름을 지정할 수 있습니다 .ExportXYv_stats
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005p0000003v000000
import arcpy
feature = "path to feature here"
# fieldnames must be explicitly provided. Note that you will get additional fields based on the feature type (e.g., "XCoord" and "YCoord" for point features)
fieldnames = [X.name for X in arcpy.ListFields(feature)]
# delimiter options "SPACE", "COMMA", or "SEMI-COLON"
# header options "ADD_FIELD_NAMES" or "NO_FIELD_NAMES"
arcpy.ExportXYv_stats(feature, fieldnames, "SPACE", "path to outfile", "ADD_FIELD_NAMES")
여기 내가 사용하는 코드가 있습니다. 0,100 범위의 모든 출력 파일을 .txt 파일로 생성하는 데 도움이됩니다. 잘하면 그것은 도움이됩니다
for x in xrange(0,100):
if os.path.isfile(outfolder + "/" + "outputs" + str(x) +".shp" ):
inFeatures = "selected_features" + str(x) +".shp"
export_ASCII = "ASCII " + str(x) +".txt"
arcpy.ExportXYv_stats(inFeatures, ["Cur1_pr2","Cur3_pl1","slp1"],"SPACE", export_ASCII,"ADD_FIELD_NAMES")