I’m trying to create an interactive map using this guide: This
I use pycharm with anaconda environment, so I don’t understand when put my .shp file. This is the example code:
JavaScript
x
5
1
import geopandas as gpd
2
shapefile = 'data/countries_110m/ne_110m_admin_0_countries.shp'
3
#Read shapefile using Geopandas
4
gdf = gpd.read_file(shapefile)[['ADMIN', 'ADM0_A3', 'geometry']]
5
Is this correct my directory?
JavaScript
1
2
1
C:UsersgpontPycharmProjectspythonProject2dataMapmap1ne_110m_admin_0_countries.shp
2
Error:
JavaScript
1
25
25
1
C:Usersgpontanaconda3envspythonProject2python.exe C:/Users/gpont/PycharmProjects/pythonProject2/main.py
2
Traceback (most recent call last):
3
File "fiona/_shim.pyx", line 83, in fiona._shim.gdal_open_vector
4
File "fiona/_err.pyx", line 270, in fiona._err.exc_wrap_pointer
5
fiona._err.CPLE_OpenFailedError: 'map1 e_110m_admin_0_countries.shp' does not exist in the file system, and is not recognized as a supported dataset name.
6
7
During handling of the above exception, another exception occurred:
8
9
Traceback (most recent call last):
10
File "C:/Users/gpont/PycharmProjects/pythonProject2/main.py", line 6, in <module>
11
gdf = gpd.read_file(shapefile)[['ADMIN', 'ADM0_A3', 'geometry']]
12
File "C:Usersgpontanaconda3envspythonProject2libsite-packagesgeopandasiofile.py", line 96, in _read_file
13
with reader(path_or_bytes, **kwargs) as features:
14
File "C:Usersgpontanaconda3envspythonProject2libsite-packagesfionaenv.py", line 398, in wrapper
15
return f(*args, **kwargs)
16
File "C:Usersgpontanaconda3envspythonProject2libsite-packagesfiona__init__.py", line 253, in open
17
c = Collection(path, mode, driver=driver, encoding=encoding,
18
File "C:Usersgpontanaconda3envspythonProject2libsite-packagesfionacollection.py", line 154, in __init__
19
self.session.start(self, **kwargs)
20
File "fiona/ogrext.pyx", line 484, in fiona.ogrext.Session.start
21
File "fiona/_shim.pyx", line 90, in fiona._shim.gdal_open_vector
22
fiona.errors.DriverError: 'map1 e_110m_admin_0_countries.shp' does not exist in the file system, and is not recognized as a supported dataset name.
23
24
Process finished with exit code 1
25
Thank you in advance.
Giovanni
Advertisement
Answer
You seem to have a n
in your path, which is interpreted as a newline character. (Note the missing n
in 'map1 e_110m_admin_0_countries.shp' does not exist
)
Try
JavaScript
1
4
1
import os
2
3
gpd.read_file(os.path.normpath(shapefile))
4