1

我正在尝试使用 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 凭证从任何机器访问数据。

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

4

1 回答 1

0

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

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

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

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

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

于 2021-07-01T19:03:53.993 回答