3

I have computed NDVI from Landsat7 image, but when I want to export the result in google drive with Export.image.toDrive() it failed with the message error : Fail with an error : Error: Exported bands must have compatible data types; found inconsistent types: Float32 and Float64.

How can I overpass this issue ?

/*-------------------------------------------------------------
                             FUNCTION
-------------------------------------------------------------*/

// This function adds a band representing the image timestamp.
var addTime = function(image) {
  return image.addBands(image.metadata('system:time_start')
    .divide(1000 * 60 * 60 * 24 * 365));
};

// COMPUTE NDVI OVER A COLLECTION FUNCTION
var addNDVI = function(image) {
  var ndvi = image.normalizedDifference(['B4', 'B3']).rename('NDVI');
  return image.addBands(ndvi);
};


/*-------------------------------------------------------------
                             END
-------------------------------------------------------------*/

//2001
var img2001 = ee.Image("LANDSAT/LE7_L1T/LE72040492001066EDC00").clip(zone_travail);

var withNDVI = addNDVI(img2001).select('NDVI');
var withNDVI = addTime(withNDVI);

print(withNDVI);


/*------------------------------------------------------------------------------------------
                                  SAVE DATA IN MY DRIVE 
--------------------------------------------------------------------------------------------*/


Export.image.toDrive({
  image: withNDVI,
  description: 'ls7_ndvi_2001',
  scale: 30,
  region: zone_travail
});
2

Cast the whole darn thing to a 32-bit float: withNDVI.float(). Of course, make sure you're not getting any overflow, but looks safe here.

2

The issue is that you are attempting to export two bands that have different data datatypes (float vs. double):

enter image description here

and because the format of the output file (GeoTIFF) does not (at least in practice) support mixing data types, because the libtiff library does not support it. Given this, Earth Engine does not support exporting images with mixed band types.

The solution, as Nicholas suggests, is to make sure that all of the exported bands have a consistent data type. This is probably best accomplished by using ee.Image.float() to convert your "time" band into a float:

var addTime = function(image) {
  return image.addBands(
    image.metadata('system:time_start')
      .divide(1000 * 60 * 60 * 24 * 365).float()
      .rename('time')
    );
};

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.