giswqs commited on
Commit
84e6e82
1 Parent(s): 6581617

Initial commit

Browse files
README.md CHANGED
@@ -1,13 +1,12 @@
1
  ---
2
- title: Solara Template
3
  emoji: 🏃
4
  colorFrom: blue
5
- colorTo: green
6
  sdk: docker
7
  pinned: false
8
  license: mit
9
  app_port: 8765
10
- duplicated_from: giswqs/solara-template
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Solara Geemap
3
  emoji: 🏃
4
  colorFrom: blue
5
+ colorTo: purple
6
  sdk: docker
7
  pinned: false
8
  license: mit
9
  app_port: 8765
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
pages/00_home.py CHANGED
@@ -5,15 +5,47 @@ import solara
5
  def Page():
6
  with solara.Column(align="center"):
7
  markdown = """
8
- ## A Solara Template for Geospatial Applications
9
 
10
  ### Introduction
11
 
12
- **A collection of [Solara](https://github.com/widgetti/solara) web apps for geospatial applications.**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- - Web App: <https://giswqs-solara-template.hf.space>
15
- - GitHub: <https://github.com/opengeos/solara-template>
16
- - Hugging Face: <https://huggingface.co/spaces/giswqs/solara-template>
17
 
18
  """
19
 
 
5
  def Page():
6
  with solara.Column(align="center"):
7
  markdown = """
8
+ ## Earth Engine Web Apps
9
 
10
  ### Introduction
11
 
12
+ **A collection of Earth Engine web apps developed using [Solara](https://github.com/widgetti/solara) and geemap**
13
+
14
+ - Web App: <https://giswqs-solara-geemap.hf.space>
15
+ - GitHub: <https://github.com/opengeos/solara-geemap>
16
+ - Hugging Face: <https://huggingface.co/spaces/giswqs/solara-geemap>
17
+
18
+
19
+ ### How to deploy this app on Hugging Face Spaces
20
+
21
+ 1. Go to <https://huggingface.co/spaces/giswqs/voila-geospatial/tree/main> and duplicate the space to your own space.
22
+
23
+ ![](https://i.imgur.com/4ib5BzB.png)
24
+
25
+ 2. Set environment variables as needed. For example, if you use Google Earth Engine, you need to set `EARTHENGINE_TOKEN` to your Earth Engine token. The token value should be copied from the following file depending on your operating system:
26
+
27
+ ```text
28
+ Windows: C:\\Users\\USERNAME\\.config\\earthengine\\credentials
29
+ Linux: /home/USERNAME/.config/earthengine/credentials
30
+ MacOS: /Users/USERNAME/.config/earthengine/credentials
31
+ ```
32
+
33
+ Simply open the file and copy **ALL** the content to the `EARTHENGINE_TOKEN` environment variable.
34
+
35
+ ![](https://i.imgur.com/i04gzyH.png)
36
+
37
+ ![](https://i.imgur.com/Ex37Ut7.png)
38
+
39
+ 3. After the space is built successfully, click the `Embed this Space` menu and find the `Direct URL` for the app, such as <https://giswqs-voila-geospatial.hf.space>.
40
+
41
+ ![](https://i.imgur.com/V2Lp0dP.png)
42
+
43
+ ![](https://i.imgur.com/klhR5FL.png)
44
+
45
+ 4. Add your own notebooks to the `notebooks` folder and wait for the app to be rebuilt.
46
+
47
+ 5. To hide the source code from the notebook, modify `run.sh` and set `--strip_sources=True`.
48
 
 
 
 
49
 
50
  """
