def get_rows(data_set, fields): with da.SearchCursor(data_set, fields) as cursor: for row in cursor: yield row if __name__ == "__main__": data_set = arcpy.GetParameterAsText(0) # feature class/Table output = arcpy.GetParameterAsText(1) # csv file desc = arcpy.Describe(data_set) fieldnames = [f.name for f in desc.fields if f.type not in ["Geometry", "Raster", "Blob"]] rows = get_rows(data_set, fieldnames) with open(output,'wb') as out_file: out_writer = csv.writer(out_file) out_writer.writerow(fieldnames) for row in rows: out_writer.writerow(row)
import arcpy from os import path as p def TableToCSV(fc,CSVFile): fields = [f.name for f in arcpy.ListFields(fc) if f.type <> 'Geometry'] with open(CSVFile, 'w') as f: f.write(','.join(fields)+'\n') #csv headers with arcpy.da.SearchCursor(fc, fields) as cursor: for row in cursor: f.write(','.join([str(r) for r in row])+'\n') print 'Created %s Successfully' %p.basename(CSVFile)
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.