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'
1 Answer 1
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")
-
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!Binx– Binx2025年02月20日 19:56:23 +00:00Commented 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.Binx– Binx2025年02月21日 22:12:16 +00:00Commented Feb 21 at 22:12
-
1Yes 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.user2856– user28562025年02月22日 00:58:12 +00:00Commented Feb 22 at 0:58
Explore related questions
See similar questions with these tags.