Friday 30 December 2016

python - Special characters in QGIS script tools


I would like to write a script that includes a selection from the attribute table. But my data is in Hungarian, so it includes special characters like: öüőűáéí


So when there is non of these in the query it executes, otherwise I get this:


Is there a setting or something to solve this?



Answer




What happens when you use diacritic characters?


It might be a simple python problem. Open the python editor in QGIS, and ensure that you start with the two comment lines on the top, like this:


#!/usr/bin/env python
# -*- coding: utf-8 -*-
layers = QgsMapLayerRegistry.instance().mapLayersByName('utilizador')
layer = layers[0]
it = layer.getFeatures()

layer.startEditing()
for feat in it:

layer.changeAttributeValue(feat.id(), 7, u'Jó napot kívánok!')

layer.commitChanges()

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...