1

I have the problem to show characters (äöü) in a utf8 format in Windows. In Linux there is no problem and everything is displayed correctly. I use at the second line:

# -*- coding: utf-8 -*-

and further for importing and opening the shapefile:

base = os.path.basename(str(filename))
self.vlayer = QgsVectorLayer(filename, base, "ogr")

layer = self.vlayer
provider = layer.dataProvider()
layer.select(provider.attributeIndexes())
addA=[] 
for elem in layer:
    attrs_r = elem.attributeMap()
    for (k,attr) in attrs_r.iteritems():
        addA.append(attr.toString())

I also tried:

addA.append(u'%s'%attr.toString())

and

layer.setProviderEncoding(u'UTF-8')
layer.dataProvider().setEncoding(u'UTF-8')

But it has no effect and the characters are still not displayed correctly. Is there somehow a possibility to assign directly utf-8 to the shapefile?

  • This isn't really Windows specific. I had the same Problem on Linux. I think it just depends on how your Environment and your data is set up. – MonsterMushroom Oct 1 '14 at 14:40
3

I found the solution for the problem:

layer = self.vlayer
provider = layer.dataProvider()
layer.select(provider.attributeIndexes())
addA=[] 
for elem in layer:
    attrs_r = elem.attributeMap()
    for (k,attr) in attrs_r.iteritems():
        unicodestr = unicode(attr.toString(), "utf-8")
        addA.append(unicodestr)

Now it is possible to use for example the German "Umlaute"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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