Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File path encoding in "delimitedtext"-Provider #19572

Closed
qgib opened this issue Sep 26, 2014 · 8 comments
Closed

File path encoding in "delimitedtext"-Provider #19572

qgib opened this issue Sep 26, 2014 · 8 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers

Comments

@qgib
Copy link
Contributor

qgib commented Sep 26, 2014

Author Name: l h_ (l h_)
Original Redmine Issue: 11274
Affected QGIS version: 2.4.0
Redmine category:data_provider/delimited_text_


Hello,

I have a problem with the path encoding of the "delimitedtext"-Provider - as soon as the file path has a special character the following error-message occurs:

"File cannot be opened or delimiter parameters are not valid"

Here is the code:

@uri = u"file:/" + unicode(fileName) + u"?delimiter={0}&xField={1}&yField={2}&crs=epsg:4326&spatialIndex=yes".format(",", "longitude", "latitude")

self.__csvLayer = QgsVectorLayer(uri, "my_csv_layer", "delimitedtext")@

@qgib
Copy link
Contributor Author

qgib commented Oct 3, 2014

Author Name: Alexander Bruy (@alexbruy)


Please be more specific, which "special" characters? Does it also failed when you load this file via QGIS GUI?


  • category_id was configured as Data Provider/Delimited Text
  • status_id was changed from Open to Feedback

@qgib
Copy link
Contributor Author

qgib commented Feb 4, 2015

Author Name: l h_ (l h_)


Special character could be an ä - any non english letter...

@qgib
Copy link
Contributor Author

qgib commented Feb 5, 2015

Author Name: l h_ (l h_)


It doesn't fail in the GUI... I think the URI-Constructor of the QgsVectorlayer isn't used there. Our plugin is also written in Python, maybe the problem is there?

@qgib
Copy link
Contributor Author

qgib commented Feb 5, 2015

Author Name: Giovanni Manghi (@gioman)


  • status_id was changed from Feedback to Open

@qgib
Copy link
Contributor Author

qgib commented Feb 5, 2015

Author Name: Minoru Akagi (@minorua)


You need to convert unicode characters to ascii (URL encoding).

from PyQt4.QtCore import QUrl

filename = u"D:\\\\テスト.csv"
url = QUrl.fromLocalFile(filename)
url.setQueryItems([["delimter", ","], ["key2", "value2"]])

url.toEncoded()    # -> PyQt4.QtCore.QByteArray('file:///E:/%E3%83%86%E3%82%B9%E3%83%88.csv?delimter=,&key2=value2')

layer = QgsVectorLayer(unicode(url.toEncoded()), "layername", "delimitedtext")

@qgib
Copy link
Contributor Author

qgib commented Feb 6, 2015

Author Name: Minoru Akagi (@minorua)


last comment has been modified.

wrong: @url.toString()@
right: @unicode(url.toEncoded())@

@qgib
Copy link
Contributor Author

qgib commented Jan 20, 2016

Author Name: Alexander Bruy (@alexbruy)


This is not a QGIS bug, plugin should take care about handling non-ASCII characters. Please reopen if necessary


  • status_id was changed from Open to Closed
  • resolution was changed from to fixed/implemented

@qgib
Copy link
Contributor Author

qgib commented Jan 20, 2016

Author Name: Alexander Bruy (@alexbruy)


  • resolution was changed from fixed/implemented to wontfix

@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers labels May 25, 2019
@qgib qgib closed this as completed May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers
Projects
None yet
Development

No branches or pull requests

1 participant