[gdal-dev] OGR python : write binary data in layer
Guilhain Averlant
g.averlant at gmail.com
Wed Dec 16 12:52:41 PST 2020
I wrote a ticket on gis.stackexchange.combut I didn't get a satisfactory
answer, so I ask my question here.
I'm trying to create a memory layer with gdal/ogr python that contains a
Binary Field.
But I didn't succeed, where am I wrong?
from osgeo import ogr
# create layer
driver = ogr.GetDriverByName('Memory')
data_source = driver.CreateDataSource('foo')
layer = data_source.CreateLayer('bar')
# create binary field
field_name = 'bin_field'
binary_field = ogr.FieldDefn(field_name, ogr.OFTBinary)
layer.CreateField(binary_field)
# add feature that contains binary value
bytes_value = bytes(b'hello world')
feature = ogr.Feature(layer.GetLayerDefn())
feature.SetField(field_name, bytes_value)
layer.CreateFeature(feature)
Error message :
feature.SetField(field_name, bytes_value)
File "/usr/lib/python3/dist-packages/osgeo/ogr.py", line 4321, in
SetField
return _ogr.Feature_SetField(self, *args)
TypeError: Wrong number or type of arguments for overloaded function
'Feature_SetField'.
Possible C/C++ prototypes are:
OGRFeatureShadow::SetField(int,char const *)
OGRFeatureShadow::SetField(char const *,char const *)
OGRFeatureShadow::SetField(int,double)
OGRFeatureShadow::SetField(char const *,double)
OGRFeatureShadow::SetField(int,int,int,int,int,int,float,int)
OGRFeatureShadow::SetField(char const
*,int,int,int,int,int,float,int)
Link to question on Stack Exchange :
https://gis.stackexchange.com/questions/382119/ogr-python-write-binary-data-in-layer
--
Guilhain AVERLANT
119 rue Manin
75019 PARIS
06 28 22 83 05
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20201216/ab8aed9f/attachment.html>
More information about the gdal-dev
mailing list