Skip to content

Commit

Permalink
Add ImageCollection to map.AddLayer
Browse files Browse the repository at this point in the history
Reduces collection using median value and renders the reduced image as an EE raster layer.
  • Loading branch information
zacdezgeo committed Mar 5, 2025
1 parent 140c1e6 commit c03b8ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ee_plugin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def add_or_update_ee_layer(
if isinstance(eeObject, ee.Geometry):
return add_or_update_ee_vector_layer(eeObject, name, shown, opacity)

if isinstance(eeObject, ee.ImageCollection):
# TODO: is median a fair assumption?
reduce_image = eeObject.reduce(ee.Reducer.median())
return add_or_update_ee_raster_layer(reduce_image, name, vis_params, shown)

raise TypeError("Unsupported EE object type")


Expand Down
20 changes: 20 additions & 0 deletions test/test_add_image_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import ee
from qgis.core import QgsMapLayer

from ee_plugin import Map


def test_add_landsat_cloud_cover(clean_qgis_iface):
collection = (
ee.ImageCollection("LANDSAT/LC09/C02/T1_L2")
.filterDate("2021-01-01", "2021-12-31")
.filter(ee.Filter.lt("CLOUD_COVER", 10))
)
Map.addLayer(collection, {}, "LANDSAT_2021")
layers = clean_qgis_iface.mapCanvas().layers()
assert len(layers) == 1
assert layers[0]
layer = layers[0]
assert layer.name() == "LANDSAT_2021"
assert layer.type() == QgsMapLayer.RasterLayer
assert layer.providerType() == "EE"

0 comments on commit c03b8ee

Please sign in to comment.