Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in displaying images in geemap #1812

Closed
haydenclose opened this issue Nov 2, 2023 · 1 comment · Fixed by #1813
Closed

Bug in displaying images in geemap #1812

haydenclose opened this issue Nov 2, 2023 · 1 comment · Fixed by #1813
Labels
bug Something isn't working

Comments

@haydenclose
Copy link

Hi,
Many thanks for solving the other bug with the drawing feature. I have now come across another bug which has appeared from the recent updates.

set up the map

geom =  ee.Geometry.Point([-2.98333, 58.93078])
Map = geemap.Map() 
Map.centerObject(geom, 13) 
 
img_params = {'bands':'VV', 'min':-16, 'max':-6}   
image = ee.Image('COPERNICUS/S1_GRD/S1A_IW_GRDH_1SDV_20231010T063002_20231010T063027_050699_061BCD_88FE')
Map.addLayer(image, img_params, 'Satellite Image',True)  
Map

Now if remove the map and then add the same image using the code below it throws an error below. However if you run the last line again Map.addLayer(image, img_params, 'Satellite Image',True) it adds the image to the map. I think there may be bug in remove_layer function.

for layer in Map.layers:
  if layer.name == 'Satellite Image':
    Map.remove_layer(layer)
Map.addLayer(image, img_params, 'Satellite Image',True) 

Error

AttributeError Traceback (most recent call last)
in <cell line: 4>()
2 if layer.name == 'Satellite Image':
3 Map.remove_layer(layer)
----> 4 Map.addLayer(image, img_params, 'Satellite Image',True)
5 Map.addLayer(image, img_params, 'Satellite Image',True)

6 frames
/usr/local/lib/python3.10/dist-packages/geemap/geemap.py in add_ee_layer(self, ee_object, vis_params, name, shown, opacity)
337 )
338
--> 339 super().add_layer(ee_object, vis_params, name, shown, opacity)
340
341 if isinstance(ee_object, (ee.Image, ee.ImageCollection)):

/usr/local/lib/python3.10/dist-packages/geemap/core.py in add_layer(self, ee_object, vis_params, name, shown, opacity)
754
755 # Remove the layer if it already exists.
--> 756 self.remove(name)
757
758 self.ee_layers[name] = {

/usr/local/lib/python3.10/dist-packages/geemap/core.py in remove(self, widget)
719 tile_layer = ee_layer.get("ee_layer", None)
720 if tile_layer is not None:
--> 721 self.remove_layer(tile_layer)
722 if legend := ee_layer.get("legend", None):
723 self.remove(legend)

/usr/local/lib/python3.10/dist-packages/ipyleaflet/leaflet.py in remove_layer(self, rm_layer)
2539 warnings.warn("remove_layer is deprecated, use remove instead", DeprecationWarning)
2540
-> 2541 self.remove(rm_layer)
2542
2543 def substitute_layer(self, old, new):

/usr/local/lib/python3.10/dist-packages/geemap/core.py in remove(self, widget)
726 return
727
--> 728 super().remove(widget)
729 if isinstance(widget, ipywidgets.Widget):
730 widget.close()

/usr/local/lib/python3.10/dist-packages/ipyleaflet/leaflet.py in remove(self, item)
2682 """
2683 if isinstance(item, Layer):
-> 2684 if item.model_id not in self._layer_ids:
2685 raise LayerException('layer not on map: %r' % item)
2686 self.layers = tuple([layer for layer in self.layers if layer.model_id != item.model_id])

/usr/local/lib/python3.10/dist-packages/ipywidgets/widgets/widget.py in model_id(self)
518
519 If a Comm doesn't exist yet, a Comm will be created automagically."""
--> 520 return self.comm.comm_id
521
522 #-------------------------------------------------------------------------

AttributeError: 'NoneType' object has no attribute 'comm_id'

@haydenclose haydenclose added the bug Something isn't working label Nov 2, 2023
@giswqs
Copy link
Member

giswqs commented Nov 2, 2023

Thanks again for reporting. This has been fixed in #1813. Please update the package using geemap.update_package() and restart the kernel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants