python3安装FileGDB读写驱动
环境
- 系统:win10x64
- python:3.6.5x64
安装步骤
-
安装gdal: GDAL‑2.4.1‑cp36‑cp36m‑win_amd64.whl
pip install GDAL-2.4.1-cp36-cp36m-win_amd64.whl
-
安装FileGDBAPI.dll:下载地址
拷贝FileGDBAPI.dll至C:\Program Files\Python36\Lib\site-packages\osgeo目录,安装目录与python安装目录一致
注意: GDAL 3.x 版本还需要把
gdalplugins\disabled
中的ogr_FileGDB.dll
移动到gdalplugins
目录 -
测试,已成功加载FileGDB:
C:\WINDOWS\system32>ogrinfo --formats|findstr "GDB" FileGDB -vector- (rw+): ESRI FileGDB OpenFileGDB -vector- (rov): ESRI FileGDB
-
ipython测试,可以看到gdb_driver为空,目前为止还是不能使用(GDAL 3.x 版本不需要此步骤)
>ipython Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] Type 'copyright', 'credits' or 'license' for more information IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: from osgeo import ogr In [2]: gdb_driver=ogr.GetDriverByName("FileGDB") In [3]: gdb_driver In [4]:
-
修改osgeo/__init__.py文件:注释15行,取消注释17行(GDAL 3.x 版本不需要此步骤)
# __init__ for osgeo package. # unofficial Windows binaries: set GDAL environment variables if necessary import os try: _here = os.path.dirname(__file__) if _here not in os.environ['PATH']: os.environ['PATH'] = _here + ';' + os.environ['PATH'] if 'GDAL_DATA' not in os.environ: os.environ['GDAL_DATA'] = os.path.join(_here, 'data', 'gdal') if 'PROJ_LIB' not in os.environ: os.environ['PROJ_LIB'] = os.path.join(_here, 'data', 'proj') if 'GDAL_DRIVER_PATH' not in os.environ: #pass # uncomment the next line to enable plugins os.environ['GDAL_DRIVER_PATH'] = os.path.join(_here, 'gdalplugins') except Exception: pass del os
-
再次测试,成功!
>ipython Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] Type 'copyright', 'credits' or 'license' for more information IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: from osgeo import ogr In [2]: gdb_driver=ogr.GetDriverByName("FileGDB") In [3]: gdb_driver Out[3]: <osgeo.ogr.Driver; proxy of <Swig Object of type 'OGRDriverShadow *' at 0x00000277407BBC60> > In [4]: