giswqs commited on
Commit
c54a043
β€’
1 Parent(s): 7ae2447

Fit GitHub vulnerability

Browse files
pages/10_🌍_Earth_Engine_Datasets.py CHANGED
@@ -1,4 +1,5 @@
1
  import ee
 
2
  import streamlit as st
3
  import geemap.foliumap as geemap
4
 
@@ -79,8 +80,7 @@ def search_data():
79
 
80
  dataset = None
81
  with col2:
82
- keyword = st.text_input(
83
- "Enter a keyword to search (e.g., elevation)", "")
84
  if keyword:
85
  ee_assets = geemap.search_ee_data(keyword)
86
  asset_titles = [x["title"] for x in ee_assets]
@@ -102,8 +102,7 @@ def search_data():
102
  with st.expander("Show dataset details", True):
103
  index = asset_titles.index(dataset)
104
 
105
- html = geemap.ee_data_html(
106
- st.session_state["ee_assets"][index])
107
  html = html.replace("\n", "")
108
  st.markdown(html, True)
109
 
@@ -111,6 +110,14 @@ def search_data():
111
  uid = ee_assets[index]["uid"]
112
  st.markdown(f"""**Earth Engine Snippet:** `{ee_id}`""")
113
  ee_asset = f"{translate[asset_types[index]]}{ee_id}')"
 
 
 
 
 
 
 
 
114
  vis_params = st.text_input(
115
  "Enter visualization parameters as a dictionary", {}
116
  )
@@ -122,12 +129,11 @@ def search_data():
122
  if vis_params.strip() == "":
123
  # st.error("Please enter visualization parameters")
124
  vis_params = "{}"
125
- vis = eval(vis_params)
126
  if not isinstance(vis, dict):
127
- st.error(
128
- "Visualization parameters must be a dictionary")
129
  try:
130
- Map.addLayer(eval(ee_asset), vis, layer_name)
131
  except Exception as e:
132
  st.error(f"Error adding layer: {e}")
133
  except Exception as e:
@@ -143,8 +149,7 @@ def search_data():
143
  def app():
144
  st.title("Earth Engine Data Catalog")
145
 
146
- apps = ["Search Earth Engine Data Catalog",
147
- "National Land Cover Database (NLCD)"]
148
 
149
  selected_app = st.selectbox("Select an app", apps)
150
 
 
1
  import ee
2
+ import json
3
  import streamlit as st
4
  import geemap.foliumap as geemap
5
 
 
80
 
81
  dataset = None
82
  with col2:
83
+ keyword = st.text_input("Enter a keyword to search (e.g., elevation)", "")
 
84
  if keyword:
85
  ee_assets = geemap.search_ee_data(keyword)
86
  asset_titles = [x["title"] for x in ee_assets]
 
102
  with st.expander("Show dataset details", True):
103
  index = asset_titles.index(dataset)
104
 
105
+ html = geemap.ee_data_html(st.session_state["ee_assets"][index])
 
106
  html = html.replace("\n", "")
107
  st.markdown(html, True)
108
 
 
110
  uid = ee_assets[index]["uid"]
111
  st.markdown(f"""**Earth Engine Snippet:** `{ee_id}`""")
112
  ee_asset = f"{translate[asset_types[index]]}{ee_id}')"
113
+
114
+ if ee_asset.startswith("ee.ImageCollection"):
115
+ ee_asset = ee.ImageCollection(ee_id)
116
+ elif ee_asset.startswith("ee.Image"):
117
+ ee_asset = ee.Image(ee_id)
118
+ elif ee_asset.startswith("ee.FeatureCollection"):
119
+ ee_asset = ee.FeatureCollection(ee_id)
120
+
121
  vis_params = st.text_input(
122
  "Enter visualization parameters as a dictionary", {}
123
  )
 
129
  if vis_params.strip() == "":
130
  # st.error("Please enter visualization parameters")
131
  vis_params = "{}"
132
+ vis = json.loads(vis_params.replace("'", '"'))
133
  if not isinstance(vis, dict):
134
+ st.error("Visualization parameters must be a dictionary")
 
135
  try:
136
+ Map.addLayer(ee_asset, vis, layer_name)
137
  except Exception as e:
138
  st.error(f"Error adding layer: {e}")
139
  except Exception as e:
 
149
  def app():
150
  st.title("Earth Engine Data Catalog")
151
 
