1

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

3

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 ) );
};
1

Found the answer

function getDims(i) {
    return ee.Image.pixelCoordinates(i.projection()) // x and y
          .reduceRegion({
              reducer: ee.Reducer.max(),
              geometry: i.geometry(),
              maxPixels: 1e9  // adjust this to suppress warnings
          });
}

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.