3

Probably OS specific, I see this issue while using QGIS 2.14.11 and 2.18.3 versions on Windows64 platform.

When I import a vector to QGIS by Layer | Add Layer | Add Vector Layer the layer source writes backslash in its path. Can I fix this to forward slash?

[EDIT] This includes "Can I avoid backslash when I load vector files?"

enter image description here

These vector layers with backslash work fine usually, but it becomes troublesome if I try to read the layer from R script. For instance if I try to read a layer of .csv file (without geometry) from a Processing rsx script by ##Layer=table it returns an error Error 'u' used without hex digits in character string.

8
  • I confirm the issue, but the same doesn't happen if you drag&drop the file in the canvas for importing it (in this case, I see the forward slashes). However, I don't understand how your second issue should be related to the first one if you are using a script.
    – mgri
    Commented Feb 12, 2017 at 20:56
  • @mgri thanks, it is interesting importing by drag&drop gives forward slashes. And sorry I was not clear about the issue. I have trouble reading the layer (after loading) from Processing Toolbox - R script. Edited my post to try to clarify the issue.
    – Kazuhito
    Commented Feb 12, 2017 at 22:28
  • I'm unfamiliar with r scripts, but can you give me an example of the filepath directly printed by the script? Is it something like C:\GIS\temp\1.csv or C:\\GIS\\temp\\1.csv? I think it should be sufficient using something like print Layer.
    – mgri
    Commented Feb 12, 2017 at 22:38
  • @mgri Unfortunately rsx scripts in processing does not have filepath in itself (you are correct about r scripts, that the filepath is set by user). Processing rsx scripts with ##Layer= headerline reads layer as input and if it is set ##Layer=table it try to read .csv table (in the Layers Panel) into the script by read.csv() function.
    – Kazuhito
    Commented Feb 12, 2017 at 22:48
  • 1
    @mgri Many thanks! I will try to follow that lead. BTW, will you post your comments as answer? I confirm it works. I should have included "to avoid backslash" as solution to my issue, equal to "to fix".
    – Kazuhito
    Commented Feb 12, 2017 at 23:54

1 Answer 1

2

I confirm the issue, but the same doesn't happen if you drag&drop the file in the canvas for importing it (in this case, I see the forward slashes).

I'm unfamiliar with R scripts, but I think there would be a way to directly retrieve the filepath instead of loading the layer in the Layers Panel before running the script (I mean, something similar to QgsVectorLayer() for PyQGIS): after a simple search, this thread could be useful for retrieving the filepath?

If you have success, or as an additional hint, you may also include a check on the filepath, for example:

filepath = 'C:\\GIS\\temp\\1.csv'
if '\\' in filepath:
    newpath = filepath.replace("\\", "/")
print newpath
2
  • 1
    Thanks! It works. I will try to follow the suggested lead, but the tip to avoid backslash is sufficient for me at the moment. If I can add, loading a vector file from Browser Panel is another way to avoid backslash. (I found it after your "drag&drop" suggestion.)
    – Kazuhito
    Commented Feb 13, 2017 at 8:41
  • I'm glad this workaround worked! it's been so long time since I uploaded something from Layer | Add Layer | Add Vector Layer =)
    – mgri
    Commented Feb 13, 2017 at 8:44

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.