[Qgis-developer] python unicode problem in raster metadata

Volkan Kepoglu vkepoglu at gmail.com
Wed Jan 28 16:16:07 EST 2009


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()

the error is:

sys.displayhook = sys.__displayhook__

UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in
position 19: ordinal not in range(128)

Python sürümü:
2.5.2 (r252:60911, Oct  5 2008, 19:42:18)
[GCC 4.3.2]

Python dizini:
['/usr/share/qgis/python', '/home/volkan/.qgis//python/plugins',
'/usr/share/qgis/python/plugins', '/usr/lib/python2.5',
'/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk',
'/usr/lib/python2.5/lib-dynload',
'/usr/local/lib/python2.5/site-packages',
'/usr/lib/python2.5/site-packages',
'/usr/lib/python2.5/site-packages/Numeric',
'/usr/lib/python2.5/site-packages/PIL',
'/usr/lib/python2.5/site-packages/gst-0.10',
'/var/lib/python-support/python2.5',
'/usr/lib/python2.5/site-packages/gtk-2.0',
'/var/lib/python-support/python2.5/gtk-2.0']

if the locale is "en_US", metadata is ok, returns:

<p class="glossy">Driver:</p> <p>GTiff<br>GeoTIFF</p> <p
class="glossy">Dataset Description</p> <p>C:\temp\Density_0.tif</p>
<tr><p> AREA_OR_POINT=Area</p> </tr><p class="glossy">Band 1</p> <p
class="glossy">Dimensions:</p> <p>X: 100 Y: 100 Bands: 1</p> <p
class="glossy">No Data Value</p> <p>*NoDataValue not set*</p> </p> <p
class="glossy">Data Type:</p> <p>GDT_Float32 - Thirty two bit floating
point </p> <p class="glossy">Pyramid overviews:</p> <p></p> <p
class="glossy">Layer Spatial Reference System: </p> <p>+proj=utm
+zone=36 +ellps=intl +units=m +no_defs </p> <p
class="glossy">Origin:</p> <p>482020,4.42133e+06</p> <p
class="glossy">Pixel Size:</p> <p>85.25,-90.96</p> <p class="glossy">
Band</p> <p>Band 1</p> <p>Band No</p> <p> 1</p> <p>No Stats</p> <p> No
stats collected yet</p>

so my guess is that metadata reads locale translation of someting and
trying to write in the string which causes return error, because both
the name and the source path of raster does not contains any turkish
character.

i think this maybe python specific (i mean pyqgis), because when i
opened the metadata tab in the raster layer properties, i can see well
formatted metadata text with true turkish characters.

i hope this explanation helps to find the problem.

by the way, is there any another way to get the format (GeoTiff, ...)
of raster layer in QGIS with python?

regards,
volkan kepoglu


More information about the Qgis-developer mailing list