skip to Main Content

#I cant export the layer to my google drive because of this error:Exported bands must have compatible data types; found inconsistent types: Float64 and Float32. (Error code: 3). can anyone help me with this problem.

var band = ['B11','B8', 'B4', 'B3', 'B2'];
var image = ee.ImageCollection("COPERNICUS/S2_SR_HARMONIZED").select(band).filterBounds(table)
            .filterDate('2023-12-01','2023-12-31').filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE",20)).median()
            .clip(table);
            
var visparams = {min:0.0, max:3000, bands:['B8','B4', 'B3']};
print(image, visparams,'image');

Map.addLayer(image,visparams, 'image');

var nd= function(image){
          
        var ndwi= image.normalizedDifference(['B3','B8']).rename('NDWI');
          return image.addBands(ndwi);
};

var nd1 = nd(image);

Map.addLayer(nd1.select('NDWI'),{palette: ['red', 'yellow', 'green', 'cyan', 'blue']},'nd2');

Export.image.toDrive({
  image: nd1,
  description: "NDWI_2023",
  region: table,
  maxPixels:380681498 ,
  scale: 10, 
})

2

Answers


  1. you need to cast the bands in the image to the same type. Since your NDWI band is likely Float64, you can cast all bands in the image to Float64

    var nd = function(image) {
        var ndwi = image.normalizedDifference(['B3', 'B8']).rename('NDWI').toFloat(); // Ensure NDWI is in Float32
        return image.addBands(ndwi);
    };
    
    var nd1 = nd(image).toFloat(); // Ensure the whole image is in Float32
    
    Map.addLayer(nd1.select('NDWI'), {palette: ['red', 'yellow', 'green', 'cyan', 'blue']}, 'nd2');
    
    Export.image.toDrive({
      image: nd1,
      description: "NDWI_2023",
      region: table,
      maxPixels: 380681498,
      scale: 10 // define scale here
    });
    
    Login or Signup to reply.
  2. This should help

    Export.image.toDrive({
      image: nd1.select('NDWI').cast({'NDWI': 'double'}), //Cast to float64
      description: "NDWI_2023",
      region: table,
      maxPixels:380681498 ,
      scale: 10, 
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search