Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import ee
|
2 |
+
import geemap.foliumap as geemap
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
ee.Initialize()
|
6 |
+
|
7 |
+
def generate_map(start_date, end_date, zoom, center_lat, center_lon):
|
8 |
+
Map = geemap.Map(center=[center_lat, center_lon], zoom=zoom)
|
9 |
+
|
10 |
+
# Load Landsat 8 ImageCollection filtered by date
|
11 |
+
landsat = (
|
12 |
+
ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
|
13 |
+
.filterDate(start_date, end_date)
|
14 |
+
.median()
|
15 |
+
)
|
16 |
+
|
17 |
+
# Visualization parameters
|
18 |
+
vis_params = {
|
19 |
+
"bands": ["SR_B4", "SR_B3", "SR_B2"], # Red, Green, Blue bands
|
20 |
+
"min": 0,
|
21 |
+
"max": 3000,
|
22 |
+
"gamma": 1.4,
|
23 |
+
}
|
24 |
+
|
25 |
+
# Add Landsat layer to the map
|
26 |
+
Map.addLayer(landsat, vis_params, "Landsat 8")
|
27 |
+
Map.addLayerControl() # Add layer controls
|
28 |
+
|
29 |
+
# Save the map as an HTML file
|
30 |
+
map_file = "map.html"
|
31 |
+
Map.save(map_file)
|
32 |
+
|
33 |
+
# Return the HTML file
|
34 |
+
return map_file
|
35 |
+
|
36 |
+
# Gradio interface
|
37 |
+
def render_map(start_date, end_date, zoom, center_lat, center_lon):
|
38 |
+
map_file = generate_map(start_date, end_date, zoom, center_lat, center_lon)
|
39 |
+
with open(map_file, "r", encoding="utf-8") as f:
|
40 |
+
html_content = f.read()
|
41 |
+
return html_content
|
42 |
+
|
43 |
+
# Gradio app
|
44 |
+
iface = gr.Interface(
|
45 |
+
fn=render_map,
|
46 |
+
inputs=[
|
47 |
+
gr.inputs.Textbox(label="Start Date (YYYY-MM-DD)", default="2021-01-01"),
|
48 |
+
gr.inputs.Textbox(label="End Date (YYYY-MM-DD)", default="2021-12-31"),
|
49 |
+
gr.inputs.Slider(label="Zoom Level", minimum=1, maximum=20, default=4),
|
50 |
+
gr.inputs.Number(label="Center Latitude", default=20.0),
|
51 |
+
gr.inputs.Number(label="Center Longitude", default=78.0),
|
52 |
+
],
|
53 |
+
outputs=gr.HTML(label="Interactive Map"),
|
54 |
+
title="Interactive Google Earth Engine Map",
|
55 |
+
description="Generate a responsive map using Landsat 8 data by specifying date range, zoom level, and center coordinates.",
|
56 |
+
)
|
57 |
+
|
58 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|