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

2024-04-23 15:19:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用geopandas python库将文件geodatabase文件读入geodataframe。地理数据库文件位于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")

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

不幸的是,我不能提供一种复制错误的方法,因为我在云上做所有的事情。它在本地运行良好


Tags: 文件inselfreadbucketmyasdriver
1条回答
网友
1楼 · 发布于 2024-04-23 15:19:46

对于S3位置和shapefile(甚至可能是具有只读权限的NAS文件夹),我们在使用只读键时也看到了类似的问题

您可以同时使用具有读写权限和只读权限的密钥吗?我的猜测是,后端的gdal驱动程序需要写入权限/访问权限,即使只需要读取

错误跟踪的最后一部分暗示了驱动程序问题

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

如果有人能够确认gdal驱动程序所需的权限的细节,那就太好了

相关问题 更多 >