Opened 5 years ago

Closed 5 years ago

#6813 closed defect (invalid)

GetFieldAsStringList returns list of emty strings

Reported by: dr Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: 2.1.2
Severity: normal Keywords:
Cc:

Description

I need to decode each item of the list. But GetFieldAsStringList returns list of empty strings and I cannot get original values. It looks like GetFieldAsString preserves original data but as I can see GetFieldAsString format for string lists is not intended to be guaranteed parsable.

driver = ogr.GetDriverByName('GeoJSON')
data_source = driver.CreateDataSource('/vsimem/data.json')
layer = data_source.CreateLayer('data')
field = layer.CreateField(ogr.FieldDefn('items', ogr.OFTStringList))
feature = ogr.Feature(layer.GetLayerDefn())
feature.SetFieldStringList(0, [u'А'.encode('cp1251'),
                               u'Б'.encode('cp1251')])

>>> feature.GetFieldAsStringList(0)
[u'', u'']

>>> feature.GetFieldAsString(0)
'(2:\xc0,\xc1)'

Change History (1)

comment:1 by Even Rouault, 5 years ago

Resolution: invalid
Status: newclosed

The issue is .encode('cp1251'). All strings passed and pulled from OGR must be encoded in UTF-8

Note: See TracTickets for help on using tickets.