UjjwalKGupta commited on
Commit
1332314
1 Parent(s): 4933d52

Fix DEM legend

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -151,7 +151,7 @@ def get_dem_slope_maps(buffer_ee_geometry):
151
  )
152
 
153
  # Calculate the minimum and maximum values
154
- stats = contours.reduceRegion(reducer=ee.Reducer.minMax(), scale=30, maxPixels=1e13)
155
  max_value = stats.get("contours_max").getInfo()
156
  min_value = stats.get("contours_min").getInfo()
157
  vis_params = {"min": min_value, "max": max_value, "palette": ["blue", "green", "yellow", "red"]}
@@ -186,14 +186,21 @@ def get_dem_slope_maps(buffer_ee_geometry):
186
  .rename("slope")
187
  )
188
  # Calculate the minimum and maximum values
189
- stats = slope_layer.reduceRegion(reducer=ee.Reducer.minMax(), scale=30, maxPixels=1e13)
190
  max_value = stats.get("slope_max").getInfo()
191
  min_value = stats.get("slope_min").getInfo()
192
  vis_params = {"min": min_value, "max": max_value, "palette": ["blue", "green", "yellow", "red"]}
193
  slope_map.addLayer(slope_layer, vis_params, "Slope Layer")
194
  # Create a colormap
195
  colormap = cm.LinearColormap(colors=vis_params["palette"], vmin=vis_params["min"], vmax=vis_params["max"])
196
- slope_map.add_child(colormap)
 
 
 
 
 
 
 
197
  return dem_map, slope_map
198
 
199
 
 
151
  )
152
 
153
  # Calculate the minimum and maximum values
154
+ stats = contours.reduceRegion(reducer=ee.Reducer.minMax(), scale=10, maxPixels=1e13)
155
  max_value = stats.get("contours_max").getInfo()
156
  min_value = stats.get("contours_min").getInfo()
157
  vis_params = {"min": min_value, "max": max_value, "palette": ["blue", "green", "yellow", "red"]}
 
186
  .rename("slope")
187
  )
188
  # Calculate the minimum and maximum values
189
+ stats = slope_layer.reduceRegion(reducer=ee.Reducer.minMax(), scale=10, maxPixels=1e13)
190
  max_value = stats.get("slope_max").getInfo()
191
  min_value = stats.get("slope_min").getInfo()
192
  vis_params = {"min": min_value, "max": max_value, "palette": ["blue", "green", "yellow", "red"]}
193
  slope_map.addLayer(slope_layer, vis_params, "Slope Layer")
194
  # Create a colormap
195
  colormap = cm.LinearColormap(colors=vis_params["palette"], vmin=vis_params["min"], vmax=vis_params["max"])
196
+ #slope_map.add_child(colormap)
197
+ tick_size=int((max_value-min_value)/4)
198
+ slope_map.add_legend(title="Slope (degrees)",
199
+ legend_dict={'{}-{} m'.format(min_value, min_value+tick_size): '#0000FF',
200
+ '{}-{} m'.format(min_value+tick_size, min_value+2*tick_size): '#00FF00',
201
+ '{}-{} m'.format(min_value+2*tick_size, min_value+3*tick_size): '#FFFF00',
202
+ '{}-{} m'.format(min_value+3*tick_size, max_value): 'FF0000'},
203
+ position='bottomright')
204
  return dem_map, slope_map
205
 
206