3

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月03日T09:07:16 WARNING Fehler in Datei c:\tmp\RJFGRK11.tmp
2024年05月03日T09:07:16 WARNING X Feld 1 ist nicht in der Datei definiert
2024年05月03日T09:07:16 WARNING Y Feld 2 ist nicht in der Datei definiert

So what am I missing?

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked May 3, 2024 at 7:27

1 Answer 1

4

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)."

answered May 3, 2024 at 7:48

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.