Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a shapefile, that I want to split with the "Split Layers by Field"-tool. Due to some umlauts (ä,ü,ö) there will be a python error as soon, as the tool reaches a feature with an umlaut. The following error message will appear:

*An error has occured while executing Python code: Traceback (most recent call last): File "C:/Users/Gidi/.qgis//python/plugins\layers_by_field\layers_by_field_dialog.py", line 58, in accept self.split( inLayer, inField ) File "C:/Users/Gidi/.qgis//python/plugins\layers_by_field\layers_by_field_dialog.py", line 146, in split self.vlayer = QgsVectorLayer(vProvider.dataSourceUri(), str(layer.name()) + "_" + str(uValues[j]), "ogr") UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 7: ordinal not in range(128) Python version: 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] QGIS version: 1.8.0-Lisboa Lisboa, 6416f38 Python path: ['C:/PROGRA~2/Quantum GIS Lisboa/apps/qgis/./python', 'C:/Users/Gidi/.qgis//python', 'C:/Users/Gidi/.qgis//python/plugins', 'C:/PROGRA~2/Quantum GIS Lisboa/apps/qgis/./python/plugins', 'C:\PROGRA~2\Quantum GIS Lisboa\bin\python27.zip', 'C:\PROGRA~2\Quantum GIS Lisboa\apps\Python27\DLLs', 'C:\PROGRA~2\Quantum GIS Lisboa\apps\Python27\lib', 'C:\PROGRA~2\Quantum GIS Lisboa\apps\Python27\lib\plat-win', 'C:\PROGRA~2\Quantum GIS Lisboa\apps\Python27\lib\lib-tk', 'C:\PROGRA~2\Quantum GIS Lisboa\apps\qgis\bin', 'C:\PROGRA~2\Quantum GIS Lisboa\apps\Python27', 'C:\PROGRA~2\Quantum GIS Lisboa\apps\Python27\lib\site-packages', 'C:\PROGRA~2\Quantum GIS Lisboa\apps\Python27\lib\site-packages\PIL', 'C:\PROGRA~2\Quantum GIS Lisboa\apps\Python27\lib\site-packages\win32', 'C:\PROGRA~2\Quantum GIS Lisboa\apps\Python27\lib\site-packages\win32\lib', 'C:\PROGRA~2\Quantum GIS Lisboa\apps\Python27\lib\site-packages\Pythonwin', 'C:\PROGRA~2\Quantum GIS Lisboa\apps\Python27\lib\site-packages\wx-2.8-msw-unicode', 'C:\PROGRA~2\Quantum GIS Lisboa\apps\qgis\python\plugins\fTools\tools']*

What can I do to avoid this error? I do not want to change the name of every feature and would prefer the umlauts to remain in my shapefile.

share|improve this question
    
Are you writing your own plugin or is this a plugin from someone else? –  Matthias Kuhn Apr 30 '13 at 9:12
    
It is a plugin, that can be intalled diectly in QGIS via the Plugin Extension Manager. –  Gideon Apr 30 '13 at 10:30

1 Answer 1

up vote 1 down vote accepted

The problem is in the python code. The following line of the error message highlights the problem:

"C:/Users/Gidi/.qgis//python/plugins\layers_by_field\layers_by_field_dialog.py", line 146, in split self.vlayer = QgsVectorLayer(vProvider.dataSourceUri(), str(layer.name()) + "_" + str(uValues[j]), "ogr") UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 7: ordinal not in range(128) Python version: 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] QGIS

The method str() is used there to generate a string. Instead, the method unicode() should be used to generate a unicode string.

self.vlayer = QgsVectorLayer( vProvider.dataSourceUri(), unicode(layer.name()) + "_" + unicode(uValues[j]), u'ogr')

If it is not your own plugin, please file a bug or contact the author.

Edit: I just checked.Here is the link to the bugtracker for this plugin.

share|improve this answer
    
Thank you! Do you think it will be possible for me to fix the plugin for my personal use without specific pythonskills? –  Gideon Apr 30 '13 at 10:32
1  
It should be pretty easy and straightforward by just replacing str with unicode on any line which gives the error mentioned in the answer. Please still open a bug (and link to this question here), so other people won't suffer from the same problem. –  Matthias Kuhn Apr 30 '13 at 10:37
    
Thank you once again, I will try it as soon as I can and also open the bug. –  Gideon Apr 30 '13 at 10:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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