2

I have always used tab-delimited text files to bring Excel data into QGIS. By default, these are saved by Excel with the suffix".txt". Mostly there is no problem opening these and I have hundreds spread across different projects, many with complex filters. Every so often, however, a project will open with errors on all or some of these. They are marked as bad layers even though nothing has changed - and I can create another project and open them perfectly well.

In comparing the description string in layer properties or the data source in the "Handle Unavailable Layers" dialogue box, the successful ones say "delimiter=%5Ct" (I have no idea why) while the ones marked as bad layers say "delimiter=/t". The browse function in handle bad layers doesn't do anything with these, and I cannot correct using repair data source or the Change Data Source plugin, because neither will recognize a ".txt" file as a valid input.

I can force all the bad layers to work correctly by manually editing the string to say "delimiter=%5Ct". I can then successfully query, display and interrogate them for the duration of the session. However, when I save the project and re-open it, the problematic part of the string has changed back to "delimiter=/t" on all the layers I corrected, and so these fail again to open properly.

Is there a work-around here except renaming all my text files as ".csv" files or re-exporting then as comma-delimited ".csv" files? I'm using 3.24.1 on Windows 10.

EDIT (1 April but not April fools): This is not so much an answer but a work-around. If I open a second copy of the delimited file and fully specify file format - "custom delimiter" and "tab" (which seems intuitive and is what I regularly do) then the file opens in the first session but reports as a bad layer in all subsequent sessions.

HOWEVER, if I open it as a delimited file after unchecking the "tab" delimited or even specifically turning off "custom delimiters", then it not only correctly recognizes the tabs and loads the file, but also loads those files without errors in subsequent sessions. A bug perhaps?

EDIT 2 On 4 July 22. @grandebooz seems to be on the right track but it is still only half the problem. My solution described in the first edit has been working without error for the last few weeks. However, I upgraded to 3.26.0 and yesterday saved the project in that format for the first time. On next opening, EVERY one of the problem files gave the error on opening. I edited the source to place "file:" in front of the string as suggested, and every one promptly opened without error. However, even after re-saving, every one continues to give an opening error, which can be resolved by editing the source as described.

EDIT 3 The Plugin mentioned in the Github link below resolves the issue at least in a temporary sense.

2
  • I guess the real problem is not the delimiter, which appears mixed as '/t' or '%5Ct' that always means <TAB>, but the missing 'file:' keyword after 'source=' before the network path. Why it do so ? I really dont know.
    – grandebooz
    Commented Jun 23, 2022 at 13:57
  • I also have updated QGIS from versieon 3.16 to 3.22 (LTR)/3.28. The updates show the same problem concerning uploading .txt/.csv files. I think that the presence of keyword "file" is not the problem. I have tried with QGis both locally as on a network. At both cases the keyword and the whole path is present. At both cases the .txt or .csv are not loaded, see below. ![enter image description here](i.sstatic.net/XVdbo.png)
    – Ahmed
    Commented Oct 31, 2022 at 10:00

1 Answer 1

1

Please note there is a thread on QGIS GitHub issues now.

It seems to me my similar problem/bug opening delimited text files was gone after moving the data files to a local drive like D:\data. The layer (resp. the original data file) loaded from a network drive was invalid every time I load the project again. The problem appeared after I updated from LTR 3.16 to 3.22.6 (Windows 10).

I left the project file on a network drive and moved the data files to a local drive. I have simple data (points) but they are constantly updated with a text editor. For the workaround ("local drive"), I had to import the data files that were previously moved to D:\data for the layer once and save the project file.

I tested the workaround with different delimiters too (see file names below).

# --------------------
# using mixed delimiters
# --------------------
id latitude longitude
5746 49.906009;6.540942
5747 49.888455 6.544912
5748 49.870383;6.544483
  • QGIS 3.22.7 (mixed delimiters: blank, tab, semicolon) source network drive -NOT working source="./data/layer-by-delimited-text-delimiters-mixed.txt?type=csv&amp;delimiter= \t;&amp;

  • QGIS 3.22.7 (mixed delimiters: blank, tab, semicolon) source local drive - working source="file:///D:/data/layer-by-delimited-text-delimiters-mixed.txt?type=csv&amp;delimiter=%20%5Ct;&amp;

  • QGIS 3.22.7 (delimiter tab only) source network drive - NOT working source="./data/layer-by-delimited-text-delimiters-tab-only.txt?type=csv&amp;delimiter=\t&amp;

  • QGIS 3.22.7 (delimiter tab only) source local drive - working source="file:///D:/data/layer-by-delimited-text-delimiters-tab-only.txt?type=csv&amp;delimiter=%5Ct&amp;

Your Answer

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

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