I wanted to read the .shp files by the file_uploader of streamlit.
- Get the list of shp files from the
file_uploaderof streamlit. - Read the shp files using the geopandas.
Here's my code.
st.session_state.data_01 = st.file_uploader('Please choose a file.', accept_multiple_files=True, key='0').
df = []
for d in st.session_state.data_01:
df.append(gpd.read_file(d),encoding='utf-8')
And I got the error such like:
File "/Users/icuh/Desktop/Eun/Web/life.py", line 17, in run_life
df.append(gpd.read_file(d),encoding='utf-8')
File "/Users/icuh/opt/anaconda3/envs/impacts_02/lib/python3.8/site-packages/geopandas/io/file.py", line 253, in _read_file
return _read_file_fiona(
File "/Users/icuh/opt/anaconda3/envs/impacts_02/lib/python3.8/site-packages/geopandas/io/file.py", line 294, in _read_file_fiona
with reader(path_or_bytes, **kwargs) as features:
File "/Users/icuh/opt/anaconda3/envs/impacts_02/lib/python3.8/site-packages/fiona/collection.py", line 555, in __init__
super(BytesCollection, self).__init__(self.virtual_file, vsi=filetype, **kwds)
File "/Users/icuh/opt/anaconda3/envs/impacts_02/lib/python3.8/site-packages/fiona/collection.py", line 162, in __init__
self.session.start(self, **kwargs)
File "fiona/ogrext.pyx", line 540, in fiona.ogrext.Session.start
File "fiona/_shim.pyx", line 90, in fiona._shim.gdal_open_vector
fiona.errors.DriverError: '/vsimem/3563f91543824520abdaa032ab1a68da' not recognized as a supported file format.
Versions I use
- python 3.8.6
- geopandas 0.11.1
- fiona 1.8.21
- shapely 1.8.4
This is not a streamlit issue as such.
.shp. Same error you reported.shp. Different error, partner files missing (`.shx', '.prj', ...).shp. SuceedsYour upload capability needs to take into account that a shape file is a set of files (not a single file). Either ensure they are all uploaded into same directory. Alternatively zip them up and upload zip file.
read_file()supports zip files.output