6

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
'OpenFileGDB'
>>> layer = src.GetLayerByName("Photo__ATTACH")
>>> feature = layer.GetFeature(1)
>>> data = feature.GetField("DATA")
>>> len(data)
75
>>> data
'FFD8FFE000104A46494600010100004800480000FFE100584578696600004D4D002A0000...'

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

4

1 Answer 1

6

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)
2735908
2
  • 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, 2016 at 5:37
  • Yes. Exactly that. Aug 25, 2016 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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