mapnik-org/mapnik — Issue #11: Mapnik Unicode support
Author: artemp
Created: 2011-10-11 07:30:23+00:00
State: closed
Labels: Boost_Python_Binding

At the moment Features store text attributes in std::string (in client encoding) and only transcoded to wide-strings (UCS-2) during rendering. This causes a problem with Python bindings exposing Features text properties in other then ASCII e.g.:

{{{
>>> from mapnik import *
>>> ds = Shapefile(file='./demo/data/boundaries')
>>> pt = ds.envelope().center()
>>> fs = ds.features_at_point(pt)
>>> f = fs.next()
>>> name = str(f.properties['NOM_FR'])
>>> name
'Qu\xe9bec'
>>> print name
Qu�ec
>>> name_unicode = unicode(name,'Latin1') # we know it's in Latin1
>>> name_unicode
u'Qu\xe9bec'
>>> print name_unicode
Québec
}}}

One way to address this is to convert to and store text attributes as Unicode (UCS-2). In Python bindings we can provide 'unicode' method to access std::wstring as a Python Unicode.

{{{
>>> name = f.properties['NOM_FR'].unicode() # name is Python Unicode
>>> name
u'Qu\xe9bec'
>>> print name
Québec
}}}