[gdal-dev] OGR python : write binary data in layer
Guilhain Averlant
g.averlant at gmail.com
Thu Dec 17 06:21:55 PST 2020
Thanks a lot !
If you want to use only native python functions you can do like this.
binary_as_hex_string = bytes_value.hex()
feature.SetFieldBinaryFromHexString(field_name, binary_as_hex_string)
To restore bytes_value to bytes type :
bytes_value = bytes.fromhex(binary_as_hex_string)
Le mer. 16 déc. 2020 à 22:28, Even Rouault <even.rouault at spatialys.com> a
écrit :
> Guilhain,
>
> On mercredi 16 décembre 2020 21:52:41 CET Guilhain Averlant wrote:
> > 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?
>
> Probably nothing. I'm not sure why we don't have an override for this.
> Perhaps
> because OFTBinary is rather exotic and nobody strongly needed it before.
> Perhaps some (past) Python2/3 dilemna too
>
> You can use f.SetFieldBinaryFromHexString(field_name,
>
> binary_as_hex_string)
>
> where e.g. binary_as_hex_string = binascii.hexlify(b'hello world')
>
> Even
>
> --
> Spatialys - Geospatial professional services
> http://www.spatialys.com
>
--
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/20201217/6ed64167/attachment.html>
More information about the gdal-dev
mailing list