#4608 closed defect (fixed)
GDAL 1.9.0 for Python 2.7.2 does not support native unicode
Reported by: | invisibleroads | Owned by: | hobu |
---|---|---|---|
Priority: | normal | Milestone: | 2.0.0 |
Component: | PythonBindings | Version: | 1.9.0 |
Severity: | normal | Keywords: | unicode utf-8 utf8 SetField GetField |
Cc: |
Description (last modified by )
Currently, using the Python SWIG bindings for GDAL 1.9.0,
feature.SetField(0, u'xxx')
feature.SetField(0, 'Спасибо'.decode('utf-8'))
raise the following exception
NotImplementedError: Wrong number of arguments for overloaded
function 'Feature_SetField'
Meanwhile, feature.SetField2() forcibly converts the string to ascii using str().
Ideally,
SetField() should accept native unicode
SetField2() should accept native unicode
GetField() should return native unicode
GetFieldAsString() should return native unicode
References:
http://lists.osgeo.org/pipermail/gdal-dev/2010-September/026156.html
Change History (9)
comment:1 by , 12 years ago
Description: | modified (diff) |
---|
comment:2 by , 12 years ago
Description: | modified (diff) |
---|
comment:3 by , 12 years ago
Component: | SWIG (all bindings) → PythonBindings |
---|
comment:4 by , 12 years ago
Maybe one can apply a variation of Ari's changes in http://trac.osgeo.org/gdal/changeset/23405 to http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/include/python
I can't do this now, but I may be able to look at this issue in a few weeks.
comment:6 by , 9 years ago
Hmm, I am still getting the same errors with GDAL 1.11.0. Unfortunately, I'm not familiar with Perl and I am not able to make much sense of Ari's changeset.
from osgeo import ogr, osr data_driver = ogr.GetDriverByName('ESRI Shapefile') data_source = data_driver.CreateDataSource('/tmp/examples.shp') spatial_reference = osr.SpatialReference() spatial_reference.ImportFromProj4('+proj=longlat +datum=WGS84 +no_defs') data_layer = data_source.CreateLayer('layer', spatial_reference, ogr.wkbPoint) feature_definition = data_layer.GetLayerDefn() feature = ogr.Feature(feature_definition) feature.SetField(0, 'Спасибо'.decode('utf-8')) NotImplementedError: Wrong number of arguments for overloaded function 'Feature_SetField'. Possible C/C++ prototypes are: SetField(OGRFeatureShadow *,int,char const *) SetField(OGRFeatureShadow *,char const *,char const *) SetField(OGRFeatureShadow *,int,int) SetField(OGRFeatureShadow *,char const *,int) SetField(OGRFeatureShadow *,int,double) SetField(OGRFeatureShadow *,char const *,double) SetField(OGRFeatureShadow *,int,int,int,int,int,int,int,int) SetField(OGRFeatureShadow *,char const *,int,int,int,int,int,int,int) feature.SetField2(0, 'Спасибо'.decode('utf-8')) UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-6: ordinal not in range(128)
comment:7 by , 9 years ago
Milestone: | → 2.0 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
comment:8 by , 9 years ago
Cool, thanks rouault. I think at the time we were dealing with accents in French sounding towns in Senegal.
Ari Jolma reports that Perl already supports unicode attributes in GDAL. This means that GDAL stores unicode attributes, but there is something wrong with the Python typemaps.
Le 11 avril 2012 10:01, Ari Jolma <ari.jolma@…> a écrit :