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
});
Answer
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.
No comments:
Post a Comment