Google Earth Engine – Understanding Image Dimensions

banddimensionsgoogle-earth-engineimage

How can one get image (band) width and height on the server side?

On the user side you do it with image.getInfo().bands[0].dimensions, following Extracting information from Google Earth Engine image by row and column position?

However, it is not possible to map such a function, since getInfo() is a user-side function.

The task sounds extremely simple, since you always see band dimensions whenever you print an image, but how to get them as a list or a numbers?

enter image description here

Best Answer

You can use ee.Algorithms.Describe() (bit hidden in the documentation)

this should work :

var numberOfPixels = function(img){
  
  var imgDescription = ee.Algorithms.Describe( img );
  var height = ee.List( ee.Dictionary( ee.List(  ee.Dictionary( imgDescription ).get("bands") ).get(0) ).get("dimensions") ).get(0);
  var width = ee.List( ee.Dictionary( ee.List(  ee.Dictionary( imgDescription ).get("bands") ).get(0) ).get("dimensions") ).get(1);
  
  //print("width", width )
  //print("height", height )
  
  return  ee.Number( width ).multiply( ee.Number( height ) );
};