152
+ apps = ["Search Earth Engine Data Catalog", "National Land Cover Database (NLCD)"]
 
153
 
154
  selected_app = st.selectbox("Select an app", apps)
155
 
pages/13_🏘️_Global_Building_Footprints.py CHANGED
@@ -6,7 +6,6 @@ import streamlit as st
6
  st.set_page_config(layout="wide")
7
 
8
 
9
- @st.cache(persist=True)
10
  def ee_authenticate(token_name="EARTHENGINE_TOKEN"):
11
  geemap.ee_initialize(token_name=token_name)
12
 
 
6
  st.set_page_config(layout="wide")
7
 
8
 
 
9
  def ee_authenticate(token_name="EARTHENGINE_TOKEN"):
10
  geemap.ee_initialize(token_name=token_name)
11
 
pages/1_πŸ“·_Timelapse.py CHANGED
@@ -1,4 +1,5 @@
1
  import ee
 
2
  import os
3
  import warnings
4
  import datetime
@@ -235,8 +236,8 @@ def app():
235
 
236
  st.markdown(
237
  """
238
- An interactive web app for creating [Landsat](https://developers.google.com/earth-engine/datasets/catalog/landsat)/[GOES](https://jstnbraaten.medium.com/goes-in-earth-engine-53fbc8783c16) timelapse for any location around the globe.
239
- The app was built using [streamlit](https://streamlit.io), [geemap](https://geemap.org), and [Google Earth Engine](https://earthengine.google.com). For more info, check out my streamlit [blog post](https://blog.streamlit.io/creating-satellite-timelapse-with-streamlit-and-earth-engine).
240
  """
241
  )
242
 
@@ -376,7 +377,9 @@ def app():
376
  st.write(
377
  cm.plot_colormap(cmap=palette_options, return_fig=True)
378
  )
379
- st.session_state["palette"] = eval(palette)
 
 
380
 
381
  if bands:
382
  vis_params = st.text_area(
@@ -391,7 +394,9 @@ def app():
391
  "{}",
392
  )
393
  try:
394
- st.session_state["vis_params"] = eval(vis_params)
 
 
395
  st.session_state["vis_params"]["palette"] = st.session_state[
396
  "palette"
397
  ]
@@ -431,7 +436,7 @@ def app():
431
  palette_values,
432
  )
433
  st.write(cm.plot_colormap(cmap=palette_options, return_fig=True))
434
- st.session_state["palette"] = eval(palette)
435
  elif collection == "MODIS Ocean Color SMI":
436
  with st.expander("Show dataset details", False):
437
  st.markdown(
@@ -489,7 +494,7 @@ def app():
489
  palette_values,
490
  )
491
  st.write(cm.plot_colormap(cmap=palette_options, return_fig=True))
492
- st.session_state["palette"] = eval(palette)
493
 
