Spaces:
Sleeping
Sleeping
Added GEE apps
Browse files- app.py +2 -1
- apps/gee.py +120 -0
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from multiapp import MultiApp
|
3 |
-
from apps import basemaps, heatmap, home, census, deck, housing, upload
|
4 |
|
5 |
st.set_page_config(layout="wide")
|
6 |
|
@@ -16,6 +16,7 @@ apps.add_app("Upload Vector Data", upload.app)
|
|
16 |
apps.add_app("Search Basemaps", basemaps.app)
|
17 |
apps.add_app("Pydeck Gallery", deck.app)
|
18 |
apps.add_app("Heatmaps", heatmap.app)
|
|
|
19 |
|
20 |
# The main app
|
21 |
apps.run()
|
|
|
1 |
import streamlit as st
|
2 |
from multiapp import MultiApp
|
3 |
+
from apps import basemaps, heatmap, gee, home, census, deck, housing, upload
|
4 |
|
5 |
st.set_page_config(layout="wide")
|
6 |
|
|
|
16 |
apps.add_app("Search Basemaps", basemaps.app)
|
17 |
apps.add_app("Pydeck Gallery", deck.app)
|
18 |
apps.add_app("Heatmaps", heatmap.app)
|
19 |
+
apps.add_app("Google Earth Engine", gee.app)
|
20 |
|
21 |
# The main app
|
22 |
apps.run()
|
apps/gee.py
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import ee
|
2 |
+
import streamlit as st
|
3 |
+
import geemap.foliumap as geemap
|
4 |
+
|
5 |
+
|
6 |
+
def nlcd():
|
7 |
+
|
8 |
+
st.header("National Land Cover Database (NLCD)")
|
9 |
+
|
10 |
+
row1_col1, row1_col2 = st.columns([2, 1])
|
11 |
+
width = 950
|
12 |
+
height = 600
|
13 |
+
|
14 |
+
Map = geemap.Map()
|
15 |
+
|
16 |
+
# Select the seven NLCD epoches after 2000.
|
17 |
+
years = ["2001", "2004", "2006", "2008", "2011", "2013", "2016"]
|
18 |
+
|
19 |
+
# Get an NLCD image by year.
|
20 |
+
def getNLCD(year):
|
21 |
+
# Import the NLCD collection.
|
22 |
+
dataset = ee.ImageCollection("USGS/NLCD_RELEASES/2016_REL")
|
23 |
+
|
24 |
+
# Filter the collection by year.
|
25 |
+
nlcd = dataset.filter(ee.Filter.eq("system:index", year)).first()
|
26 |
+
|
27 |
+
# Select the land cover band.
|
28 |
+
landcover = nlcd.select("landcover")
|
29 |
+
return landcover
|
30 |
+
|
31 |
+
with row1_col2:
|
32 |
+
selected_year = st.multiselect("Select a year", years)
|
33 |
+
|
34 |
+
if selected_year:
|
35 |
+
for year in selected_year:
|
36 |
+
Map.addLayer(getNLCD(year), {}, "NLCD " + year)
|
37 |
+
|
38 |
+
Map.add_legend(
|
39 |
+
legend_title="NLCD Land Cover Classification", builtin_legend="NLCD"
|
40 |
+
)
|
41 |
+
with row1_col1:
|
42 |
+
Map.to_streamlit(width=width, height=height)
|
43 |
+
|
44 |
+
else:
|
45 |
+
with row1_col1:
|
46 |
+
Map.to_streamlit(width=width, height=height)
|
47 |
+
|
48 |
+
|
49 |
+
def search_data():
|
50 |
+
|
51 |
+
st.header("Search Earth Engine Data Catalog")
|
52 |
+
|
53 |
+
Map = geemap.Map()
|
54 |
+
|
55 |
+
if "ee_assets" not in st.session_state:
|
56 |
+
st.session_state["ee_assets"] = None
|
57 |
+
if "asset_titles" not in st.session_state:
|
58 |
+
st.session_state["asset_titles"] = None
|
59 |
+
|
60 |
+
col1, col2 = st.columns([1, 1])
|
61 |
+
|
62 |
+
dataset = None
|
63 |
+
with col2:
|
64 |
+
keyword = st.text_input("Enter a keyword to search (e.g., elevation)", "")
|
65 |
+
if keyword:
|
66 |
+
ee_assets = geemap.search_ee_data(keyword)
|
67 |
+
asset_titles = [x["title"] for x in ee_assets]
|
68 |
+
dataset = st.selectbox("Select a dataset", asset_titles)
|
69 |
+
if len(ee_assets) > 0:
|
70 |
+
st.session_state["ee_assets"] = ee_assets
|
71 |
+
st.session_state["asset_titles"] = asset_titles
|
72 |
+
|
73 |
+
if dataset is not None:
|
74 |
+
with st.expander("Show dataset details", True):
|
75 |
+
index = asset_titles.index(dataset)
|
76 |
+
html = geemap.ee_data_html(st.session_state["ee_assets"][index])
|
77 |
+
st.markdown(html, True)
|
78 |
+
|
79 |
+
ee_id = ee_assets[index]["ee_id_snippet"]
|
80 |
+
uid = ee_assets[index]["uid"]
|
81 |
+
st.markdown(f"""**Earth Engine Snippet:** `{ee_id}`""")
|
82 |
+
|
83 |
+
vis_params = st.text_input(
|
84 |
+
"Enter visualization parameters as a dictionary", {}
|
85 |
+
)
|
86 |
+
layer_name = st.text_input("Enter a layer name", uid)
|
87 |
+
button = st.button("Add dataset to map")
|
88 |
+
if button:
|
89 |
+
vis = {}
|
90 |
+
try:
|
91 |
+
if vis_params.strip() == "":
|
92 |
+
st.error("Please enter visualization parameters")
|
93 |
+
vis = eval(vis_params)
|
94 |
+
if not isinstance(vis, dict):
|
95 |
+
st.error("Visualization parameters must be a dictionary")
|
96 |
+
try:
|
97 |
+
Map.addLayer(eval(ee_id), vis, layer_name)
|
98 |
+
except Exception as e:
|
99 |
+
st.error(f"Error adding layer: {e}")
|
100 |
+
except Exception as e:
|
101 |
+
st.error(f"Invalid visualization parameters: {e}")
|
102 |
+
|
103 |
+
with col1:
|
104 |
+
Map.to_streamlit()
|
105 |
+
else:
|
106 |
+
with col1:
|
107 |
+
Map.to_streamlit()
|
108 |
+
|
109 |
+
|
110 |
+
def app():
|
111 |
+
st.title("Google Earth Engine Applications")
|
112 |
+
|
113 |
+
apps = ["National Land Cover Database (NLCD)", "Search Earth Engine Data Catalog"]
|
114 |
+
|
115 |
+
selected_app = st.selectbox("Select an app", apps)
|
116 |
+
|
117 |
+
if selected_app == "National Land Cover Database (NLCD)":
|
118 |
+
nlcd()
|
119 |
+
elif selected_app == "Search Earth Engine Data Catalog":
|
120 |
+
search_data()
|