Here is a sample of my source data.
682575.040,5769613.850,153.410,87
682575.990,5769611.700,153.470,91
682575.850,5769613.340,153.530,95
682580.120,5769612.860,153.480,88
682580.270,5769613.760,153.470,83
682579.430,5769615.690,153.400,90
682577.800,5769628.040,153.450,94
682580.510,5769622.020,153.440,93
682581.370,5769620.100,153.480,86
682582.430,5769617.740,153.530,95
And this is the script I am trying to use:
import os.path, glob
layers=[]
for file in glob.glob('D:/Projects/RPope/LLPG/Lidar/2007/ascii/test/*.txt'): # Change this base path
uri = "file:///" + file + "?delimiter=%s&xField=%s&yField=%s&useHeader=no&crs=epsg:28354" % (",", "xField","yField")
vlayer = QgsVectorLayer(uri, os.path.basename(file), "delimitedtext")
vlayer.addAttributeAlias(0,'X')
vlayer.addAttributeAlias(1,'Y')
vlayer.addAttributeAlias(2,'Z')
vlayer.addAttributeAlias(3,'code')
layers.append(vlayer)
Here is the Error message.
Traceback (most recent call last):
File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\code.py", line 90, in run-code
exec(code, self.locals)
File "<input>", line 4, in <module>
AttributeError: 'QgsVectorLayer' object has no attribute 'addAttributeAlias'
How do I make it work?
-
Related: gis.stackexchange.com/questions/166517/… it looks like the attributes are specified in the constructor rather than added later, give that a try and see if it works for you. The example though has a header row so I'm not exactly certain how to modify the layer to use enumerated columns rather than header specified field columns.Michael Stimson– Michael Stimson2020年04月29日 04:15:25 +00:00Commented Apr 29, 2020 at 4:15
-
1AddAttributeAlias has been renamed. Extract from the QGIS API documentation: "Renamed addAttributeAlias() to setFieldAlias()" (see: qgis.org/api/api_break.html).Zoltan– Zoltan2020年04月29日 05:25:08 +00:00Commented Apr 29, 2020 at 5:25