2

I have a CSV file with no headers like this

FOO:ObjList(EPSG:25832)
640410.2620,5493340.3749,23/2024#566.520,00##
640406.4920,5493342.0019,23/2024#566.520,00##
640391.6548,5493327.6581,23/2024#566.520,00##
640361.2631,5493323.8864,23/2024#566.520,00##
640248.2900,5493307.3972,23/2024#566.520,00##
640425.2456,5493346.9037,23/2024#566.520,00##

Following the advice found on https://qgis.org/pyqgis/master/core/QgsVectorLayer.html section Delimited text file data provider (delimitedtext) under xField=column yField=column where it says

"...xField=column yField=column

Defines the name of the columns holding the x and y coordinates for XY point geometries. If the useHeader is no (ie there are no column names), then this is the column number (with the first column as 1)."

I try to read this with PyQGIS with the following code

>>> uri = r'file:///c:\tmp\RJFGRK11.tmp?delimiter=,&skipLines=1&xField=1&yField=2&geomType=point&useHeader=no'
>>> lyr = QgsVectorLayer(uri, 'Test', 'delimitedtext')
>>> lyr.isValid()
False

In the protocol under delimitedText I find

[...]
2024-05-03T09:07:16     WARNING    Fehler in Datei c:\tmp\RJFGRK11.tmp
2024-05-03T09:07:16     WARNING    X Feld 1 ist nicht in der Datei definiert
2024-05-03T09:07:16     WARNING    Y Feld 2 ist nicht in der Datei definiert

So what am I missing?

1 Answer 1

3

Your xField=1&yField2 definition is wrong it should be xField=field_1&yField=field_2. I think the docs are outdate. Should be:

"Defines the name of the columns holding the x and y coordinates for XY point geometries. If the useHeader is no (ie there are no column names), then this is the column number (with the first column as field_1)."

Not the answer you're looking for? Browse other questions tagged or ask your own question.