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 ?


// 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));

var addNDVI = function(image) {
  var ndvi = image.normalizedDifference(['B4', 'B3']).rename('NDVI');
  return image.addBands(ndvi);


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

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


                                  SAVE DATA IN MY DRIVE 

  image: withNDVI,
  description: 'ls7_ndvi_2001',
  scale: 30,
  region: zone_travail

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.

| improve this answer | |

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(
      .divide(1000 * 60 * 60 * 24 * 365).float()
| improve this answer | |

Nicholas' answer is spot on, but if you want to be sure of avoiding any overflow issues then you could cast as a 64-bit float instead: withNDVI.toDouble(). This could be potentially be important with some images.

| improve this answer | |

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.