0

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Apr 29, 2020 at 3:59
2
  • 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. Commented Apr 29, 2020 at 4:15
  • 1
    AddAttributeAlias has been renamed. Extract from the QGIS API documentation: "Renamed addAttributeAlias() to setFieldAlias()" (see: qgis.org/api/api_break.html). Commented Apr 29, 2020 at 5:25

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.