494
  sample_roi = st.selectbox(
495
  "Select a sample ROI or upload a GeoJSON file:",
@@ -1341,7 +1346,9 @@ def app():
1341
  if vis_params.startswith("{") and vis_params.endswith(
1342
  "}"
1343
  ):
1344
- vis_params = eval(vis_params)
 
 
1345
  else:
1346
  vis_params = None
1347
  out_gif = geemap.modis_ocean_color_timelapse(
 
1
  import ee
2
+ import json
3
  import os
4
  import warnings
5
  import datetime
 
236
 
237
  st.markdown(
238
  """
239
+ An interactive web app for creating [Landsat](https://developers.google.com/earth-engine/datasets/catalog/landsat)/[GOES](https://jstnbraaten.medium.com/goes-in-earth-engine-53fbc8783c16) timelapse for any location around the globe.
240
+ The app was built using [streamlit](https://streamlit.io), [geemap](https://geemap.org), and [Google Earth Engine](https://earthengine.google.com). For more info, check out my streamlit [blog post](https://blog.streamlit.io/creating-satellite-timelapse-with-streamlit-and-earth-engine).
241
  """
242
  )
243
 
 
377
  st.write(
378
  cm.plot_colormap(cmap=palette_options, return_fig=True)
379
  )
380
+ st.session_state["palette"] = json.loads(
381
+ palette.replace("'", '"')
382
+ )
383
 
384
  if bands:
385
  vis_params = st.text_area(
 
394
  "{}",
395
  )
396
  try:
397
+ st.session_state["vis_params"] = json.loads(
398
+ vis_params.replace("'", '"')
399
+ )
400
  st.session_state["vis_params"]["palette"] = st.session_state[
401
  "palette"
402
  ]
 
436
  palette_values,
437
  )
438
  st.write(cm.plot_colormap(cmap=palette_options, return_fig=True))
439
+ st.session_state["palette"] = json.loads(palette.replace("'", '"'))
440
  elif collection == "MODIS Ocean Color SMI":
441
  with st.expander("Show dataset details", False):
442
  st.markdown(
 
494
  palette_values,
495
  )
496
  st.write(cm.plot_colormap(cmap=palette_options, return_fig=True))
497
+ st.session_state["palette"] = json.loads(palette.replace("'", '"'))
498
 
499
  sample_roi = st.selectbox(
500
  "Select a sample ROI or upload a GeoJSON file:",
 
1346
  if vis_params.startswith("{") and vis_params.endswith(
1347
  "}"
1348
  ):
1349
+ vis_params = json.loads(
1350
+ vis_params.replace("'", '"')
1351
+ )
1352
  else:
1353
  vis_params = None
1354
  out_gif = geemap.modis_ocean_color_timelapse(
pages/2_🏠_U.S._Housing.py CHANGED
@@ -224,7 +224,7 @@ def app():
224
  st.title("U.S. Real Estate Data and Market Trends")
225
  st.markdown(
226
  """**Introduction:** This interactive dashboard is designed for visualizing U.S. real estate data and market trends at multiple levels (i.e., national,
227
- state, county, and metro). The data sources include [Real Estate Data](https://www.realtor.com/research/data) from realtor.com and
228
  [Cartographic Boundary Files](https://www.census.gov/geographies/mapping-files/time-series/geo/carto-boundary-file.html) from U.S. Census Bureau.
229
  Several open-source packages are used to process the data and generate the visualizations, e.g., [streamlit](https://streamlit.io),
230
  [geopandas](https://geopandas.org), [leafmap](https://leafmap.org), and [pydeck](https://deckgl.readthedocs.io).
 
224
  st.title("U.S. Real Estate Data and Market Trends")
225
  st.markdown(
226
  """**Introduction:** This interactive dashboard is designed for visualizing U.S. real estate data and market trends at multiple levels (i.e., national,
227
+ state, county, and metro). The data sources include [Real Estate Data](https://www.realtor.com/research/data) from realtor.com and
228
  [Cartographic Boundary Files](https://www.census.gov/geographies/mapping-files/time-series/geo/carto-boundary-file.html) from U.S. Census Bureau.
229
  Several open-source packages are used to process the data and generate the visualizations, e.g., [streamlit](https://streamlit.io),
230
  [geopandas](https://geopandas.org), [leafmap](https://leafmap.org), and [pydeck](https://deckgl.readthedocs.io).
pages/3_πŸͺŸ_Split_Map.py CHANGED
@@ -23,8 +23,8 @@ with st.expander("See source code"):
23
  with st.echo():
24
  m = leafmap.Map()
25
  m.split_map(
26
- left_layer='ESA WorldCover 2020 S2 FCC', right_layer='ESA WorldCover 2020'
27
  )
28
- m.add_legend(title='ESA Land Cover', builtin_legend='ESA_WorldCover')
29
 
30
  m.to_streamlit(height=700)
 
23
  with st.echo():
24
  m = leafmap.Map()
25
  m.split_map(
26
+ left_layer="ESA WorldCover 2020 S2 FCC", right_layer="ESA WorldCover 2020"
27
  )
28
+ m.add_legend(title="ESA Land Cover", builtin_legend="ESA_WorldCover")
29
 
30
  m.to_streamlit(height=700)
pages/5_πŸ“_Marker_Cluster.py CHANGED
@@ -23,16 +23,16 @@ with st.expander("See source code"):
23
  with st.echo():
24
 
25
  m = leafmap.Map(center=[40, -100], zoom=4)
26
- cities = 'https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/us_cities.csv'
27
- regions = 'https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/us_regions.geojson'
28
 
29
- m.add_geojson(regions, layer_name='US Regions')
30
  m.add_points_from_xy(
31
  cities,
32
  x="longitude",
33
  y="latitude",
34
- color_column='region',
35
- icon_names=['gear', 'map', 'leaf', 'globe'],
36
  spin=True,
37
  add_legend=True,
38
  )
 
23
  with st.echo():
24
 
25
  m = leafmap.Map(center=[40, -100], zoom=4)
26
+ cities = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/us_cities.csv"
27
+ regions = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/us_regions.geojson"
28
 
29
+ m.add_geojson(regions, layer_name="US Regions")
30
  m.add_points_from_xy(
31
  cities,
32
  x="longitude",
33
  y="latitude",
34
+ color_column="region",
35
+ icon_names=["gear", "map", "leaf", "globe"],
36
  spin=True,
37
  add_legend=True,
38
  )
pages/6_πŸ—ΊοΈ_Basemaps.py CHANGED
@@ -22,7 +22,7 @@ def app():
22
  st.title("Search Basemaps")
23
  st.markdown(
24
  """
25
- This app is a demonstration of searching and loading basemaps from [xyzservices](https://github.com/geopandas/xyzservices) and [Quick Map Services (QMS)](https://github.com/nextgis/quickmapservices). Selecting from 1000+ basemaps with a few clicks.
26
  """
27
  )
28
 
@@ -54,11 +54,7 @@ def app():
54
 
55
  if tiles is not None:
56
  for tile in tiles:
57
- try:
58
- m.add_xyz_service(tile)
59
- except Exception as e:
60
- with row1_col2:
61
- st.error(e)
62
 
63
  m.to_streamlit(height=height)
64
 
 
22
  st.title("Search Basemaps")
23
  st.markdown(
24
  """
25
+ This app is a demonstration of searching and loading basemaps from [xyzservices](https://github.com/geopandas/xyzservices) and [Quick Map Services (QMS)](https://github.com/nextgis/quickmapservices). Selecting from 1000+ basemaps with a few clicks.
26
  """
27
  )
28
 
 
54
 
55
  if tiles is not None:
56
  for tile in tiles:
57
+ m.add_xyz_service(tile)
 
 
 
 
58
 
59
  m.to_streamlit(height=height)
60
 
pages/7_πŸ“¦_Web_Map_Service.py CHANGED
@@ -1,4 +1,5 @@
1
  import ast
 
2
  import streamlit as st
3
  import leafmap.foliumap as leafmap
4
 
@@ -18,6 +19,12 @@ st.sidebar.info(
18
  """
19
  )
20
 
 
 
 
 
 
 
21
 
22
  @st.cache_data
23
  def get_layers(url):
@@ -25,12 +32,16 @@ def get_layers(url):
25
  return options
26
 
27
 
 
 
 
 
28
  def app():
29
  st.title("Web Map Service (WMS)")
30
  st.markdown(
31
  """
32
- This app is a demonstration of loading Web Map Service (WMS) layers. Simply enter the URL of the WMS service
33
- in the text box below and press Enter to retrieve the layers. Go to https://apps.nationalmap.gov/services to find
34
  some WMS URLs if needed.
35
  """
36
  )
@@ -49,7 +60,14 @@ def app():
49
  empty = st.empty()
50
 
51
  if url:
52
- options = get_layers(url)
 
 
 
 
 
 
 
53
 
54
  default = None
55
  if url == esa_landcover:
@@ -78,7 +96,7 @@ def app():
78
  url, layers=layer, name=layer, attribution=" ", transparent=True
79
  )
80
  if add_legend and legend_text:
81
- legend_dict = ast.literal_eval(legend_text)
82
  m.add_legend(legend_dict=legend_dict)
83
 
84
  m.to_streamlit(height=height)
 
1
  import ast
2
+ import json
3
  import streamlit as st
4
  import leafmap.foliumap as leafmap
5
 
 
19
  """
20
  )
21
 
22
+ # Define a whitelist of trusted URLs
23
+ trusted_urls = [
24
+ "https://services.terrascope.be/wms/v2",
25
+ # Add more trusted URLs here
26
+ ]
27
+
28
 
29
  @st.cache_data
30
  def get_layers(url):
 
32
  return options
33
 
34
 
35
+ def is_trusted_url(url):
36
+ return url in trusted_urls
37
+
38
+
39
  def app():
40
  st.title("Web Map Service (WMS)")
41
  st.markdown(
42
  """
43
+ This app is a demonstration of loading Web Map Service (WMS) layers. Simply enter the URL of the WMS service
44
+ in the text box below and press Enter to retrieve the layers. Go to https://apps.nationalmap.gov/services to find
45
  some WMS URLs if needed.
46
  """
47
  )
 
60
  empty = st.empty()
61
 
62
  if url:
63
+
64
+ if is_trusted_url(url):
65
+ options = get_layers(url)
66
+ # Process options as needed
67
+ else:
68
+ st.error(
69
+ "The entered URL is not trusted. Please enter a valid WMS URL."
70
+ )
71
 
72
  default = None
73
  if url == esa_landcover:
 
96
  url, layers=layer, name=layer, attribution=" ", transparent=True
97
  )
98
  if add_legend and legend_text:
99
+ legend_dict = json.loads(legend_text.replace("'", '"'))
100
  m.add_legend(legend_dict=legend_dict)
101
 
102
  m.to_streamlit(height=height)
pages/8_🏜️_Raster_Data_Visualization.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import os
2
  import leafmap.foliumap as leafmap
3
  import leafmap.colormaps as cm
@@ -44,6 +45,14 @@ An interactive web app for visualizing local raster datasets and Cloud Optimized
44
  """
45
  )
46
 
 
 
 
 
 
 
 
 
47
  row1_col1, row1_col2 = st.columns([2, 1])
48
 
49
  with row1_col1:
@@ -58,7 +67,7 @@ with row1_col2:
58
  cog,
59
  )
60
 
61
- if url:
62
  try:
63
  options = leafmap.cog_bands(url)
64
  except Exception as e:
@@ -73,6 +82,8 @@ with row1_col2:
73
  pass
74
  else:
75
  st.error("Please select one or three bands")
 
 
76
 
77
  add_params = st.checkbox("Add visualization parameters")
78
  if add_params:
@@ -82,7 +93,7 @@ with row1_col2:
82
 
83
  if len(vis_params) > 0:
84
  try:
85
- vis_params = eval(vis_params)
86
  except Exception as e:
87
  st.error(
88
  f"Invalid visualization parameters. It should be a dictionary. Error: {e}"
 
1
+ import json
2
  import os
3
  import leafmap.foliumap as leafmap
4
  import leafmap.colormaps as cm
 
45
  """
46
  )
47
 
48
+
49
+ def is_trusted_url(url):
50
+ if url.startswith("https://opendata.digitalglobe.com/events/california-fire-2020/"):
51
+ return True
52
+ else:
53
+ return False
54
+
55
+
56
  row1_col1, row1_col2 = st.columns([2, 1])
57
 
58
  with row1_col1:
 
67
  cog,
68
  )
69
 
70
+ if is_trusted_url(url):
71
  try:
72
  options = leafmap.cog_bands(url)
73
  except Exception as e:
 
82
  pass
83
  else:
84
  st.error("Please select one or three bands")
85
+ else:
86
+ st.error("Please enter a trusted URL")
87
 
88
  add_params = st.checkbox("Add visualization parameters")
89
  if add_params:
 
93
 
94
  if len(vis_params) > 0:
95
  try:
96
+ vis_params = json.loads(vis_params.replace("'", '"'))
97
  except Exception as e:
98
  st.error(
99
  f"Invalid visualization parameters. It should be a dictionary. Error: {e}"
pages/9_πŸ”²_Vector_Data_Visualization.py CHANGED
@@ -20,6 +20,17 @@ st.sidebar.info(
20
  )
21
 
22
 
 
 
 
 
 
 
 
 
 
 
 
23
  def save_uploaded_file(file_content, file_name):
24
  """
25
  Save the uploaded file to a temporary directory
@@ -70,7 +81,7 @@ def app():
70
 
71
  container = st.container()
72
 
73
- if data or url:
74
  if data:
75
  file_path = save_uploaded_file(data, data.name)
76
  layer_name = os.path.splitext(data.name)[0]
 
20
  )
21
 
22
 
23
+ # Define a whitelist of trusted URLs
24
+ trusted_urls = [
25
+ "https://github.com/giswqs/streamlit-geospatial/raw/master/data/us_states.geojson",
26
+ # Add more trusted URLs here
27
+ ]
28
+
29
+
30
+ def is_trusted_url(url):
31
+ return url in trusted_urls
32
+
33
+
34
  def save_uploaded_file(file_content, file_name):
35
  """
36
  Save the uploaded file to a temporary directory
 
81
 
82
  container = st.container()
83
 
84
+ if data or is_trusted_url(url):
85
  if data:
86
  file_path = save_uploaded_file(data, data.name)
87
  layer_name = os.path.splitext(data.name)[0]