使用 geopandas 从 S3 读取文件地理数据库的驱动程序错误

问题描述

我正在尝试使用 geopandas python 库将文件地理数据库文件读入地理数据框。地理数据库文件位于 S3 上,因此我使用 fssspec 读取它,但出现错误:

import geopandas as gpd
import fsspec

fs = fsspec.filesystem('s3',profile='my-profile',anon=False)

它可以读取 geojson 文件:

# this runs w/o error
g_file = fs.open("my-bucket/my-file.geojson")
gdf = gpd.read_file(g_file)

这会导致错误:

gbd_file = fs.open("my-bucket/my-file.gdb/")
gdf = gpd.read_file(gdb_file,driver="FileGDB")

这是错误回溯:

---------------------------------------------------------------------------
CPLE_OpenFailedError                      Traceback (most recent call last)
fiona/_shim.pyx in fiona._shim.gdal_open_vector()

fiona/_err.pyx in fiona._err.exc_wrap_pointer()

CPLE_OpenFailedError: '/vsimem/83f6a4d8051c449c86c4c608520eb998' not recognized as a supported file format.

During handling of the above exception,another exception occurred:

DriverError                               Traceback (most recent call last)
<ipython-input-33-7245da312526> in <module>
----> 1 gdf = gpd.read_file(file,driver='FileGDB')

~/my-conda-envs/nwm/lib/python3.7/site-packages/geopandas/io/file.py in _read_file(filename,bbox,mask,rows,**kwargs)
    158 
    159     with fiona_env():
--> 160         with reader(path_or_bytes,**kwargs) as features:
    161 
    162             # In a future Fiona release the crs attribute of features will

~/my-conda-envs/nwm/lib/python3.7/site-packages/fiona/collection.py in __init__(self,bytesbuf,**kwds)
    554         # Instantiate the parent class.
    555         super(BytesCollection,self).__init__(self.virtual_file,vsi=filetype,--> 556                                               encoding='utf-8',**kwds)
    557 
    558     def close(self):

~/my-conda-envs/nwm/lib/python3.7/site-packages/fiona/collection.py in __init__(self,path,mode,driver,schema,crs,encoding,layer,vsi,archive,enabled_drivers,crs_wkt,ignore_fields,ignore_geometry,**kwargs)
    160             if self.mode == 'r':
    161                 self.session = Session()
--> 162                 self.session.start(self,**kwargs)
    163             elif self.mode in ('a','w'):
    164                 self.session = WritingSession()

fiona/ogrext.pyx in fiona.ogrext.Session.start()

fiona/_shim.pyx in fiona._shim.gdal_open_vector()

DriverError: '/vsimem/83f6a4d8051c449c86c4c608520eb998' not recognized as a supported file format.

另一个潜在的线索: 我可以通过简单的方式让它工作:

gdf = gpd.read_file("s3://my-bucket/my-file.gdb/",driver="FileGDB")

但仅在属于存储桶访问策略一部分的机器上。我想要的是使用存储在 my-profile 配置文件中的 AWS 凭证从任何机器访问数据。

不幸的是,我无法提供重现错误的方法,因为我在云上进行所有操作。它在本地运行良好...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)