Currently I am writing a plugin which allows the user to quickly import a .txt file as a point layer in qgis. The .txt file is output data from a gps device and does not contain a header row. However, I was wondering if it is possible to add headers to the file while importing it as a point layer. Because the .txt structure is always the same, I always know which name a column should have.
Right now I am using addAttributeAlias
but this is not satisfying as it only gives an alias to the columns.
Currently I am using the code below for importing the txt file. Is it possible somehow add a line of code in here which allows me add headers for all the columns?
txt_path = self.dlg.lineEdit_txt.text()
txt_info = "?crs=epsg:" + str(crs_rd_new) \
+ "&type=csv&useHeader=No&xField=field_2&yField=field_3&spatialIndex=no&subsetIndex=no&watchFile=no&=&=&=&="
txt_output_filename = os.path.splitext(os.path.basename(txt_path))[0]
txt_vl = QgsVectorLayer("file:///" + txt_path + txt_info, txt_output_filename + ".txt", 'delimitedtext')