0

I have a peculiar situation when trying to write to a .gdb using OGR. I get a NoneType error following any OGR function after ogr.Open() when I specify the data source as writable. From previous questions (e.g., 'NoneType' object has no attribute), I have learned that the NoneType error is thrown when the data source cannot be opened, such as when the path is incorrect. However, I am successfully able to open the OpenFileGDB datasource as read-only and retrieve the correct number of layers, per the code below, which makes the me think I have a different problem. What could be the reason for this discrepancy?

Python 3.9.16 [MSC v.1931 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> from osgeo import ogr
>>> parcel_gdb = r'C:\mypath\mygdb.gdb'
>>> output_gdb = ogr.GetDriverByName("OpenFileGDB").Open(parcel_gdb, 1)
>>> print(output_gdb.GetLayerCount())
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    print(output_gdb.GetLayerCount())
AttributeError: 'NoneType' object has no attribute 'GetLayerCount'
>>>
>>> output_gdb = ogr.GetDriverByName("OpenFileGDB").Open(parcel_gdb, 0)
>>> print(output_gdb.GetLayerCount())
2
>>> 
4
  • Try enabling exceptions and seeing if you get a more descriptive error
    – mikewatt
    Jul 12, 2023 at 19:41
  • Thanks for the comment, mikewatt. Unfortunately, it does not look like I get any more information from UseExceptions(). >>> ogr.UseExceptions() >>> output_gdb = ogr.GetDriverByName("OpenFileGDB").Open(parcel_gdb, 1) >>> print(output_gdb.GetLayerCount()) Traceback (most recent call last): File "<pyshell#14>", line 1, in <module> print(output_gdb.GetLayerCount()) AttributeError: 'NoneType' object has no attribute 'GetLayerCount'
    – Airv
    Jul 12, 2023 at 20:21
  • What version of GDAL? The OpenFileGDB driver only supports writing since GDAL >= 3.6 (released Dec 2022) gdal.org/drivers/vector/openfilegdb.html
    – user2856
    Jul 12, 2023 at 22:21
  • @user2856, thank you, that was it! Apparently I was on GDAL 3.4.0, which was the default version that came with ArcGIS Pro. I installed a new version of Python and GDAL through Conda and using GDAL 3.6.2, I was able to open the .gdb for writing. Happy to mark your answer as correct if you want to write it in.
    – Airv
    Jul 13, 2023 at 21:10

1 Answer 1

0

The GDAL OpenFileGDB driver added write and update support at GDAL 3.6 (released Dec 2022).

If your version of GDAL is < 3.6 then you can only use GDAL to read FileGDBs with the OpenFileGDB driver.

If you have installed the Esri FileGDB SDK and have a version of GDAL with the Esri FileGDB driver included (either built-in or as a plugin) then you can write/update file GDBs with earlier GDAL versions, however, not many GDAL distributions include this driver.

Your Answer

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

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