Py.Cafe

amjadraza/

streamlit-pydeck

Geospatial 3D- Data Visualization using Streamlit & PyDeck in Browser

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import streamlit as st
import pydeck as pdk

def app_company_information():
    with st.sidebar:
            # st.sidebar.image(add_logo(logo_path=f"datafy_logo.png", width=200, height=60))
            st.markdown("---")
            st.markdown("📖 Demo: Streamlit x PyDeck x PyCafe" )
            st.markdown("Made by [DR. AMJAD RAZA](https://www.linkedin.com/in/amjadraza/)")
            st.markdown("---")

if __name__ == "__main__":
    st.set_page_config(
        page_title="Streamlit x PyDeck x PyCafe",
        page_icon="🧰",
        layout="wide",
        initial_sidebar_state="expanded",
        menu_items={
        'Get Help': 'https://www.datafyassociates.com/',
        'Report a bug': "https://www.datafyassociates.com/",
        'About': "# A project to showcase geospatial Visualization"
        })
    
    app_company_information()

    st.header("Demo: Streamlit x PyDeck x PyCafe")
    st.markdown('''In this streamlit application, we an compare the floods geospatial data before and after. The images are taken from opengeos GitHub page. 
                ''')
    
    DATA_URL = "https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/geojson/vancouver-blocks.json"
    LAND_COVER = [[[-123.0, 49.196], [-123.0, 49.324], [-123.306, 49.324], [-123.306, 49.196]]]

    INITIAL_VIEW_STATE = pdk.ViewState(latitude=49.254, longitude=-123.13, zoom=11, max_zoom=16, pitch=45, bearing=0)

    polygon = pdk.Layer(
        "PolygonLayer",
        LAND_COVER,
        stroked=False,
        # processes the data as a flat longitude-latitude pair
        get_polygon="-",
        get_fill_color=[0, 0, 0, 20],
    )
    geojson = pdk.Layer(
        "GeoJsonLayer",
        DATA_URL,
        opacity=0.8,
        stroked=False,
        filled=True,
        extruded=True,
        wireframe=True,
        get_elevation="properties.valuePerSqm / 20",
        get_fill_color="[255, 255, properties.growth * 255]",
        get_line_color=[255, 255, 255],
    )

    r = pdk.Deck(layers=[polygon, geojson], initial_view_state=INITIAL_VIEW_STATE)
    st.pydeck_chart(r, use_container_width=True)