Geopandas with file_uploader

Hi,

I have spatial data in (*.shp) format which is nothing but a polygon file with spatial coordinates.
I am using file_uploader to get the file from the local path and dump it in geopandas for further processing.

import streamlit as st
import geopandas as gpd

input = st.file_uploader(“Upload AOI *.shp file”, type=‘shp’)

if input is not None:
f_name = gpd.read_file(input)

Input file:

Hi @manish7738 -

Is this a question or a demonstration that this can be done in Streamlit?

Best,
Randy

A question, how can we do this with streamlit.

I see 2 workarounds;

  1. Read file as Geodataframe
  2. Get file Path from file_uploader and pass it to geopandas library

Maybe The second one seems workable, but I cannot fetch that details. Please help.

file_uploader will let you pass any sort of file, so uploading a shapefile works the same as any other file type.

If you use geopandas to make a GeoDataFrame, I suspect you could use st.pydeck_chart to display the data.

Best,
Randy

Thanks @randyzwitch, but for now I managed to do it with text_input

Before adding the path the application shows DriveError as below;

Please suggest how can I remove this from display.

Thanks in advance

In this case, it’s telling you that the file/directory you are providing doesn’t exist. Though, passing a string with the file path instead of sending the file directly shouldn’t be needed. Can you post your full app code?

Hi,
Some code issues which are fixed now.

Not sure if the question is relevant to streamlit;
I am using folium with streamlit to

  1. display the GeoDataframe on maps
  2. Create a new GeoDataframe and add to maps

But, both processes display 2 different maps. I want the new GeoDatframe to be added to same map.

Below is what I get now and to be fixed;

Thanks in advance