kolibril13 giswqs commited on
Commit
1dbcc8d
0 Parent(s):

Duplicate from giswqs/solara-geospatial

Browse files

Co-authored-by: Qiusheng Wu <giswqs@users.noreply.huggingface.co>

.github/workflows/sync-hf.yml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face hub
2
+ on:
3
+ push:
4
+ branches: [main]
5
+
6
+ # to run this workflow manually from the Actions tab
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ sync-to-hub:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ with:
15
+ fetch-depth: 0
16
+ lfs: true
17
+ - name: Push to hub
18
+ env:
19
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
20
+ run: git push --force https://giswqs:$HF_TOKEN@huggingface.co/spaces/giswqs/solara-geospatial main
.gitignore ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
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/
Dockerfile ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM jupyter/base-notebook:latest
2
+
3
+ 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
+
10
+ RUN mkdir ./pages
11
+ COPY /pages ./pages
12
+
13
+ ENV PROJ_LIB='/opt/conda/share/proj'
14
+
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"]
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Open Geospatial Solutions
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Solara Geospatial
3
+ emoji: 🌍
4
+ colorFrom: green
5
+ colorTo: red
6
+ sdk: docker
7
+ pinned: false
8
+ license: mit
9
+ app_port: 8765
10
+ duplicated_from: giswqs/solara-geospatial
11
+ ---
12
+
13
+ ## Introduction
14
+
15
+ A collection of [Solara](https://github.com/widgetti/solara) web apps for geospatial applications
16
+
17
+ Just a proof-of-concept for now. Not all features are working yet. More features will be added in the future.
18
+
19
+ - Web App: <https://giswqs-solara-geospatial.hf.space>
20
+ - GitHub: <https://github.com/opengeos/solara-geospatial>
21
+ - Hugging Face: <https://huggingface.co/spaces/giswqs/solara-geospatial>
22
+
23
+ ## Demos
24
+
25
+ ![](https://i.imgur.com/4uIEnAJ.gif)
pages/00_home.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import solara
2
+
3
+ @solara.component
4
+ def Page():
5
+
6
+ markdown = """
7
+ ## Solara for Geospatial Applications
8
+
9
+ ### Introduction
10
+
11
+ **A collection of [Solara](https://github.com/widgetti/solara) web apps for geospatial applications.**
12
+
13
+ Just a proof-of-concept for now. Not all features are working yet. More features will be added in the future. Click on the menu above to see the other pages.
14
+
15
+ - Web App: <https://giswqs-solara-geospatial.hf.space>
16
+ - GitHub: <https://github.com/opengeos/solara-geospatial>
17
+ - Hugging Face: <https://huggingface.co/spaces/giswqs/solara-geospatial>
18
+
19
+ ### Demos
20
+
21
+ ![](https://i.imgur.com/4uIEnAJ.gif)
22
+
23
+ """
24
+
25
+ solara.Markdown(markdown)
pages/01_leafmap.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import leafmap
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
18
+ def Page():
19
+ with solara.Column(style={"min-width": "500px"}):
20
+ # solara components support reactive variables
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.element( # type: ignore
25
+ zoom=zoom.value,
26
+ on_zoom=zoom.set,
27
+ center=center.value,
28
+ on_center=center.set,
29
+ scroll_wheel_zoom=True,
30
+ toolbar_ctrl=False,
31
+ data_ctrl=False,
32
+
33
+ )
34
+ solara.Text(f"Zoom: {zoom.value}")
35
+ solara.Text(f"Center: {center.value}")
pages/02_geemap.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import ee
3
+ import geemap
4
+
5
+ import solara
6
+
7
+ zoom = solara.reactive(4)
8
+ center = solara.reactive([40, -100])
9
+
10
+
11
+ class Map(geemap.Map):
12
+ def __init__(self, **kwargs):
13
+ super().__init__(**kwargs)
14
+ self.add_ee_data()
15
+ self.add_layer_manager()
16
+ self.add_inspector()
17
+
18
+
19
+ def add_ee_data(self):
20
+
21
+ # Add Earth Engine dataset
22
+ dem = ee.Image('USGS/SRTMGL1_003')
23
+ landsat7 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003').select(
24
+ ['B1', 'B2', 'B3', 'B4', 'B5', 'B7']
25
+ )
26
+ states = ee.FeatureCollection("TIGER/2018/States")
27
+
28
+ # Set visualization parameters.
29
+ vis_params = {
30
+ 'min': 0,
31
+ 'max': 4000,
32
+ 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
33
+ }
34
+
35
+ # Add Earth Engine layers to Map
36
+ self.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)
37
+ self.addLayer(
38
+ landsat7,
39
+ {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma': 2.0},
40
+ 'Landsat 7', False
41
+ )
42
+ self.addLayer(states, {}, "US States")
43
+
44
+
45
+ @solara.component
46
+ def Page():
47
+ with solara.Column(style={"min-width": "500px"}):
48
+ # solara components support reactive variables
49
+ # solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
50
+ # using 3rd party widget library require wiring up the events manually
51
+ # using zoom.value and zoom.set
52
+ Map.element( # type: ignore
53
+ zoom=zoom.value,
54
+ on_zoom=zoom.set,
55
+ center=center.value,
56
+ on_center=center.set,
57
+ scroll_wheel_zoom=True,
58
+ add_google_map=True,
59
+ height="700px"
60
+
61
+ )
62
+ solara.Text(f"Zoom: {zoom.value}")
63
+ solara.Text(f"Center: {center.value}")
pages/03_mapbox.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import mapwidget.mapbox as mapwidget
3
+
4
+ import solara
5
+
6
+ zoom = solara.reactive(2)
7
+ center = solara.reactive((20, 0))
8
+
9
+
10
+ @solara.component
11
+ def Page():
12
+ with solara.Column(style={"min-width": "500px", "height": "500px"}):
13
+ solara.Text("Not fully working yet. Try resizing the window to use the full width.")
14
+ # solara components support reactive variables
15
+ solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
16
+ # using 3rd party widget library require wiring up the events manually
17
+ # using zoom.value and zoom.set
18
+ mapwidget.Map.element( # type: ignore
19
+ zoom=zoom.value,
20
+ center=center.value,
21
+ height='600px',
22
+ width="100%"
23
+ )
24
+ solara.Text(f"Zoom: {zoom.value}")
25
+ solara.Text(f"Center: {center.value}")
pages/04_cesium.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import os
3
+ import mapwidget.cesium as mapwidget
4
+
5
+ import solara
6
+
7
+ altitude = solara.reactive(400)
8
+ center = solara.reactive((37.655, -122.4175))
9
+
10
+ if os.environ.get('CESIUM_TOKEN') is None:
11
+ token = 'YOUR-CESIUM-TOKEN'
12
+ else:
13
+ token = os.environ.get('CESIUM_TOKEN')
14
+
15
+ @solara.component
16
+ def Page():
17
+ with solara.Column(style={"min-width": "500px", "height": "500px"}):
18
+ # solara components support reactive variables
19
+ solara.SliderInt(label="Zoom level", value=altitude, min=1, max=1000)
20
+ # using 3rd party widget library require wiring up the events manually
21
+ # using zoom.value and zoom.set
22
+ mapwidget.Map.element( # type: ignore
23
+ center=center.value,
24
+ altitude=altitude.value,
25
+ height='600px',
26
+ width="100%"
27
+ )
28
+
pages/05_maplibre.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import mapwidget.maplibre as mapwidget
3
+
4
+ import solara
5
+
6
+ zoom = solara.reactive(2)
7
+ center = solara.reactive((20, 0))
8
+
9
+
10
+ @solara.component
11
+ def Page():
12
+ with solara.Column(style={"min-width": "500px", "height": "500px"}):
13
+ solara.Text("Not fully working yet. Try resizing the window to use the full width.")
14
+
15
+ # solara components support reactive variables
16
+ solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
17
+ # using 3rd party widget library require wiring up the events manually
18
+ # using zoom.value and zoom.set
19
+ mapwidget.Map.element( # type: ignore
20
+ zoom=zoom.value,
21
+ center=center.value,
22
+ height='600px',
23
+ width="100%"
24
+ )
25
+ solara.Text(f"Zoom: {zoom.value}")
26
+ solara.Text(f"Center: {center.value}")
pages/06_openlayers.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import mapwidget.openlayers as mapwidget
3
+
4
+ import solara
5
+
6
+ zoom = solara.reactive(5)
7
+ center = solara.reactive((53.2305799, 6.5323552))
8
+
9
+
10
+ @solara.component
11
+ def Page():
12
+ with solara.Column(style={"min-width": "500px", "height": "500px"}):
13
+ # solara components support reactive variables
14
+ solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
15
+ # using 3rd party widget library require wiring up the events manually
16
+ # using zoom.value and zoom.set
17
+ mapwidget.Map.element( # type: ignore
18
+ zoom=zoom.value,
19
+ center=center.value,
20
+ height='600px',
21
+ width="100%"
22
+ )
23
+ # solara.Text(f"Zoom: {zoom.value}")
24
+ # solara.Text(f"Center: {center.value}")
pages/07_ipyleaflet.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ipyleaflet
2
+ import solara
3
+ import ipywidgets as widgets
4
+
5
+ zoom = solara.reactive(2)
6
+ center = solara.reactive((20, 0))
7
+
8
+
9
+ class Map(ipyleaflet.Map):
10
+ def __init__(self, **kwargs):
11
+ super().__init__(**kwargs)
12
+ self.layout.height = '600px'
13
+ # Add what you want below
14
+
15
+ label = widgets.Label('Clicked location')
16
+ output = widgets.Output()
17
+ widget = widgets.VBox([label, output])
18
+ control = ipyleaflet.WidgetControl(widget=widget, position='bottomright')
19
+ self.add_control(control)
20
+
21
+ def handle_interaction(**kwargs):
22
+ latlon = kwargs.get("coordinates")
23
+ if kwargs.get("type") == "click":
24
+ with output:
25
+ output.clear_output()
26
+ print(latlon)
27
+
28
+ self.on_interaction(handle_interaction)
29
+
30
+
31
+ @solara.component
32
+ def Page():
33
+ with solara.Column(style={"min-width": "500px"}):
34
+ solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
35
+ Map.element(
36
+ zoom=zoom.value,
37
+ on_zoom=zoom.set,
38
+ center=center.value,
39
+ on_center=center.set,
40
+ scroll_wheel_zoom=True,
41
+
42
+ )
43
+ solara.Text(f"Zoom: {zoom.value}")
44
+ solara.Text(f"Center: {center.value}")
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ geemap>=0.21.0
2
+ leafmap
3
+ mapwidget
4
+ solara
5
+ geopandas