Skip to main content
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
naming; removed please
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

How to batch Batch import .xyz files in Qgis?QGIS

I have about 200 .xyz files I want to import into my QgisQGIS project. I've tried using this answer https://gis.stackexchange.com/a/310415 but haven't been able to make it work. I'm getting this exec(Path('C:/Users/AppData/Local/Temp/tmp8k1lnjji.py').read_text()) as an output and no error messages so it seems like QgisQGIS is reading my files but not doing anything with them? To be honest I have no idea what I'm doing with the pythonPython console so please tell me what I'm. What am I doing wrong?

thisThis is the adjusted code I'm using:

import os.path, glob
from qgis.core import QgsProject, QgsVectorLayer
layers=[]
for file in glob.glob('D:/Documents/Uni/Master/Masterarbeit/Daten/2014/100*.xyz'): # Change this base path
  uri = "file:///" + file + "?delimiter=%s&xField=%s&yField=%s&useHeader=no&crs=epsg:31467" % (" ", "field_1","field_2")
  vlayer = QgsVectorLayer(uri, os.path.basename(file), "delimitedtext")
  vlayer.setFieldAlias(0,'X')
  vlayer.setFieldAlias(1,'Y')
  vlayer.setFieldAlias(2,'Z')
  layers.append(vlayer)

QgsProject.instance().addMapLayers(layers)

I'm on Windows 10 with QgisQGIS version 3.28.5. This

This is what the data looks like:

3465888.000 5910084.000 -10.431
3465888.000 5910086.000 -10.399
3465888.000 5910088.000 -10.421
3465888.000 5910090.000 -10.473
3465888.000 5910092.000 -10.536

How to batch import .xyz files in Qgis?

I have about 200 .xyz files I want to import into my Qgis project. I've tried using this answer https://gis.stackexchange.com/a/310415 but haven't been able to make it work. I'm getting this exec(Path('C:/Users/AppData/Local/Temp/tmp8k1lnjji.py').read_text()) as an output and no error messages so it seems like Qgis is reading my files but not doing anything with them? To be honest I have no idea what I'm doing with the python console so please tell me what I'm doing wrong

this is the adjusted code I'm using

import os.path, glob
from qgis.core import QgsProject, QgsVectorLayer
layers=[]
for file in glob.glob('D:/Documents/Uni/Master/Masterarbeit/Daten/2014/100*.xyz'): # Change this base path
  uri = "file:///" + file + "?delimiter=%s&xField=%s&yField=%s&useHeader=no&crs=epsg:31467" % (" ", "field_1","field_2")
  vlayer = QgsVectorLayer(uri, os.path.basename(file), "delimitedtext")
  vlayer.setFieldAlias(0,'X')
  vlayer.setFieldAlias(1,'Y')
  vlayer.setFieldAlias(2,'Z')
  layers.append(vlayer)

QgsProject.instance().addMapLayers(layers)

I'm on Windows 10 with Qgis version 3.28.5. This is what the data looks like:

3465888.000 5910084.000 -10.431
3465888.000 5910086.000 -10.399
3465888.000 5910088.000 -10.421
3465888.000 5910090.000 -10.473
3465888.000 5910092.000 -10.536

Batch import .xyz files in QGIS

I have about 200 .xyz files I want to import into my QGIS project. I've tried using this answer https://gis.stackexchange.com/a/310415 but haven't been able to make it work. I'm getting this exec(Path('C:/Users/AppData/Local/Temp/tmp8k1lnjji.py').read_text()) as an output and no error messages so it seems like QGIS is reading my files but not doing anything with them? To be honest I have no idea what I'm doing with the Python console. What am I doing wrong?

This is the adjusted code I'm using:

import os.path, glob
from qgis.core import QgsProject, QgsVectorLayer
layers=[]
for file in glob.glob('D:/Documents/Uni/Master/Masterarbeit/Daten/2014/100*.xyz'): # Change this base path
  uri = "file:///" + file + "?delimiter=%s&xField=%s&yField=%s&useHeader=no&crs=epsg:31467" % (" ", "field_1","field_2")
  vlayer = QgsVectorLayer(uri, os.path.basename(file), "delimitedtext")
  vlayer.setFieldAlias(0,'X')
  vlayer.setFieldAlias(1,'Y')
  vlayer.setFieldAlias(2,'Z')
  layers.append(vlayer)

QgsProject.instance().addMapLayers(layers)

I'm on Windows 10 with QGIS version 3.28.5.

This is what the data looks like:

3465888.000 5910084.000 -10.431
3465888.000 5910086.000 -10.399
3465888.000 5910088.000 -10.421
3465888.000 5910090.000 -10.473
3465888.000 5910092.000 -10.536
Source Link

How to batch import .xyz files in Qgis?

I have about 200 .xyz files I want to import into my Qgis project. I've tried using this answer https://gis.stackexchange.com/a/310415 but haven't been able to make it work. I'm getting this exec(Path('C:/Users/AppData/Local/Temp/tmp8k1lnjji.py').read_text()) as an output and no error messages so it seems like Qgis is reading my files but not doing anything with them? To be honest I have no idea what I'm doing with the python console so please tell me what I'm doing wrong

this is the adjusted code I'm using

import os.path, glob
from qgis.core import QgsProject, QgsVectorLayer
layers=[]
for file in glob.glob('D:/Documents/Uni/Master/Masterarbeit/Daten/2014/100*.xyz'): # Change this base path
  uri = "file:///" + file + "?delimiter=%s&xField=%s&yField=%s&useHeader=no&crs=epsg:31467" % (" ", "field_1","field_2")
  vlayer = QgsVectorLayer(uri, os.path.basename(file), "delimitedtext")
  vlayer.setFieldAlias(0,'X')
  vlayer.setFieldAlias(1,'Y')
  vlayer.setFieldAlias(2,'Z')
  layers.append(vlayer)

QgsProject.instance().addMapLayers(layers)

I'm on Windows 10 with Qgis version 3.28.5. This is what the data looks like:

3465888.000 5910084.000 -10.431
3465888.000 5910086.000 -10.399
3465888.000 5910088.000 -10.421
3465888.000 5910090.000 -10.473
3465888.000 5910092.000 -10.536