ipywidets
Import libraries¶
In [1]:
Copied!
# !pip install geodemo
# !pip install geodemo
In [2]:
Copied!
import ee
import geogee
import ipywidgets as widgets
from ipyleaflet import WidgetControl
import ee
import geogee
import ipywidgets as widgets
from ipyleaflet import WidgetControl
C:\Users\Sarath_Kin\miniconda3\envs\demo310\lib\site-packages\google\api_core\_python_version_support.py:266: FutureWarning: You are using a Python version (3.10.19) which Google will stop supporting in new releases of google.api_core once it reaches its end of life (2026-10-04). Please upgrade to the latest Python version, or at least Python 3.11, to continue receiving updates for google.api_core past that date. warnings.warn(message, FutureWarning)
Create an interactive map¶
In [3]:
Copied!
Map = geogee.Map()
Map
Map = geogee.Map()
Map
Out[3]:
In [4]:
Copied!
geogee.ee_initialize()
geogee.ee_initialize()
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[4], line 1 ----> 1 geogee.ee_initialize() File L:\Coding\Github\geogee\geogee\common.py:16, in ee_initialize(token_name) 14 def ee_initialize(token_name="EARTHENGINE_TOKEN"): 15 """Authenticates Earth Engine and initialize an Earth Engine session""" ---> 16 if ee.data._credentials is None: 17 try: 18 ee_token = os.environ.get(token_name) AttributeError: module 'ee.data' has no attribute '_credentials'
In [5]:
Copied!
dem = ee.Image('USGS/SRTMGL1_003')
vis_params = {
'min': 0,
'max': 4000,
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}
Map.addLayer(dem, vis_params, 'DEM')
dem = ee.Image('USGS/SRTMGL1_003')
vis_params = {
'min': 0,
'max': 4000,
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}
Map.addLayer(dem, vis_params, 'DEM')
--------------------------------------------------------------------------- EEException Traceback (most recent call last) Cell In[5], line 1 ----> 1 dem = ee.Image('USGS/SRTMGL1_003') 3 vis_params = { 4 'min': 0, 5 'max': 4000, 6 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']} 8 Map.addLayer(dem, vis_params, 'DEM') File ~\miniconda3\envs\demo310\lib\site-packages\ee\computedobject.py:29, in ComputedObjectMetaclass.__call__(cls, *args, **kwargs) 27 return args[0] 28 else: ---> 29 return type.__call__(cls, *args, **kwargs) File ~\miniconda3\envs\demo310\lib\site-packages\ee\deprecation.py:127, in WarnForDeprecatedAsset.<locals>.Decorator.<locals>.Wrapper(*args, **kwargs) 125 if asset: 126 _IssueAssetDeprecationWarning(asset) --> 127 return func(*args, **kwargs) File ~\miniconda3\envs\demo310\lib\site-packages\ee\image.py:73, in Image.__init__(self, args, version) 54 @deprecation.WarnForDeprecatedAsset('args') 55 def __init__(self, args: Any | None = None, version: float | None = None): 56 """Constructs an Earth Engine image. 57 58 Args: (...) 71 EEException: if passed something other than the above. 72 """ ---> 73 self.initialize() 75 if version is not None: 76 if ee_types.isString(args) and ee_types.isNumber(version): 77 # An ID and version. File ~\miniconda3\envs\demo310\lib\site-packages\ee\image.py:119, in Image.initialize(cls) 117 """Imports API functions to this class.""" 118 if not cls._initialized: --> 119 apifunction.ApiFunction.importApi(cls, cls.name(), cls.name()) 120 cls._initialized = True File ~\miniconda3\envs\demo310\lib\site-packages\ee\_utils.py:39, in accept_opt_prefix.<locals>.opt_fixed.<locals>.wrapper(*args, **kwargs) 37 if new_key not in kwargs: 38 kwargs[new_key] = old_key_val ---> 39 return func(*args, **kwargs) File ~\miniconda3\envs\demo310\lib\site-packages\ee\apifunction.py:199, in ApiFunction.importApi(cls, target, prefix, type_name, prepend) 179 @classmethod 180 @_utils.accept_opt_prefix('opt_prepend') 181 def importApi( (...) 186 prepend: str | None = None, 187 ) -> None: 188 """Adds all API functions that begin with a given prefix to a target class. 189 190 Args: (...) 197 functions. 198 """ --> 199 cls.initialize() 200 prepend = prepend or '' 201 for name, api_func in cls._api.items(): File ~\miniconda3\envs\demo310\lib\site-packages\ee\apifunction.py:163, in ApiFunction.initialize(cls) 161 """Initializes the list of signatures from the Earth Engine front-end.""" 162 if not cls._api: --> 163 signatures = data.getAlgorithms() 164 api = {} 165 for name, sig in signatures.items(): 166 # Strip type parameters. File ~\miniconda3\envs\demo310\lib\site-packages\ee\data.py:1421, in getAlgorithms() 1404 """Get the list of algorithms. 1405 1406 Returns: (...) 1417 is not specified. 1418 """ 1419 try: 1420 call = ( -> 1421 _get_cloud_projects() 1422 .algorithms() 1423 .list(parent=_get_projects_path(), prettyPrint=False) 1424 ) 1425 except TypeError: 1426 call = ( 1427 _get_cloud_projects() 1428 .algorithms() 1429 .list(project=_get_projects_path(), prettyPrint=False) 1430 ) File ~\miniconda3\envs\demo310\lib\site-packages\ee\data.py:289, in _get_cloud_projects() 287 state = _get_state() 288 if state.cloud_api_resource is None: --> 289 raise ee_exception.EEException(_NOT_INITIALIZED_MESSAGE) 290 return state.cloud_api_resource.projects() EEException: Earth Engine client library not initialized. See http://goo.gle/ee-auth.
Add vector data¶
In [6]:
Copied!
fc = ee.FeatureCollection('TIGER/2018/States')
Map.addLayer(fc, {}, 'US States')
fc = ee.FeatureCollection('TIGER/2018/States')
Map.addLayer(fc, {}, 'US States')
--------------------------------------------------------------------------- EEException Traceback (most recent call last) Cell In[6], line 1 ----> 1 fc = ee.FeatureCollection('TIGER/2018/States') 2 Map.addLayer(fc, {}, 'US States') File ~\miniconda3\envs\demo310\lib\site-packages\ee\computedobject.py:29, in ComputedObjectMetaclass.__call__(cls, *args, **kwargs) 27 return args[0] 28 else: ---> 29 return type.__call__(cls, *args, **kwargs) File ~\miniconda3\envs\demo310\lib\site-packages\ee\_utils.py:39, in accept_opt_prefix.<locals>.opt_fixed.<locals>.wrapper(*args, **kwargs) 37 if new_key not in kwargs: 38 kwargs[new_key] = old_key_val ---> 39 return func(*args, **kwargs) File ~\miniconda3\envs\demo310\lib\site-packages\ee\deprecation.py:127, in WarnForDeprecatedAsset.<locals>.Decorator.<locals>.Wrapper(*args, **kwargs) 125 if asset: 126 _IssueAssetDeprecationWarning(asset) --> 127 return func(*args, **kwargs) File ~\miniconda3\envs\demo310\lib\site-packages\ee\featurecollection.py:63, in FeatureCollection.__init__(self, args, column) 33 @_utils.accept_opt_prefix('opt_column') 34 @deprecation.WarnForDeprecatedAsset('args') 35 def __init__( (...) 45 column: Any | None = None, 46 ): 47 """Constructs a collection features. 48 49 Args: (...) 61 EEException: if passed something other than the above. 62 """ ---> 63 self.initialize() 65 # Wrap geometries with features. 66 if isinstance(args, geometry.Geometry): File ~\miniconda3\envs\demo310\lib\site-packages\ee\featurecollection.py:109, in FeatureCollection.initialize(cls) 107 """Imports API functions to this class.""" 108 if not cls._initialized: --> 109 super().initialize() 110 apifunction.ApiFunction.importApi(cls, cls.name(), cls.name()) 111 cls._initialized = True File ~\miniconda3\envs\demo310\lib\site-packages\ee\collection.py:57, in Collection.initialize(cls) 55 """Imports API functions to this class.""" 56 if not cls._initialized: ---> 57 apifunction.ApiFunction.importApi(cls, cls.name(), cls.name()) 58 apifunction.ApiFunction.importApi( 59 cls, 'AggregateFeatureCollection', cls.name(), 'aggregate_') 60 cls._initialized = True File ~\miniconda3\envs\demo310\lib\site-packages\ee\_utils.py:39, in accept_opt_prefix.<locals>.opt_fixed.<locals>.wrapper(*args, **kwargs) 37 if new_key not in kwargs: 38 kwargs[new_key] = old_key_val ---> 39 return func(*args, **kwargs) File ~\miniconda3\envs\demo310\lib\site-packages\ee\apifunction.py:199, in ApiFunction.importApi(cls, target, prefix, type_name, prepend) 179 @classmethod 180 @_utils.accept_opt_prefix('opt_prepend') 181 def importApi( (...) 186 prepend: str | None = None, 187 ) -> None: 188 """Adds all API functions that begin with a given prefix to a target class. 189 190 Args: (...) 197 functions. 198 """ --> 199 cls.initialize() 200 prepend = prepend or '' 201 for name, api_func in cls._api.items(): File ~\miniconda3\envs\demo310\lib\site-packages\ee\apifunction.py:163, in ApiFunction.initialize(cls) 161 """Initializes the list of signatures from the Earth Engine front-end.""" 162 if not cls._api: --> 163 signatures = data.getAlgorithms() 164 api = {} 165 for name, sig in signatures.items(): 166 # Strip type parameters. File ~\miniconda3\envs\demo310\lib\site-packages\ee\data.py:1421, in getAlgorithms() 1404 """Get the list of algorithms. 1405 1406 Returns: (...) 1417 is not specified. 1418 """ 1419 try: 1420 call = ( -> 1421 _get_cloud_projects() 1422 .algorithms() 1423 .list(parent=_get_projects_path(), prettyPrint=False) 1424 ) 1425 except TypeError: 1426 call = ( 1427 _get_cloud_projects() 1428 .algorithms() 1429 .list(project=_get_projects_path(), prettyPrint=False) 1430 ) File ~\miniconda3\envs\demo310\lib\site-packages\ee\data.py:289, in _get_cloud_projects() 287 state = _get_state() 288 if state.cloud_api_resource is None: --> 289 raise ee_exception.EEException(_NOT_INITIALIZED_MESSAGE) 290 return state.cloud_api_resource.projects() EEException: Earth Engine client library not initialized. See http://goo.gle/ee-auth.
Change layer opacity¶
In [7]:
Copied!
Map
Map
Out[7]:
In [8]:
Copied!
Map.layers
Map.layers
Out[8]:
(TileLayer(attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', base=True, max_zoom=19, min_zoom=1, name='OpenStreetMap.Mapnik', options=['attribution', 'bounds', 'detect_retina', 'max_native_zoom', 'max_zoom', 'min_native_zoom', 'min_zoom', 'no_wrap', 'pm_ignore', 'tile_size', 'tms', 'zoom_offset']),
TileLayer(attribution='Google', name='Google Maps', options=['attribution', 'bounds', 'detect_retina', 'max_native_zoom', 'max_zoom', 'min_native_zoom', 'min_zoom', 'no_wrap', 'pm_ignore', 'tile_size', 'tms', 'zoom_offset'], url='https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}'))
In [9]:
Copied!
dem_layer = Map.layers[2]
dem_layer.interact(opacity=(0, 1, 0.1))
dem_layer = Map.layers[2]
dem_layer.interact(opacity=(0, 1, 0.1))
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) Cell In[9], line 1 ----> 1 dem_layer = Map.layers[2] 2 dem_layer.interact(opacity=(0, 1, 0.1)) IndexError: tuple index out of range
In [10]:
Copied!
vector_layer = Map.layers[3]
vector_layer.interact(opacity=(0, 1, 0.1))
vector_layer = Map.layers[3]
vector_layer.interact(opacity=(0, 1, 0.1))
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) Cell In[10], line 1 ----> 1 vector_layer = Map.layers[3] 2 vector_layer.interact(opacity=(0, 1, 0.1)) IndexError: tuple index out of range
Widget list¶
Widget list: https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html
Icons: https://fontawesome.com/v4.7.0/icons
Numeric widgets¶
IntSlider¶
In [11]:
Copied!
int_slider = widgets.IntSlider(
value=2000,
min=1984,
max=2020,
step=1,
description='Year:'
)
int_slider
int_slider = widgets.IntSlider(
value=2000,
min=1984,
max=2020,
step=1,
description='Year:'
)
int_slider
Out[11]:
In [12]:
Copied!
int_slider.value
int_slider.value
Out[12]:
2000
FloatSlider¶
In [13]:
Copied!
float_slider = widgets.FloatSlider(
value=0,
min=-1,
max=1,
step=0.05,
description='Threshold:'
)
float_slider
float_slider = widgets.FloatSlider(
value=0,
min=-1,
max=1,
step=0.05,
description='Threshold:'
)
float_slider
Out[13]:
In [14]:
Copied!
float_slider.value
float_slider.value
Out[14]:
0.0
IntProgress¶
In [15]:
Copied!
int_progress = widgets.IntProgress(
value=7,
min=0,
max=10,
step=1,
description='Loading:',
bar_style='', # 'success', 'info', 'warning', 'danger' or ''
orientation='horizontal'
)
int_progress
int_progress = widgets.IntProgress(
value=7,
min=0,
max=10,
step=1,
description='Loading:',
bar_style='', # 'success', 'info', 'warning', 'danger' or ''
orientation='horizontal'
)
int_progress
Out[15]:
In [16]:
Copied!
int_text = widgets.IntText(
value=7,
description='Any:',
)
int_text
int_text = widgets.IntText(
value=7,
description='Any:',
)
int_text
Out[16]:
In [17]:
Copied!
float_text = widgets.FloatText(
value=7.5,
description='Any:',
)
float_text
float_text = widgets.FloatText(
value=7.5,
description='Any:',
)
float_text
Out[17]:
In [18]:
Copied!
toggle_button = widgets.ToggleButton(
value=False,
description='Click me',
disabled=False,
button_style='success', # 'success', 'info', 'warning', 'danger' or ''
tooltip='Description',
icon='check' # (FontAwesome names without the `fa-` prefix)
)
toggle_button
toggle_button = widgets.ToggleButton(
value=False,
description='Click me',
disabled=False,
button_style='success', # 'success', 'info', 'warning', 'danger' or ''
tooltip='Description',
icon='check' # (FontAwesome names without the `fa-` prefix)
)
toggle_button
Out[18]:
In [19]:
Copied!
toggle_button.value
toggle_button.value
Out[19]:
False
Checkbox¶
In [20]:
Copied!
checkbox = widgets.Checkbox(
value=False,
description='Check me',
disabled=False,
indent=False
)
checkbox
checkbox = widgets.Checkbox(
value=False,
description='Check me',
disabled=False,
indent=False
)
checkbox
Out[20]:
In [21]:
Copied!
checkbox.value
checkbox.value
Out[21]:
False
In [22]:
Copied!
dropdown = widgets.Dropdown(
options=['USA', 'Canada', 'Mexico'],
value='Canada',
description='Country:'
)
dropdown
dropdown = widgets.Dropdown(
options=['USA', 'Canada', 'Mexico'],
value='Canada',
description='Country:'
)
dropdown
Out[22]:
In [23]:
Copied!
dropdown.value
dropdown.value
Out[23]:
'Canada'
RadioButtons¶
In [24]:
Copied!
radio_buttons = widgets.RadioButtons(
options=['USA', 'Canada', 'Mexico'],
value='Canada',
description='Country:'
)
radio_buttons
radio_buttons = widgets.RadioButtons(
options=['USA', 'Canada', 'Mexico'],
value='Canada',
description='Country:'
)
radio_buttons
Out[24]:
In [25]:
Copied!
radio_buttons.value
radio_buttons.value
Out[25]:
'Canada'
In [26]:
Copied!
text = widgets.Text(
value='USA',
placeholder='Enter a country name',
description='Country:',
disabled=False
)
text
text = widgets.Text(
value='USA',
placeholder='Enter a country name',
description='Country:',
disabled=False
)
text
Out[26]:
In [27]:
Copied!
text.value
text.value
Out[27]:
'USA'
Textarea¶
In [28]:
Copied!
widgets.Textarea(
value='Hello World',
placeholder='Type something',
description='String:',
disabled=False
)
widgets.Textarea(
value='Hello World',
placeholder='Type something',
description='String:',
disabled=False
)
Out[28]:
HTML¶
In [29]:
Copied!
widgets.HTML(
value="Hello <b>World</b>",
placeholder='Some HTML',
description='Some HTML',
)
widgets.HTML(
value="Hello World",
placeholder='Some HTML',
description='Some HTML',
)
Out[29]:
In [30]:
Copied!
widgets.HTML(
value='<img src="https://earthengine.google.com/static/images/earth-engine-logo.png" width="100" height="100">'
)
widgets.HTML(
value='
'
)
'
)Out[30]:
Button¶
In [31]:
Copied!
button = widgets.Button(
description='Click me',
button_style='info', # 'success', 'info', 'warning', 'danger' or ''
tooltip='Click me',
icon='check' # (FontAwesome names without the `fa-` prefix)
)
button
button = widgets.Button(
description='Click me',
button_style='info', # 'success', 'info', 'warning', 'danger' or ''
tooltip='Click me',
icon='check' # (FontAwesome names without the `fa-` prefix)
)
button
Out[31]:
Date picker¶
In [32]:
Copied!
date_picker = widgets.DatePicker(
description='Pick a Date',
disabled=False
)
date_picker
date_picker = widgets.DatePicker(
description='Pick a Date',
disabled=False
)
date_picker
Out[32]:
In [33]:
Copied!
date_picker.value
date_picker.value
Color picker¶
In [34]:
Copied!
color_picker = widgets.ColorPicker(
concise=False,
description='Pick a color',
value='blue',
disabled=False
)
color_picker
color_picker = widgets.ColorPicker(
concise=False,
description='Pick a color',
value='blue',
disabled=False
)
color_picker
Out[34]:
In [35]:
Copied!
color_picker.value
color_picker.value
Out[35]:
'blue'
Output widget¶
In [36]:
Copied!
out = widgets.Output(layout={'border': '1px solid black'})
out
out = widgets.Output(layout={'border': '1px solid black'})
out
Out[36]:
In [37]:
Copied!
with out:
for i in range(10):
print(i, 'Hello world!')
with out:
for i in range(10):
print(i, 'Hello world!')
In [38]:
Copied!
from IPython.display import YouTubeVideo
out.clear_output()
with out:
display(YouTubeVideo('mA21Us_3m28'))
out
from IPython.display import YouTubeVideo
out.clear_output()
with out:
display(YouTubeVideo('mA21Us_3m28'))
out
Out[38]:
In [39]:
Copied!
out.clear_output()
with out:
display(widgets.IntSlider())
out
out.clear_output()
with out:
display(widgets.IntSlider())
out
Out[39]:
Add a widget to the map¶
In [40]:
Copied!
Map = geogee.Map()
dem = ee.Image('USGS/SRTMGL1_003')
fc = ee.FeatureCollection('TIGER/2018/States')
vis_params = {
'min': 0,
'max': 4000,
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}
Map.addLayer(dem, vis_params, 'DEM')
Map.addLayer(fc, {}, 'US States')
Map
Map = geogee.Map()
dem = ee.Image('USGS/SRTMGL1_003')
fc = ee.FeatureCollection('TIGER/2018/States')
vis_params = {
'min': 0,
'max': 4000,
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}
Map.addLayer(dem, vis_params, 'DEM')
Map.addLayer(fc, {}, 'US States')
Map
--------------------------------------------------------------------------- EEException Traceback (most recent call last) Cell In[40], line 3 1 Map = geogee.Map() ----> 3 dem = ee.Image('USGS/SRTMGL1_003') 4 fc = ee.FeatureCollection('TIGER/2018/States') 5 vis_params = { 6 'min': 0, 7 'max': 4000, 8 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']} File ~\miniconda3\envs\demo310\lib\site-packages\ee\computedobject.py:29, in ComputedObjectMetaclass.__call__(cls, *args, **kwargs) 27 return args[0] 28 else: ---> 29 return type.__call__(cls, *args, **kwargs) File ~\miniconda3\envs\demo310\lib\site-packages\ee\deprecation.py:127, in WarnForDeprecatedAsset.<locals>.Decorator.<locals>.Wrapper(*args, **kwargs) 125 if asset: 126 _IssueAssetDeprecationWarning(asset) --> 127 return func(*args, **kwargs) File ~\miniconda3\envs\demo310\lib\site-packages\ee\image.py:73, in Image.__init__(self, args, version) 54 @deprecation.WarnForDeprecatedAsset('args') 55 def __init__(self, args: Any | None = None, version: float | None = None): 56 """Constructs an Earth Engine image. 57 58 Args: (...) 71 EEException: if passed something other than the above. 72 """ ---> 73 self.initialize() 75 if version is not None: 76 if ee_types.isString(args) and ee_types.isNumber(version): 77 # An ID and version. File ~\miniconda3\envs\demo310\lib\site-packages\ee\image.py:119, in Image.initialize(cls) 117 """Imports API functions to this class.""" 118 if not cls._initialized: --> 119 apifunction.ApiFunction.importApi(cls, cls.name(), cls.name()) 120 cls._initialized = True File ~\miniconda3\envs\demo310\lib\site-packages\ee\_utils.py:39, in accept_opt_prefix.<locals>.opt_fixed.<locals>.wrapper(*args, **kwargs) 37 if new_key not in kwargs: 38 kwargs[new_key] = old_key_val ---> 39 return func(*args, **kwargs) File ~\miniconda3\envs\demo310\lib\site-packages\ee\apifunction.py:199, in ApiFunction.importApi(cls, target, prefix, type_name, prepend) 179 @classmethod 180 @_utils.accept_opt_prefix('opt_prepend') 181 def importApi( (...) 186 prepend: str | None = None, 187 ) -> None: 188 """Adds all API functions that begin with a given prefix to a target class. 189 190 Args: (...) 197 functions. 198 """ --> 199 cls.initialize() 200 prepend = prepend or '' 201 for name, api_func in cls._api.items(): File ~\miniconda3\envs\demo310\lib\site-packages\ee\apifunction.py:163, in ApiFunction.initialize(cls) 161 """Initializes the list of signatures from the Earth Engine front-end.""" 162 if not cls._api: --> 163 signatures = data.getAlgorithms() 164 api = {} 165 for name, sig in signatures.items(): 166 # Strip type parameters. File ~\miniconda3\envs\demo310\lib\site-packages\ee\data.py:1421, in getAlgorithms() 1404 """Get the list of algorithms. 1405 1406 Returns: (...) 1417 is not specified. 1418 """ 1419 try: 1420 call = ( -> 1421 _get_cloud_projects() 1422 .algorithms() 1423 .list(parent=_get_projects_path(), prettyPrint=False) 1424 ) 1425 except TypeError: 1426 call = ( 1427 _get_cloud_projects() 1428 .algorithms() 1429 .list(project=_get_projects_path(), prettyPrint=False) 1430 ) File ~\miniconda3\envs\demo310\lib\site-packages\ee\data.py:289, in _get_cloud_projects() 287 state = _get_state() 288 if state.cloud_api_resource is None: --> 289 raise ee_exception.EEException(_NOT_INITIALIZED_MESSAGE) 290 return state.cloud_api_resource.projects() EEException: Earth Engine client library not initialized. See http://goo.gle/ee-auth.
In [41]:
Copied!
output_widget = widgets.Output(layout={'border': '1px solid black'})
output_control = WidgetControl(widget=output_widget, position='bottomright')
Map.add_control(output_control)
output_widget = widgets.Output(layout={'border': '1px solid black'})
output_control = WidgetControl(widget=output_widget, position='bottomright')
Map.add_control(output_control)
In [42]:
Copied!
with output_widget:
print('Nice map!')
with output_widget:
print('Nice map!')
In [43]:
Copied!
output_widget.clear_output()
logo = widgets.HTML(
value='<img src="https://earthengine.google.com/static/images/earth-engine-logo.png" width="100" height="100">'
)
with output_widget:
display(logo)
output_widget.clear_output()
logo = widgets.HTML(
value='
'
)
with output_widget:
display(logo)
'
)
with output_widget:
display(logo)In [44]:
Copied!
def handle_interaction(**kwargs):
latlon = kwargs.get('coordinates')
if kwargs.get('type') == 'click':
Map.default_style = {'cursor': 'wait'}
xy = ee.Geometry.Point(latlon[::-1])
selected_fc = fc.filterBounds(xy)
with output_widget:
output_widget.clear_output()
try:
name = selected_fc.first().get('NAME').getInfo()
usps = selected_fc.first().get('STUSPS').getInfo()
Map.layers = Map.layers[:4]
geom = selected_fc.geometry()
layer_name = name + '-' + usps
Map.addLayer(ee.Image().paint(geom, 0, 2), {'palette': 'red'}, layer_name)
print(layer_name)
except Exception as e:
print('No feature could be found')
Map.layers = Map.layers[:4]
Map.default_style = {'cursor': 'pointer'}
Map.on_interaction(handle_interaction)
def handle_interaction(**kwargs):
latlon = kwargs.get('coordinates')
if kwargs.get('type') == 'click':
Map.default_style = {'cursor': 'wait'}
xy = ee.Geometry.Point(latlon[::-1])
selected_fc = fc.filterBounds(xy)
with output_widget:
output_widget.clear_output()
try:
name = selected_fc.first().get('NAME').getInfo()
usps = selected_fc.first().get('STUSPS').getInfo()
Map.layers = Map.layers[:4]
geom = selected_fc.geometry()
layer_name = name + '-' + usps
Map.addLayer(ee.Image().paint(geom, 0, 2), {'palette': 'red'}, layer_name)
print(layer_name)
except Exception as e:
print('No feature could be found')
Map.layers = Map.layers[:4]
Map.default_style = {'cursor': 'pointer'}
Map.on_interaction(handle_interaction)