Spaces:
Running
Running
Update web app
Browse files- .gitignore +1 -0
- pages/01_leafmap.py +0 -33
- pages/01_morocco.py +121 -0
.gitignore
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
__pycache__/
|
3 |
*.py[cod]
|
4 |
*$py.class
|
|
|
5 |
|
6 |
# C extensions
|
7 |
*.so
|
|
|
2 |
__pycache__/
|
3 |
*.py[cod]
|
4 |
*$py.class
|
5 |
+
private/
|
6 |
|
7 |
# C extensions
|
8 |
*.so
|
pages/01_leafmap.py
DELETED
@@ -1,33 +0,0 @@
|
|
1 |
-
import leafmap
|
2 |
-
import solara
|
3 |
-
|
4 |
-
zoom = solara.reactive(2)
|
5 |
-
center = solara.reactive((20, 0))
|
6 |
-
|
7 |
-
|
8 |
-
class Map(leafmap.Map):
|
9 |
-
def __init__(self, **kwargs):
|
10 |
-
super().__init__(**kwargs)
|
11 |
-
# Add what you want below
|
12 |
-
self.add_stac_gui()
|
13 |
-
|
14 |
-
|
15 |
-
@solara.component
|
16 |
-
def Page():
|
17 |
-
with solara.Column(style={"min-width": "500px"}):
|
18 |
-
# solara components support reactive variables
|
19 |
-
# solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
|
20 |
-
# using 3rd party widget library require wiring up the events manually
|
21 |
-
# using zoom.value and zoom.set
|
22 |
-
Map.element( # type: ignore
|
23 |
-
zoom=zoom.value,
|
24 |
-
on_zoom=zoom.set,
|
25 |
-
center=center.value,
|
26 |
-
on_center=center.set,
|
27 |
-
scroll_wheel_zoom=True,
|
28 |
-
toolbar_ctrl=False,
|
29 |
-
data_ctrl=False,
|
30 |
-
height="780px",
|
31 |
-
)
|
32 |
-
# solara.Text(f"Zoom: {zoom.value}")
|
33 |
-
# solara.Text(f"Center: {center.value}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/01_morocco.py
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import leafmap
|
3 |
+
import solara
|
4 |
+
import ipyleaflet
|
5 |
+
import ipywidgets as widgets
|
6 |
+
import pandas as pd
|
7 |
+
|
8 |
+
url = 'https://open.gishub.org/maxar-open-data'
|
9 |
+
repo = 'https://github.com/opengeos/maxar-open-data/blob/master/datasets'
|
10 |
+
|
11 |
+
|
12 |
+
def get_datasets():
|
13 |
+
datasets = f'{url}/datasets.csv'
|
14 |
+
df = pd.read_csv(datasets)
|
15 |
+
return df
|
16 |
+
|
17 |
+
|
18 |
+
def get_catalogs(name):
|
19 |
+
dataset = f'{url}/datasets/{name}.tsv'
|
20 |
+
|
21 |
+
dataset_df = pd.read_csv(dataset, sep='\t')
|
22 |
+
catalog_ids = dataset_df['catalog_id'].unique().tolist()
|
23 |
+
catalog_ids.sort()
|
24 |
+
return catalog_ids
|
25 |
+
|
26 |
+
|
27 |
+
def update_geojson(m):
|
28 |
+
datasets = get_datasets()['dataset'].tolist()
|
29 |
+
|
30 |
+
style = {"description_width": "initial"}
|
31 |
+
padding = "0px 0px 0px 5px"
|
32 |
+
dataset = widgets.Dropdown(
|
33 |
+
options=datasets,
|
34 |
+
description='Event:',
|
35 |
+
value="Morocco-Earthquake-Sept-2023",
|
36 |
+
style=style,
|
37 |
+
layout=widgets.Layout(width="270px", padding=padding),
|
38 |
+
)
|
39 |
+
|
40 |
+
image = widgets.Dropdown(
|
41 |
+
value=None,
|
42 |
+
options=get_catalogs(dataset.value),
|
43 |
+
description='Image:',
|
44 |
+
style=style,
|
45 |
+
layout=widgets.Layout(width="270px", padding=padding),
|
46 |
+
)
|
47 |
+
|
48 |
+
checkbox = widgets.Checkbox(
|
49 |
+
value=True,
|
50 |
+
description='Show footprints',
|
51 |
+
style=style,
|
52 |
+
layout=widgets.Layout(width="130px", padding=padding),
|
53 |
+
)
|
54 |
+
|
55 |
+
def change_dataset(change):
|
56 |
+
default_geojson = f'{url}/datasets/{change.new}.geojson'
|
57 |
+
m.layers = m.layers[:2]
|
58 |
+
m.controls = m.controls[:-1]
|
59 |
+
m.add_geojson(default_geojson, layer_name='Footprint', zoom_to_layer=True)
|
60 |
+
image.options = get_catalogs(change.new)
|
61 |
+
|
62 |
+
dataset.observe(change_dataset, names='value')
|
63 |
+
|
64 |
+
def change_image(change):
|
65 |
+
if change.new:
|
66 |
+
mosaic = f'{url}/datasets/{dataset.value}/{image.value}.json'
|
67 |
+
m.add_stac_layer(mosaic, name=image.value)
|
68 |
+
|
69 |
+
image.observe(change_image, names='value')
|
70 |
+
|
71 |
+
def change_footprint(change):
|
72 |
+
geojson_layer = m.find_layer('Footprint')
|
73 |
+
if change.new:
|
74 |
+
geojson_layer.visible = True
|
75 |
+
else:
|
76 |
+
geojson_layer.visible = False
|
77 |
+
|
78 |
+
checkbox.observe(change_footprint, names='value')
|
79 |
+
|
80 |
+
event_control = ipyleaflet.WidgetControl(widget=dataset, position='topright')
|
81 |
+
image_control = ipyleaflet.WidgetControl(widget=image, position='topright')
|
82 |
+
checkbox_control = ipyleaflet.WidgetControl(widget=checkbox, position='topright')
|
83 |
+
m.add(event_control)
|
84 |
+
m.add(image_control)
|
85 |
+
m.add(checkbox_control)
|
86 |
+
|
87 |
+
|
88 |
+
zoom = solara.reactive(2)
|
89 |
+
center = solara.reactive((20, 0))
|
90 |
+
|
91 |
+
|
92 |
+
class Map(leafmap.Map):
|
93 |
+
def __init__(self, **kwargs):
|
94 |
+
kwargs['toolbar_control'] = False
|
95 |
+
super().__init__(**kwargs)
|
96 |
+
self.add_basemap('Esri.WorldImagery', show=False)
|
97 |
+
self.add_layer_manager(opened=False)
|
98 |
+
update_geojson(self)
|
99 |
+
default_geojson = f'{url}/datasets/Morocco-Earthquake-Sept-2023.geojson'
|
100 |
+
self.add_geojson(default_geojson, layer_name='Footprint', zoom_to_layer=True)
|
101 |
+
|
102 |
+
|
103 |
+
@solara.component
|
104 |
+
def Page():
|
105 |
+
with solara.Column(style={"min-width": "500px"}):
|
106 |
+
# solara components support reactive variables
|
107 |
+
# solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
|
108 |
+
# using 3rd party widget library require wiring up the events manually
|
109 |
+
# using zoom.value and zoom.set
|
110 |
+
Map.element( # type: ignore
|
111 |
+
zoom=zoom.value,
|
112 |
+
on_zoom=zoom.set,
|
113 |
+
center=center.value,
|
114 |
+
on_center=center.set,
|
115 |
+
scroll_wheel_zoom=True,
|
116 |
+
toolbar_ctrl=False,
|
117 |
+
data_ctrl=False,
|
118 |
+
height="780px",
|
119 |
+
)
|
120 |
+
# solara.Text(f"Zoom: {zoom.value}")
|
121 |
+
# solara.Text(f"Center: {center.value}")
|