1

Scoured the internet, github, and stack exchange for a couple days to get the FileGDB Driver installed/enabled within a venv. Purpose is to generate a FileGDB (NOT read a gdb - OpenFileGDB) and utilize features such as domains, field alias, subtypes, etc. Currently using uv and windows 10, but also have mamba/conda available as well. Most tutorials and posts are well over 5 years old so I seek some up to date guidance.

uv set up

pip install uv
uv .venv --python 3.11
.venv\Scripts\activate

FileGDB set up

# Installed Visual Studio 2022
# install gdal
uv add https://github.com/cgohlke/geospatial-wheels/releases/download/v2025.1.20/GDAL-3.10.1-cp311-cp311-win_amd64.whl
# Download ESRI SDK API (the link in gdal documentation is broken)
# https://github.com/Esri/file-geodatabase-api/blob/master/FileGDB_API_1.5.3/FileGDB_API_VS2022.zip
# FileGDBAPID.dll, Esri.FileGDBAPI.dll, FileGDBAPI.dll --> .venv/Lib/site-packages/osgeo
# Update __init__.py os.environ['GDAL_DRIVER_PATH']
try:
 _here = os.path.dirname(__file__)
 ...
 if 'GDAL_DRIVER_PATH' not in os.environ:
 os.environ['GDAL_DRIVER_PATH'] = _here
 os.add_dll_directory(_here)
except Exception:
 pass

Test code

from osgeo import ogr
from osgeo import gdal
driver_count = gdal.GetDriverCount()
# List all drivers
for i in range(driver_count):
 driver = gdal.GetDriver(i)
 if "FileGDB" in driver.ShortName:
 print(driver.ShortName)
driver = ogr.GetDriverByName("FileGDB")
print(driver)
gdb = driver.CreateDataSource("./my_gdb.gdb")

Results

Warning 1: Missing global # gdal: DRIVER_NAME declaration in ...\.venv\Lib\site-packages\osgeo\gdal_array.py
OpenFileGDB
None
Traceback (most recent call last):
 File "...\test.py", line 14, in <module>
 gdb = driver.CreateDataSource("./my_gdb.gdb")
 ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'CreateDataSource'
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Feb 20 at 18:56
0

1 Answer 1

3

I assume those tutorials are old because they are no longer required. The OpenFileGDB driver is read/write and handles raster data (read-only) which FileGDB does not. From the driver documentation:

Write and update capabilities are supported since GDAL >= 3.6

The driver also supports raster layers since GDAL 3.7

So you can just use:

driver = ogr.GetDriverByName("OpenFileGDB") 
gdb = driver.CreateDataSource("./my_gdb.gdb")
answered Feb 20 at 19:39
3
  • Wow, well that was anticlimatic. I must have read something wrong somewhere in the documentation. Didn't understand that OpenFileGDB was a replacement for FileGDB. Thank you! Commented Feb 20 at 19:56
  • You have "driver supports raster layers since GDAL 3.7". That is only read support correct? I don't think writing rasters has been supported yet. Commented Feb 21 at 22:12
  • 1
    Yes rasters are read only currently gdal.org/en/stable/drivers/raster/…. I only noted it as FileGDB API and driver doesn't support rasters at all. Commented Feb 22 at 0:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.