Python3的ogr写入GDB文件暨配置FileGDB读写驱动

版权声明:转载请注明作者(独孤尚良dugushangliang)出处:https://blog.csdn.net/dugushangliang/article/details/122501606

先看用什么驱动来访问ArcGIS的GDB文件。

Search — GDAL documentation部分界面如下:

OK,有两个驱动可以访问GDB,一个是FileGDB,一个是OpenFileGDB。两者有什么区别?

The OpenFileGDB driver provides read access to vector layers of File Geodatabases (.gdb directories) created by ArcGIS 9 and above. The dataset name must be the directory/folder name, and it must end with the .gdb extension.

The FileGDB driver provides read and write access to vector layers of File Geodatabases (.gdb directories) created by ArcGIS 10 and above. The dataset name must be the directory/folder name, and it must end with the .gdb extension.

看不懂英文?不要紧,可以翻译。

简而言之,OpenFileGDB是内置的,只能读不能写,FileGDB能读能写,但不是内置的。那要通过ogr创建GDB的一个图层怎么办?得用FileGDB,要用FileGDB得先安装。

先说明GDAL的两种安装方式:一、软件安装,独立于Python环境;二、轮子安装,依赖于Python环境。第一种的方式可参照:

windows系统下给python安装gdal、ogr的操作_dugushangliang的博客-CSDN博客_ogr python 安装

第二种的方式可参照:给anaconda的python安装gdal_dugushangliang的博客-CSDN博客_conda 安装gdal

那么如何配置FileGDB呢?其实大同小异,细心的人已经发现思路了。

whl文件安装GDAL后确认可用的情况下,下载FileGDB的文件,本文结合当前实际下的是FileGDB_API_1_5_1-VS2015.zip,解压这个zip,本文的Python是64位,装的GDAL也是64位,所以去bin64文件夹找FileGDBAPI.dll这个文件(如果是32位的去bin文件夹内找对应文件),把它拷贝到osgeo文件夹中。因本人的anaconda安装路径是F:\software\anaconda,所以本文的osgeo文件夹是F:\software\anaconda\Lib\site-packages\osgeo。因为本文所用的GDAL是3版本系列,所以把osgeo\gdalplugins\disabled中的ogr_FileGDB.dll移动到osgeo\gdalplugins中。

 重开cmd,发现,世界真美好啊!问题终于解决了。

File Geodatabase API下载处:

Esri Downloads

GitHub - Esri/file-geodatabase-api: FileGeodatabaseAPI_1.4 (1.4.0.183) The File Geodatabase C++ API for Windows, MacOS and Linux

https://github.com/Esri/file-geodatabase-api/tree/master/FileGDB_API_1.5.1

后面的写入水到渠成了。

DriverName = "FileGDB"
FilePath=r'F:\temp\gis.gdb'
os.chdir(FilePath)
#创建数据驱动
driver = ogr.GetDriverByName(DriverName)
data_source = driver.Open(FilePath, 1)
#创建坐标系和图层
srs = osr.SpatialReference()
srs.ImportFromEPSG(4490)
outLayer = data_source.CreateLayer(FileName,srs, geom_type=ogr.wkbPolygon)

参阅:

Setting up GDAL/OGR with FileGDB Driver for Python on Windows | Geospatiality

python3安装FileGDB读写驱动_llc的博客-CSDN博客_gdb python3

独孤尚良dugushangliang——著

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值