I want to clip an ImageCollection with a grid (FeatureCollection) in Google Earth Engine. Every image in the ImageCollection should be clipped with every feature in the FeatureCollection. I need all images as separate segments for further calculations. Therefore, the result should be a new ImageCollection with each image segment including all properties of the original ImageCollection.

I work with Sentinel-1 images (SAR) and generated a grid over my study area. The clipping between the ImageCollection and the grid works (see Code snippet or the link for the GEE script). My problem is that I don't know how I can address the several image segments now for further processing.

var imagecollection = Sent1;
var featurecollection = grid;

var clip_fc = function(col) {
return col.clipToCollection(featurecollection);
var map_ic = imagecollection.map(clip_fc);

print ('New ImageCollection:', map_ic);
Map.addLayer(map_ic, imageVisParam, 'New ImageCollection');


Does anyone have an idea? I'm not that advanced with JavaScript and short explanations or links would be very helpful as well!

1 Answer 1


You can create a function that take as arguments both the image and feature collections and then loop over all the entries of each object using map. Additionally, you need to make a small trick to convert the FeatureCollection coming from the feature collection loop to an ImageCollection and flatten the resulting ImageCollection.

// Function to loop over image and feat collections
var wrap = function(imagecol, featcol){
  // image collection loop
  var resul = imagecol.map(function(image){
    // feature collection loop
    var resul2 = featcol.map(function(feat){
      // make clip and add feat property according to feat id
      return ee.Image(image).clip(ee.Feature(feat))
                              'feat': ee.Feature(feat).id()
    // convert the FeatureCollection to list and convert it to ImageCollection
    return ee.ImageCollection.fromImages(resul2.toList(featcol.size()));
  // Flatten, unnest lists
  return ee.ImageCollection(resul.flatten());

// Apply function
var map_ic = wrap(imagecollection, featurecollection);

print ('New ImageCollection:', map_ic);

// Add layers
Map.addLayer(ee.Image(map_ic.first()), imageVisParam, 'New ImageCollection');
// Select another image using the feat property
Map.addLayer(ee.Image(map_ic.filter(ee.Filter.eq('feat', '-9,119'))
                            'New ImageCollection');
  • Thanks a lot! It works perfectly!
    – lena
    Commented Mar 7, 2022 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.