Maps streamlit

Hi,
How can i add maps ploted based on geojson data (long and lat) to my streamlit app please?
I need a layer with “zone clim” column

couche = gpd.read_file('C:/Users/xxx/chambre/carte.geojson')
couche.plot(column = 'ZONE_2022' ,cmap = 'cool', legend = True, figsize = (5,5))
plt.title("zones climatiques 2022")
st.map(couche)

CRSError: Invalid projection: epsg:4326: (Internal Proj Error: proj_create: SQLite error on SELECT name, type, coordinate_system_auth_name, coordinate_system_code, datum_auth_name, datum_code, area_of_use_auth_name, area_of_use_code, text_definition, deprecated FROM geodetic_crs WHERE auth_name = ? AND code = ?: no such column: area_of_use_auth_name)

Hi @Amira_RIAHI, welcome to the Streamlit community!

In this example, st.map only takes in a dataframe with lat/lon coordinates, whereas you are passing in a plot method. Did you mean to call st.pyplot(couche) instead?

Best,
Randy

Double posting:

Help st.map please!

Hi randyzwitch,
Thank you,
Yes i tried both st.map and st.pyplot since i need to add a plot with layers to my app :roll_eyes:
I find streamlit quite simple to use except when dealing with geopandas

Regards,

As i already wrote, i think this problem is geopandas related.

  • You are running streamlit locally on windows i assume?
  • Which python version?
  • Can you share your code or your geojson file?

Hi Franky,
I was trying to update geopandas to see if it will work
i’m using streamlit locally on windows. and my Python version is 3.9.7

Thanks for help,

Without seeing actual code or data, i can only guess.
Here is a simple example to load a geojson file with point data and show it on a streamlit app:

df = gpd.read_file('cities.geojson')
df['lon'] = df.geometry.x  # extract longitude from geometry
df['lat'] = df.geometry.y  # extract latitude from geometry
df = df[['lon','lat']]     # only keep longitude and latitude
st.write(df.head())        # show on table for testing only
st.map(df)                 # show on map

Edit: Be aware that with st.map you can only show point data, for other geospatial data you have to use other libraries/elements for example plotly or pydeck and their corresponding streamlit elements:

Chart elements - Streamlit Docs

2 Likes

Hi Franky1,
Using pydeck was the solution because i was able to add layers :smiling_face:
Thanks !!

1 Like

you also can try streamlit-folium package

package url:

3 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.