geopython-workshop icon indicating copy to clipboard operation
geopython-workshop copied to clipboard

add Streamlit exercise to Section 7

Open tomkralidis opened this issue 1 year ago • 1 comments

tomkralidis avatar May 02 '24 12:05 tomkralidis

  • add high level description/overview/demo (@krishnaglodha) for further reading.

tomkralidis avatar Jun 27 '24 11:06 tomkralidis

https://streamlit.io/playground?example=geospatial -> deck has limited wms support, alternative is https://folium.streamlit.app/ based on leaflet, so should have wms etc

Other option would be to load data from wfs via owslib and geopandas, following this https://pythongis.org/part2/chapter-09/nb/01-retrieving-data-from-wfs.html and then connect pydeck to geopandas as https://deckgl.readthedocs.io/en/latest/gallery/geopandas_integration.html; or connect deck directly to a geojson, returned by a ogcapi-features:


import streamlit as st
import pydeck as pdk
import geopandas as gpd

lakes = gpd.read_file("https://demo.pygeoapi.io/master/collections/lakes/items")

centroids = gpd.GeoDataFrame()
centroids["geometry"] = lakes.geometry.centroid
centroids["name"] = lakes.name

st.pydeck_chart(pdk.Deck(
    map_style=None,
    initial_view_state=pdk.ViewState(
        latitude=40,
        longitude=-92,
        zoom=3,
        pitch=50,
    ),
    layers=[
        pdk.Layer(
        "GeoJsonLayer",
        data=lakes,
        opacity=0.5,
        get_fill_color= [99, 99, 255],
    ),
    pdk.Layer(
        "TextLayer",
        data=centroids,
        get_position="geometry.coordinates",
        get_size=16,
        get_color=[0, 0, 50],
        get_text="name",
    )   
    ],
))

st.dataframe(lakes, use_container_width=True, column_config={
        "name_alt": st.column_config.LinkColumn()}, column_order=("name","name_alt"))

pvgenuchten avatar Apr 10 '25 07:04 pvgenuchten