2

In the below code I'm going to get image id in a function but returns error. Could anyone guide me please? How can I solve this?

enter image description here

code link: https://code.earthengine.google.com/154cea3df7a29cdf0a42b13f3a71f42c

Map.centerObject(table);
Map.addLayer(table);

var uhi = ee.ImageCollection("YALE/YCEO/UHI/Summer_UHI_yearly_pixel/v4")
.filterBounds(table)
.mean().clip(table)

print(uhi)


// normalization process

var normal = function(img){
  
  var id = ee.String(img.get('system:id'))
  
  var min = ee.Number(img.reduceRegion(ee.Reducer.min(), table, 1000).get(id));
  var max = ee.Number(img.reduceRegion(ee.Reducer.max(), table, 1000).get(id));
  
  var normalization = (img.subtract(min)).divide(max.subtract(min));
  
  return normalization;
};


var uhiNormal = normal(uhi.select('Daytime'));

print(uhiNormal);
1
  • After using mean() at the beginning of the code, you lost the ID, because you are converting the collection into a single image (a mean composite). This composite does not have an id unless you set it.
    – HMSP
    Jun 9 at 14:39
1

As @HMSP pointed out, after using mean() at the beginning of the code, you lost the ID because you are converting the collection into a mean composite without any id. Following code produces normalized images (by using your normalization formula) with its respective id for each image in Image Collection.

Map.centerObject(table, 11);
Map.addLayer(table);

var imageVisParam = {"opacity":1,
                     "bands":["Daytime"],
                     "min":0.07318689642113053,
                     "max":0.9887331944707479,
                     "palette":["1016ff","14fff5","ffb62d","fdff8f"]};

var uhi = ee.ImageCollection("YALE/YCEO/UHI/Summer_UHI_yearly_pixel/v4")
  .filterBounds(table);

print("first image", uhi.first());

var id = ee.String(uhi.first().get('system:id'));

print("id first image", id);

// normalization process

var listOfImages = uhi.toList(uhi.size());

var normal = listOfImages.map(function (img){
  
  var id = ee.String(ee.Image(img).get('system:id'));
  
  var min = ee.Image(img)
    .reduceRegion(ee.Reducer.min(), table)
    .get('Daytime');
    
  var max = ee.Image(img)
    .reduceRegion(ee.Reducer.max(), table)
    .get('Daytime');
  
  var normalization = (ee.Image(img)
    .subtract(ee.Number(min)))
    .divide(ee.Number(max).subtract(ee.Number(min)));
  
  return normalization.set('system:id', id)
                      .select('Daytime')
                      .clip(table);

});

print("List of images in Image Collection", normal);
Map.addLayer(ee.Image(normal.get(0)),imageVisParam, 'normalized');

First image of normalized collection is added to Map Canvas for verification purpose. It can be observed in following picture.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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