Search code examples
fileerror-handlinganacondageojsongeopandas

trying to read GeoJson File but I get this error message CPLE_OpenFailedError


I'm trying to read a GeoJson file: acs2022_5yr_B01003_15000US060371198021.geojson

I downloaded the following libraries:

to read and visualize spatial data

import geopandas as gpd

to provide basemaps

import contextily as ctx

to give more power to your figures (plots)

import matplotlib.pyplot as plt

I saved the geojson in my folder (see path below): OneDrive/pscript/Practice_1/data/acs2022_5yr_B01003_15000US060371198021.geojson

Then I enter the following:

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

I get the following message: What does this mean?

---------------------------------------------------------------------------
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

Solution

  • As the error states: the file is not being found on the location you specify:

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

    Note that you are using a relative path as it doesn't start with /. So the file will be searched starting from the "current directory" you are running it, which isn't always super transparent where that is. Best make it an absolute path.