Is it possible to read a binary data field (BLOB) from an Esri geodatabase using OGR? I'm using the OpenFileGDB driver and can extract the first few bytes, but then it truncates the data with "...".

>>> import ogr
>>> src = ogr.Open("data.gdb")
>>> src.GetDriver().name
>>> layer = src.GetLayerByName("Photo__ATTACH")
>>> feature = layer.GetFeature(1)
>>> data = feature.GetField("DATA")
>>> len(data)
>>> data

I'm not sure if this is a problem with the driver, or if I just need to pass it a particular flag?

FFD8 is the start of a JPEG file in HEX.

The equivalent in ArcGIS-speak is here: http://support.esri.com/technical-article/000011912


After upgrading to a more recent version of GDAL (was using 1.11.4, now on 2.1.1) the feature object provides a GetFieldAsBinary method. This returns the full data as a bytes object.

>>> data = feature.GetFieldAsBinary("DATA")
>>> len(data)
  • Ah, this is very useful, didn't know there is support for this in gdal, very cool. Do you get Python bytes you can write with wb option to file? Aug 25 '16 at 5:37
  • Yes. Exactly that. Aug 25 '16 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.