Spaces:
Build error
Build error
Kelbec
commited on
Commit
·
0b48bca
1
Parent(s):
cb2bdbd
leafmap and controls
Browse files- .gitignore +2 -0
- Dockerfile +8 -1
- pages/01_leafmap.py +189 -7
.gitignore
CHANGED
@@ -158,3 +158,5 @@ cython_debug/
|
|
158 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
#.idea/
|
|
|
|
|
|
158 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
#.idea/
|
161 |
+
|
162 |
+
/public
|
Dockerfile
CHANGED
@@ -4,6 +4,13 @@ RUN mamba install -c conda-forge leafmap geopandas localtileserver -y && \
|
|
4 |
fix-permissions "${CONDA_DIR}" && \
|
5 |
fix-permissions "/home/${NB_USER}"
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
COPY requirements.txt .
|
8 |
RUN pip install -r requirements.txt
|
9 |
|
@@ -15,7 +22,7 @@ ENV PROJ_LIB='/opt/conda/share/proj'
|
|
15 |
USER root
|
16 |
RUN chown -R ${NB_UID} ${HOME}
|
17 |
USER ${NB_USER}
|
18 |
-
|
19 |
EXPOSE 8765
|
20 |
|
21 |
CMD ["solara", "run", "./pages", "--host=0.0.0.0"]
|
|
|
4 |
fix-permissions "${CONDA_DIR}" && \
|
5 |
fix-permissions "/home/${NB_USER}"
|
6 |
|
7 |
+
USER root
|
8 |
+
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
|
9 |
+
RUN apt-get install -y gdal-bin libgdal-dev
|
10 |
+
RUN export CPLUS_INCLUDE_PATH=/usr/include/gdal
|
11 |
+
RUN export C_INCLUDE_PATH=/usr/include/gdal
|
12 |
+
RUN pip install GDAL==3.4.3
|
13 |
+
RUN pip install git+https://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@github.com/saferplaces/dcascade_py.git@development
|
14 |
COPY requirements.txt .
|
15 |
RUN pip install -r requirements.txt
|
16 |
|
|
|
22 |
USER root
|
23 |
RUN chown -R ${NB_UID} ${HOME}
|
24 |
USER ${NB_USER}
|
25 |
+
RUN mkdir ./public
|
26 |
EXPOSE 8765
|
27 |
|
28 |
CMD ["solara", "run", "./pages", "--host=0.0.0.0"]
|
pages/01_leafmap.py
CHANGED
@@ -1,17 +1,124 @@
|
|
1 |
-
import
|
|
|
|
|
|
|
|
|
|
|
2 |
import solara
|
3 |
from leafmap.toolbar import change_basemap
|
|
|
|
|
4 |
|
5 |
zoom = solara.reactive(2)
|
6 |
center = solara.reactive((20, 0))
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
class Map(leafmap.Map):
|
10 |
def __init__(self, **kwargs):
|
11 |
super().__init__(**kwargs)
|
12 |
# Add what you want below
|
13 |
-
self.add_basemap("OpenTopoMap")
|
14 |
-
change_basemap(self)
|
|
|
15 |
|
16 |
|
17 |
@solara.component
|
@@ -21,7 +128,8 @@ def Page():
|
|
21 |
# solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
|
22 |
# using 3rd party widget library require wiring up the events manually
|
23 |
# using zoom.value and zoom.set
|
24 |
-
Map
|
|
|
25 |
zoom=zoom.value,
|
26 |
on_zoom=zoom.set,
|
27 |
center=center.value,
|
@@ -30,5 +138,79 @@ def Page():
|
|
30 |
toolbar_ctrl=False,
|
31 |
data_ctrl=False,
|
32 |
)
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from pathlib import Path
|
3 |
+
from typing import Callable, Optional, Union, cast
|
4 |
+
# import leafmap
|
5 |
+
import textwrap
|
6 |
+
import leafmap.kepler as leafmap
|
7 |
import solara
|
8 |
from leafmap.toolbar import change_basemap
|
9 |
+
from solara.components.file_drop import FileInfo
|
10 |
+
from dcascade import main as dcascade_main
|
11 |
|
12 |
zoom = solara.reactive(2)
|
13 |
center = solara.reactive((20, 0))
|
14 |
+
config = {'version': 'v1',
|
15 |
+
'config': {'visState': {'filters': [{'dataId': ['Countries'],
|
16 |
+
'id': '58woufh3',
|
17 |
+
'name': ['ts'],
|
18 |
+
'type': 'range',
|
19 |
+
'value': [0, 1.68], ###time change here
|
20 |
+
'enlarged': False,
|
21 |
+
'plotType': 'histogram',
|
22 |
+
'animationWindow': 'free',
|
23 |
+
'yAxis': None,
|
24 |
+
'speed': 1}],
|
25 |
+
'layers': [{'id': 'lqz57i8',
|
26 |
+
'type': 'geojson',
|
27 |
+
'config': {'dataId': 'Countries',
|
28 |
+
'label': 'Countries',
|
29 |
+
'color': [18, 147, 154],
|
30 |
+
'highlightColor': [252, 242, 26, 255],
|
31 |
+
'columns': {'geojson': '_geojson'},
|
32 |
+
'isVisible': True,
|
33 |
+
'visConfig': {'opacity': 0.8,
|
34 |
+
'strokeOpacity': 0.3,
|
35 |
+
'thickness': 1,
|
36 |
+
'strokeColor': [210, 0, 0],
|
37 |
+
'colorRange': {'name': 'Global Warming',
|
38 |
+
'type': 'sequential',
|
39 |
+
'category': 'Uber',
|
40 |
+
'colors': ['#5A1846',
|
41 |
+
'#900C3F',
|
42 |
+
'#C70039',
|
43 |
+
'#E3611C',
|
44 |
+
'#F1920E',
|
45 |
+
'#FFC300']},
|
46 |
+
'strokeColorRange': {'name': 'Ice And Fire',
|
47 |
+
'type': 'diverging',
|
48 |
+
'category': 'Uber',
|
49 |
+
'colors': ['#0198BD',
|
50 |
+
'#49E3CE',
|
51 |
+
'#E8FEB5',
|
52 |
+
'#FEEDB1',
|
53 |
+
'#FEAD54',
|
54 |
+
'#D50255']},
|
55 |
+
'radius': 10,
|
56 |
+
'sizeRange': [0, 10],
|
57 |
+
'radiusRange': [0, 50],
|
58 |
+
'heightRange': [0, 500],
|
59 |
+
'elevationScale': 5,
|
60 |
+
'enableElevationZoomFactor': True,
|
61 |
+
'stroked': True,
|
62 |
+
'filled': False,
|
63 |
+
'enable3d': False,
|
64 |
+
'wireframe': False},
|
65 |
+
'hidden': False,
|
66 |
+
'textLabel': [{'field': None,
|
67 |
+
'color': [255, 255, 255],
|
68 |
+
'size': 18,
|
69 |
+
'offset': [0, 0],
|
70 |
+
'anchor': 'start',
|
71 |
+
'alignment': 'center'}]},
|
72 |
+
'visualChannels': {'colorField': None,
|
73 |
+
'colorScale': 'quantile',
|
74 |
+
'strokeColorField': {'name': 'Discharge', 'type': 'real'},
|
75 |
+
'strokeColorScale': 'quantize',
|
76 |
+
'sizeField': None,
|
77 |
+
'sizeScale': 'linear',
|
78 |
+
'heightField': None,
|
79 |
+
'heightScale': 'linear',
|
80 |
+
'radiusField': None,
|
81 |
+
'radiusScale': 'linear'}}],
|
82 |
+
'interactionConfig': {'tooltip': {'fieldsToShow': {'Countries': [{'name': 'ts',
|
83 |
+
'format': None},
|
84 |
+
{'name': 'Discharge', 'format': None}]},
|
85 |
+
'compareMode': False,
|
86 |
+
'compareType': 'absolute',
|
87 |
+
'enabled': True},
|
88 |
+
'brush': {'size': 0.5, 'enabled': False},
|
89 |
+
'geocoder': {'enabled': False},
|
90 |
+
'coordinate': {'enabled': False}},
|
91 |
+
'layerBlending': 'additive',
|
92 |
+
'splitMaps': [],
|
93 |
+
'animationConfig': {'currentTime': None, 'speed': 1}},
|
94 |
+
'mapState': {'bearing': 0,
|
95 |
+
'dragRotate': False,
|
96 |
+
'latitude': 40.24060796334474,
|
97 |
+
'longitude': 20.565835594966174,
|
98 |
+
'pitch': 0,
|
99 |
+
'zoom': 8.776177236597563,
|
100 |
+
'isSplit': False},
|
101 |
+
'mapStyle': {'styleType': 'dark',
|
102 |
+
'topLayerGroups': {},
|
103 |
+
'visibleLayerGroups': {'label': True,
|
104 |
+
'road': True,
|
105 |
+
'border': False,
|
106 |
+
'building': True,
|
107 |
+
'water': True,
|
108 |
+
'land': True,
|
109 |
+
'3d building': False},
|
110 |
+
'threeDBuildingColor': [9.665468314072013,
|
111 |
+
17.18305478057247,
|
112 |
+
31.1442867897876],
|
113 |
+
'mapStyles': {}}}}
|
114 |
|
115 |
class Map(leafmap.Map):
|
116 |
def __init__(self, **kwargs):
|
117 |
super().__init__(**kwargs)
|
118 |
# Add what you want below
|
119 |
+
# self.add_basemap("OpenTopoMap")
|
120 |
+
# change_basemap(self)
|
121 |
+
# self.add_shp()
|
122 |
|
123 |
|
124 |
@solara.component
|
|
|
128 |
# solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
|
129 |
# using 3rd party widget library require wiring up the events manually
|
130 |
# using zoom.value and zoom.set
|
131 |
+
m = Map()
|
132 |
+
m.element( # type: ignore
|
133 |
zoom=zoom.value,
|
134 |
on_zoom=zoom.set,
|
135 |
center=center.value,
|
|
|
138 |
toolbar_ctrl=False,
|
139 |
data_ctrl=False,
|
140 |
)
|
141 |
+
m.config = config
|
142 |
+
|
143 |
+
# solara.Text(f"Zoom: {zoom.value}")
|
144 |
+
# solara.Text(f"Center: {center.value}")
|
145 |
+
|
146 |
+
content, set_content = solara.use_state(b"")
|
147 |
+
filename, set_filename = solara.use_state("")
|
148 |
+
size, set_size = solara.use_state(0)
|
149 |
+
file_browser, set_file_browser = solara.use_state(cast(Optional[Path], None))
|
150 |
+
|
151 |
+
|
152 |
+
def on_file(file: FileInfo):
|
153 |
+
set_filename(file["name"])
|
154 |
+
set_size(file["size"])
|
155 |
+
f = file["file_obj"]
|
156 |
+
set_content(f.read())
|
157 |
+
|
158 |
+
def upload_file():
|
159 |
+
if content:
|
160 |
+
file_path = os.path.join("public",filename)
|
161 |
+
with open(file_path,"wb") as file:
|
162 |
+
file.write(content)
|
163 |
+
|
164 |
+
def open_file():
|
165 |
+
print(type(str(file_browser)))
|
166 |
+
if file_browser:
|
167 |
+
file_path = os.path.join("public",file_browser)
|
168 |
+
with open(file_path,"wb") as file:
|
169 |
+
file.write(content)
|
170 |
+
# m.add_shp(str(file_browser), "Countries")
|
171 |
+
|
172 |
+
def run_dcascade():
|
173 |
+
file_river = os.getcwd()+"/public/River_Network.shp"
|
174 |
+
file_q = os.getcwd()+"/public/Q_Vjosa.csv"
|
175 |
+
print(os.getcwd())
|
176 |
+
print(os.listdir(os.getcwd()+"/public"))
|
177 |
+
print(file_river)
|
178 |
+
print(os.path.exists(Path(file_river)))
|
179 |
+
dcascade_main.main(river=file_river, q=file_q,timescale=20, formula=3, partitioning=4, out="public/deposito.shp", version=False, verbose=False, debug=False, credits=False)
|
180 |
+
# m = leafmap.Map.element(center=[20, 0], zoom=1)
|
181 |
+
m.add_shp("public/deposito.shp", "Countries")
|
182 |
+
m.config = config
|
183 |
+
m
|
184 |
+
|
185 |
+
with solara.Div() as main:
|
186 |
+
|
187 |
+
with solara.Card("Upload files and run dcascade"):
|
188 |
+
solara.FileDrop(
|
189 |
+
label="Drag and drop a file here to read the first 100 bytes",
|
190 |
+
on_file=on_file,
|
191 |
+
lazy=True,
|
192 |
+
)
|
193 |
+
with solara.ColumnsResponsive(6, large=4):
|
194 |
+
solara.Button("Upload file",
|
195 |
+
color="primary",
|
196 |
+
on_click=upload_file)
|
197 |
+
# solara.Button("Open file",
|
198 |
+
# color="primary",
|
199 |
+
# on_click=open_file)
|
200 |
+
solara.Button("DCASCADE",
|
201 |
+
color="primary",
|
202 |
+
on_click=run_dcascade)
|
203 |
+
if content:
|
204 |
+
solara.Info(f"File {filename} has total length: {size}\n, first 100 bytes:")
|
205 |
+
# solara.Preformatted("\n".join(textwrap.wrap(repr(content))))
|
206 |
+
solara.Preformatted("\n".join(textwrap.wrap(repr(filename))))
|
207 |
+
|
208 |
+
|
209 |
+
|
210 |
+
solara.FileBrowser(
|
211 |
+
can_select=False,
|
212 |
+
on_file_open=set_file_browser
|
213 |
+
)
|
214 |
+
# solara.Info(f"You are in directory: {directory}")
|
215 |
+
# solara.Info(f"You selected path: {path}")
|
216 |
+
# solara.Info(f"You opened file: {file}")
|