51
 
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/02_inspector.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ee
2
+ import geemap
3
+
4
+ import solara
5
+
6
+
7
+ class Map(geemap.Map):
8
+ def __init__(self, **kwargs):
9
+ super().__init__(**kwargs)
10
+ self.add_ee_data()
11
+ self.add_layer_manager()
12
+ self.add_inspector()
13
+
14
+ def add_ee_data(self):
15
+ # Add Earth Engine dataset
16
+ dem = ee.Image('USGS/SRTMGL1_003')
17
+ landsat7 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003').select(
18
+ ['B1', 'B2', 'B3', 'B4', 'B5', 'B7']
19
+ )
20
+ states = ee.FeatureCollection("TIGER/2018/States")
21
+
22
+ # Set visualization parameters.
23
+ vis_params = {
24
+ 'min': 0,
25
+ 'max': 4000,
26
+ 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
27
+ }
28
+
29
+ # Add Earth Engine layers to Map
30
+ self.addLayer(
31
+ landsat7,
32
+ {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma': 2.0},
33
+ 'Landsat 7',
34
+ True,
35
+ )
36
+ self.addLayer(dem, vis_params, 'SRTM DEM', True, 1)
37
+ self.addLayer(states, {}, "US States")
38
+
39
+
40
+ @solara.component
41
+ def Page():
42
+ with solara.Column(style={"min-width": "500px"}):
43
+ Map.element(
44
+ center=[40, -100],
45
+ zoom=4,
46
+ height="800px",
47
+ )
pages/03_plotting.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ee
2
+ import geemap
3
+
4
+ import solara
5
+
6
+
7
+ class Map(geemap.Map):
8
+ def __init__(self, **kwargs):
9
+ super().__init__(**kwargs)
10
+ self.add_ee_data()
11
+ self.add_plot_gui()
12
+
13
+ def add_ee_data(self):
14
+ landsat7 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003').select(
15
+ ['B1', 'B2', 'B3', 'B4', 'B5', 'B7']
16
+ )
17
+
18
+ landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.4}
19
+ self.addLayer(landsat7, landsat_vis, "Landsat")
20
+
21
+ hyperion = ee.ImageCollection('EO1/HYPERION').filter(
22
+ ee.Filter.date('2016-01-01', '2017-03-01')
23
+ )
24
+
25
+ hyperion_vis = {
26
+ 'min': 1000.0,
27
+ 'max': 14000.0,
28
+ 'gamma': 2.5,
29
+ }
30
+ self.addLayer(hyperion, hyperion_vis, 'Hyperion')
31
+
32
+
33
+ @solara.component
34
+ def Page():
35
+ with solara.Column(style={"min-width": "500px"}):
36
+ Map.element(
37
+ center=[40, -100],
38
+ zoom=4,
39
+ height="800px",
40
+ )
pages/04_split_map.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ee
2
+ import geemap
3
+
4
+ import solara
5
+
6
+
7
+ class Map(geemap.Map):
8
+ def __init__(self, **kwargs):
9
+ super().__init__(**kwargs)
10
+ self.add_ee_data()
11
+
12
+ def add_ee_data(self):
13
+ # Select the eight NLCD epochs after 2000.
14
+ years = ['2001', '2004', '2006', '2008', '2011', '2013', '2016', '2019']
15
+
16
+ # Get an NLCD image by year.
17
+ def getNLCD(year):
18
+ # Import the NLCD collection.
19
+ dataset = ee.ImageCollection('USGS/NLCD_RELEASES/2019_REL/NLCD')
20
+
21
+ # Filter the collection by year.
22
+ nlcd = dataset.filter(ee.Filter.eq('system:index', year)).first()
23
+
24
+ # Select the land cover band.
25
+ landcover = nlcd.select('landcover')
26
+ return landcover
27
+
28
+ ## Create an NLCD image collection for the selected years.
29
+ collection = ee.ImageCollection(ee.List(years).map(lambda year: getNLCD(year)))
30
+
31
+ # Create a list of labels to populate the dropdown list.
32
+ labels = [f'NLCD {year}' for year in years]
33
+
34
+ # Add a split-panel map for visualizing NLCD land cover change.
35
+ self.ts_inspector(
36
+ left_ts=collection,
37
+ right_ts=collection,
38
+ left_names=labels,
39
+ right_names=labels,
40
+ )
41
+
42
+ # Add the NLCD legend to the map.
43
+ self.add_legend(
44
+ title='NLCD Land Cover Type', builtin_legend='NLCD', height="460px"
45
+ )
46
+
47
+
48
+ @solara.component
49
+ def Page():
50
+ with solara.Column(style={"min-width": "500px"}):
51
+ Map.element(
52
+ center=[40, -100],
53
+ zoom=4,
54
+ height="800px",
55
+ )