admin管理员组文章数量:1404355
I am trying to add a large .shp file to a streamlit folium map, and there is a significant lag each time I zoom or re-center the map. The shapefile is large, with about 10000 rows with polygon geometries covering texas and new mexico. I've tried putting it inside a form, and that is helpful, but I still get a long wait time after pushing the submit button.
My question, is there a more efficient way to load a layer than what I have below? I've seen other Streamlit apps with very complex base maps that render almost instantly, and I'm hoping to get the same result. Ultimately, I'd like to add some dynamic drawing features to this, but I can't get to that step until the base map is running well.
import streamlit as st
import geopandas as gpd
import folium
from streamlit_folium import st_folium
st.set_page_config(layout="wide")
@st.cache_data
def load_shp():
shp_df = gpd.read_file('testlayer.shp')
return shp_df.to_json()
layer_to_add = load_shp()
with st.form(key='mymap'):
m = folium.Map(location = [31.5943, -102.8927], zoom_start = 12)
folium.GeoJson(layer_to_add, name="my layer",style_function=lambda feature: {"fillColor": "yellow", "color": "black", "weight": 0.5, "fillOpacity": 0.4}).add_to(m)
st_folium(m, height = 1000, use_container_width = True, key = 'map')
submit_button = st.form_submit_button("Submit")
本文标签: pythonAdding a large shp file to a Streamlit appStack Overflow
版权声明:本文标题:python - Adding a large .shp file to a Streamlit app - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744784726a2624927.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论