<div dir="ltr"><span style="color:rgb(0,0,0)">I wrote a ticket on <a dir="ltr" href="http://gis.stackexchange.com/" target="_blank">gis.stackexchange.com</a>but I didn't get a satisfactory answer, so I ask my question here.</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)"></span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">I'm trying to create a memory layer with gdal/ogr python that contains a Binary Field.</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)"></span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">But I didn't succeed, where am I wrong? </span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)"></span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   from osgeo import ogr</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)"></span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   # create layer</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   driver = ogr.GetDriverByName('Memory')</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   data_source = driver.CreateDataSource('foo')</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   layer = data_source.CreateLayer('bar')</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)"></span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   # create binary field </span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   field_name = 'bin_field'</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   binary_field = ogr.FieldDefn(field_name, ogr.OFTBinary)</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   layer.CreateField(binary_field)</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)"></span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   # add feature that contains binary value</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   bytes_value = bytes(b'hello world')</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   feature = ogr.Feature(layer.GetLayerDefn())</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   feature.SetField(field_name, bytes_value)</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   layer.CreateFeature(feature)</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)"></span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">Error message : </span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)"></span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">       feature.SetField(field_name, bytes_value)</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">     File "/usr/lib/python3/dist-packages/osgeo/ogr.py", line 4321, in SetField</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">       return _ogr.Feature_SetField(self, *args)</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">   TypeError: Wrong number or type of arguments for overloaded function 'Feature_SetField'.</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">     Possible C/C++ prototypes are:</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">       OGRFeatureShadow::SetField(int,char const *)</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">       OGRFeatureShadow::SetField(char const *,char const *)</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">       OGRFeatureShadow::SetField(int,double)</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">       OGRFeatureShadow::SetField(char const *,double)</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">       OGRFeatureShadow::SetField(int,int,int,int,int,int,float,int)</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">       OGRFeatureShadow::SetField(char const *,int,int,int,int,int,float,int)</span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)"></span><br style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">Link to question on Stack Exchange : <a dir="ltr" href="https://gis.stackexchange.com/questions/382119/ogr-python-write-binary-data-in-layer" target="_blank">https://gis.stackexchange.com/questions/382119/ogr-python-write-binary-data-in-layer</a></span><br clear="all"><br>-- <br><div dir="ltr" data-smartmail="gmail_signature">Guilhain AVERLANT<br>119 rue Manin<br>75019 PARIS<br>06 28 22 83 05</div></div>