尝试读取 GeoJson 文件,但收到此错误消息 CPLE_OpenFailedError

问题描述 投票:0回答:1

我正在尝试读取 GeoJson 文件:acs2022_5yr_B01003_15000US060371198021.geojson

我下载了以下库:

读取和可视化空间数据

将 geopandas 导入为 gpd

提供底图

上下文导入为 ctx

为你的图形(图)赋予更多力量

将 matplotlib.pyplot 导入为 plt

我将geojson保存在我的文件夹中(参见下面的路径):OneDrive/pscript/Practice_1/data/acs2022_5yr_B01003_15000US060371198021.geojson

然后我输入以下内容:

gdf = gpd.read_file('OneDrive/pscript/Practice_1/data/acs2022_5yr_B01003_15000US060371198021.geojson')

我收到以下消息:这是什么意思?

---------------------------------------------------------------------------
CPLE_OpenFailedError                      Traceback (most recent call last)
File fiona\\ogrext.pyx:136, in fiona.ogrext.gdal_open_vector()

File fiona\\_err.pyx:291, in fiona._err.exc_wrap_pointer()

CPLE_OpenFailedError: OneDrive/pscript/Practice_1/data/acs2022_5yr_B01003_15000US060371198021.geojson: No such file or directory

During handling of the above exception, another exception occurred:

DriverError                               Traceback (most recent call last)
Cell In[6], line 3
      1 # load a data file
      2 # note the relative filepath! where is this file located?
----> 3 gdf = gpd.read_file('OneDrive/pscript/Practice_1/data/acs2022_5yr_B01003_15000US060371198021.geojson')

File ~\anaconda3\Lib\site-packages\geopandas\io\file.py:297, in _read_file(filename, bbox, mask, rows, engine, **kwargs)
    294     else:
    295         path_or_bytes = filename
--> 297     return _read_file_fiona(
    298         path_or_bytes, from_bytes, bbox=bbox, mask=mask, rows=rows, **kwargs
    299     )
    301 else:
    302     raise ValueError(f"unknown engine '{engine}'")

File ~\anaconda3\Lib\site-packages\geopandas\io\file.py:338, in _read_file_fiona(path_or_bytes, from_bytes, bbox, mask, rows, where, **kwargs)
    335     reader = fiona.open
    337 with fiona_env():
--> 338     with reader(path_or_bytes, **kwargs) as features:
    339         crs = features.crs_wkt
    340         # attempt to get EPSG code

File ~\anaconda3\Lib\site-packages\fiona\env.py:457, in ensure_env_with_credentials.<locals>.wrapper(*args, **kwds)
    454     session = DummySession()
    456 with env_ctor(session=session):
--> 457     return f(*args, **kwds)

File ~\anaconda3\Lib\site-packages\fiona\__init__.py:292, in open(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, allow_unsupported_drivers, **kwargs)
    289     path = parse_path(fp)
    291 if mode in ("a", "r"):
--> 292     colxn = Collection(
    293         path,
    294         mode,
    295         driver=driver,
    296         encoding=encoding,
    297         layer=layer,
    298         enabled_drivers=enabled_drivers,
    299         allow_unsupported_drivers=allow_unsupported_drivers,
    300         **kwargs
    301     )
    302 elif mode == "w":
    303     colxn = Collection(
    304         path,
    305         mode,
   (...)
    314         **kwargs
    315     )

File ~\anaconda3\Lib\site-packages\fiona\collection.py:243, in Collection.__init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, ignore_fields, ignore_geometry, include_fields, wkt_version, allow_unsupported_drivers, **kwargs)
    241 if self.mode == "r":
    242     self.session = Session()
--> 243     self.session.start(self, **kwargs)
    244 elif self.mode in ("a", "w"):
    245     self.session = WritingSession()

File fiona\\ogrext.pyx:588, in fiona.ogrext.Session.start()

File fiona\\ogrext.pyx:143, in fiona.ogrext.gdal_open_vector()

DriverError: OneDrive/pscript/Practice_1/data/acs2022_5yr_B01003_15000US060371198021.geojson: No such file or directory
file error-handling anaconda geojson geopandas
1个回答
0
投票

如错误所述:在您指定的位置找不到该文件:

DriverError: OneDrive/pscript/Practice_1/data/acs2022_5yr_B01003_15000US060371198021.geojson:
No such file or directory

请注意,您使用的是相对路径,因为它不以 / 开头。因此,当您运行该文件时,将从“当前目录”开始搜索该文件。最好使其成为绝对路径。

© www.soinside.com 2019 - 2024. All rights reserved.