File size: 2,960 Bytes
9ad0e2d
 
 
 
 
 
 
 
 
 
 
 
 
 
a22204c
f2cf4fa
9ad0e2d
 
 
 
 
 
81b9b9a
9ad0e2d
 
 
 
 
 
 
 
d5c9531
9ad0e2d
 
 
 
d5c9531
 
 
 
9ad0e2d
 
 
 
d5c9531
 
 
9ad0e2d
d5c9531
9ad0e2d
d5c9531
9ad0e2d
 
 
 
 
 
 
d5c9531
9ad0e2d
 
d5c9531
 
 
9ad0e2d
d5c9531
 
 
 
9ad0e2d
 
 
 
d5c9531
 
9ad0e2d
d5c9531
9ad0e2d
 
 
 
d5c9531
 
9ad0e2d
d5c9531
9ad0e2d
 
 
d5c9531
9ad0e2d
d5c9531
9ad0e2d
 
 
 
d5c9531
9ad0e2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import ee
import geemap.foliumap as geemap
import geopandas as gpd
import streamlit as st

st.set_page_config(layout="wide")


def ee_authenticate(token_name="EARTHENGINE_TOKEN"):
    geemap.ee_initialize(token_name=token_name)


st.sidebar.info(
    """
    - Web App URL: <https://streamlit.gishub.org>
    - GitHub repository: <https://github.com/giswqs/streamlit-geospatial>
    """
)

st.sidebar.title("Contact")
st.sidebar.info(
    """
    Qiusheng Wu at [wetlands.io](https://wetlands.io) | [GitHub](https://github.com/giswqs) | [Twitter](https://twitter.com/giswqs) | [YouTube](https://www.youtube.com/@giswqs) | [LinkedIn](https://www.linkedin.com/in/giswqs)
    """
)

st.title("Global Building Footprints")

col1, col2 = st.columns([8, 2])


@st.cache_data
def read_data(url):
    return gpd.read_file(url)


countries = (
    "https://github.com/giswqs/geemap/raw/master/examples/data/countries.geojson"
)
states = "https://github.com/giswqs/geemap/raw/master/examples/data/us_states.json"

countries_gdf = read_data(countries)
states_gdf = read_data(states)

country_names = countries_gdf["NAME"].values.tolist()
country_names.remove("United States of America")
country_names.append("USA")
country_names.sort()
country_names = [name.replace(".", "").replace(" ", "_") for name in country_names]

state_names = states_gdf["name"].values.tolist()

basemaps = list(geemap.basemaps)

Map = geemap.Map()

with col2:

    basemap = st.selectbox("Select a basemap", basemaps, index=basemaps.index("HYBRID"))
    Map.add_basemap(basemap)

    country = st.selectbox(
        "Select a country", country_names, index=country_names.index("USA")
    )

    if country == "USA":
        state = st.selectbox(
            "Select a state", state_names, index=state_names.index("Florida")
        )
        layer_name = state

        try:
            fc = ee.FeatureCollection(
                f"projects/sat-io/open-datasets/MSBuildings/US/{state}"
            )
        except:
            st.error("No data available for the selected state.")

    else:
        try:
            fc = ee.FeatureCollection(
                f"projects/sat-io/open-datasets/MSBuildings/{country}"
            )
        except:
            st.error("No data available for the selected country.")

        layer_name = country

    color = st.color_picker("Select a color", "#FF5500")

    style = {"fillColor": "00000000", "color": color}

    split = st.checkbox("Split-panel map")

    if split:
        left = geemap.ee_tile_layer(fc.style(**style), {}, "Left")
        right = left
        Map.split_map(left, right)
    else:
        Map.addLayer(fc.style(**style), {}, layer_name)

    Map.centerObject(fc.first(), zoom=16)

    with st.expander("Data Sources"):
        st.info(
            """
            [Microsoft Building Footprints](https://gee-community-catalog.org/projects/msbuildings/)
            """
        )


with col1:

    Map.to_streamlit(height=1000)