[Qgis-developer] Re: python unicode problem in raster metadata

Martin Dobias wonder.sk at gmail.com
Wed Jan 28 19:49:42 EST 2009

On Wed, Jan 28, 2009 at 10:16 PM, Volkan Kepoglu <vkepoglu at gmail.com> wrote:
> how i get the error is:
> set locale of qgis to "tr" (by edit > options > locale > tr)
> (maybe also "fr" or any language that has different characters from english.)
> and add raster file, click raster filename to select/activete the
> layer, open python console, then write those commands:
>>>> layer = iface.activeLayer()
>>>> layer.name()
> Density_0
>>>> layer.source()
> C:\temp\Density_0.tif
>>>> layer.metadata()

Hi Volkan,

I've hopefully fixed this in r10038 (and without regressions). There
were some mismatches in the qgis python support regarding unicode.
Please check whether it helped. Now the only issue with unicode/str
handling I'm aware of is corruption of entered unicode strings - those
in form u"..." or u'...'. The reason is that prior to running the
command in python, the command has to be converted from QString to
8-bit string. Here is how it works:

>>> "ň"
>>> unicode("ň",'utf8')
>>> unicode("ň",'utf8').encode('unicode-escape')
>>> u"\u0148"
>>> u"ň"

You can see that when using classic strings, they're converted to
utf-8 and then back correctly. Also when you use unicode escaped
strings, everything's ok. Only the last case is wrong and should be
escaped. It's on my todo list but hard to say when I get to it again.


More information about the Qgis-developer mailing list