I found a script for loading several csv files into QGIS and modified it for .xyz Data. Yesterday on one Computer it worked and today on a different Computer it's not working anymore.
Is there something wrong with the code?
I tried to use the following code in the python console
import glob, os
path = "C:\Users\J\Desktop\xyz_data"
os.chdir(path)
for file in glob.glob("*.xyz"):
uri = "file:///" + path + file + "?delimiter=%s&crs=epsg:4647&xField=%s&yField=%s" % (" ", "field_1", "field_2")
name = file.replace('.xyz', '')
lyr = QgsVectorLayer(uri, name, 'delimitedtext')
QgsMapLayerRegistry.instance().addMapLayer(lyr)
After the "path" line I get the following error message:
Traceback (most recent call last): File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\code.py", line 63, in runsource code = self.compile(source, filename, symbol) File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\codeop.py", line 168, in call return _maybe_compile(self.compiler, source, filename, symbol) File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\codeop.py", line 99, in _maybe_compile raise err1 File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\codeop.py", line 87, in _maybe_compile code1 = compiler(source + "\n", filename, symbol) File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\codeop.py", line 133, in call codeob = compile(source, filename, symbol, self.flags, 1) File "", line 1 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape os.chdir(path) Traceback (most recent call last): File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in NameError: name 'path' is not defined
When I enter the last line of the Code into the python console nothing happens. No layers are uploaded and I don't get error Messages.