0

The following code downloads 3 band burned area rasters for each month in the defined range.

I am only interested in the pixels in the 'BurnDate' band, which have values between 1 and 366.

I wish to download all pixels in the defined range, which meet these conditions, as a single raster. This could be reclassified so that 1 = within range, 0 = nodata.

    var batch = require('users/fitoprincipe/geetools:batch')
    
    var dataset = ee.ImageCollection('MODIS/006/MCD64A1')
                      .filter(ee.Filter.date('2000-01-01', '2001-01-01'))
                      .select(['BurnDate']);
    // Select "1 < BurnDate < 366" here
 
    
    batch.Download.ImageCollection.toDrive(dataset, '1899', 
          {region: geometry, // use a polygon
           scale: 500,
           fileFormat: 'GeoTIFF',
           crs: 'EPSG:4326'
          })

2 Answers 2

2

You can use ee.ImageCollection.toBands() to convert each image in an image collection to a band in a multiband image. Then just export that single multiband image.

burnedArea = burnedArea.toBands();
Export.image.toDrive({
  image: burnedArea ,
  description: 'BurnedImage_multiband',
  folder: 'FOLDER',
  region: geometry,
  scale: 500,
  fileFormat: 'GeoTIFF',
  crs: 'EPSG:4326'
});
5
  • the variable I want to download is "dataset" and when I try burnedArea = dataset.toBands(); I get this error - Error: Exported bands must have compatible data types; found inconsistent types: Int16 and Byte.
    – Stuey17
    Aug 12, 2021 at 20:48
  • Sound like you have bands with different data types. Try casting the images to a single datatype. For example, for integer: dataset = dataset.map(function(image){ return image.int()}) Aug 12, 2021 at 21:07
  • The 'BurnDate' band contains the information I want, and when I use this method the output TIFF contains many bands of burn date, but they all have values of 0
    – Stuey17
    Aug 13, 2021 at 9:55
  • According to the collection's information 0 corrresponds to unburned (see: developers.google.com/earth-engine/datasets/catalog/…). Try to locate an area that was indeed burned and see if the export shows it. Aug 13, 2021 at 14:14
  • I have added more information to my question perhaps this makes what I'm looking for clearer.
    – Stuey17
    Sep 3, 2021 at 16:54
1
+50

Following the new edits of the question, I think you are interested in using a reducer to obtain a single image from the images contained in the filtered image collection. First, you should calculate the maximum value by pixel and then just apply a condition over this image (greater than or equal than 1). Pixels that meet this condition will get a value of 1, while pixels that not, a value of zero. Finally, due to the fact that there are pixels masked in the final image, you can unmask them and set them to 0, so you get an image that only contains ones and zeros.

// Reduce all the images of one year in a single image.
// Get the max value by pixel
var maxIm = dataset.max();
// Get an image that is 1 where pixels have a value greater than or equal to 1
// and 0 where pixels had a value of 0
var burnedIm = maxIm.gte(1)
                    // unmask masked values and set them to 0
                    .unmask(0);

// Visualise the image    
Map.addLayer(ee.Image(burnedIm),{min: 0, max:1},'first');

// Export the image to your drive    
Export.image.toDrive({
 image: burnedIm,
 description: 'burnedIm',
 // 500 m pixels
 scale: 500,
 region: geometry,
 fileFormat: 'GeoTIFF',
 crs: 'EPSG:4326',
 // If geometry is very large you might need to add this argument:
 maxPixels:1e11
});
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.