Spaces:
Runtime error
Runtime error
File size: 1,936 Bytes
7c43ab3 5988513 d2e4717 7c43ab3 |
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 |
import ee
import geemap.foliumap as geemap
import gradio as gr
ee.Authenticate
ee.Initialize(project='august-tract-445517-i2')
def generate_map(start_date, end_date, zoom, center_lat, center_lon):
Map = geemap.Map(center=[center_lat, center_lon], zoom=zoom)
# Load Landsat 8 ImageCollection filtered by date
landsat = (
ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
.filterDate(start_date, end_date)
.median()
)
# Visualization parameters
vis_params = {
"bands": ["SR_B4", "SR_B3", "SR_B2"], # Red, Green, Blue bands
"min": 0,
"max": 3000,
"gamma": 1.4,
}
# Add Landsat layer to the map
Map.addLayer(landsat, vis_params, "Landsat 8")
Map.addLayerControl() # Add layer controls
# Save the map as an HTML file
map_file = "map.html"
Map.save(map_file)
# Return the HTML file
return map_file
# Gradio interface
def render_map(start_date, end_date, zoom, center_lat, center_lon):
map_file = generate_map(start_date, end_date, zoom, center_lat, center_lon)
with open(map_file, "r", encoding="utf-8") as f:
html_content = f.read()
return html_content
# Gradio app
iface = gr.Interface(
fn=render_map,
inputs=[
gr.inputs.Textbox(label="Start Date (YYYY-MM-DD)", default="2021-01-01"),
gr.inputs.Textbox(label="End Date (YYYY-MM-DD)", default="2021-12-31"),
gr.inputs.Slider(label="Zoom Level", minimum=1, maximum=20, default=4),
gr.inputs.Number(label="Center Latitude", default=20.0),
gr.inputs.Number(label="Center Longitude", default=78.0),
],
outputs=gr.HTML(label="Interactive Map"),
title="Interactive Google Earth Engine Map",
description="Generate a responsive map using Landsat 8 data by specifying date range, zoom level, and center coordinates.",
)
iface.launch(server_name="0.0.0.0", server_port=7860) |