The usual cause of the problem "my export is all black or all white" is that one has used Map.addLayer
with visualization parameters to rescale specific bands for RGB, but not done that with the export. The result is an image file that may be suitable for import into GIS software but is not for normal image viewing software — or at least has an extremely low contrast.
You've got a different variation on this problem: the numerical range is OK, but you're exporting a file with floating-point values, and your viewing software is probably assuming they will be between 0.0 and 1.0, not 0.0 and 255.0; hence all the pixels are out of range. Other viewing software might entirely refuse to open the file.
The original data set has type unsigned 8-bit integer, but when you take the mean()
, that produces double float values, so you just need to convert it back to integer. You also probably want to select the RGB bands like you did for visualization.
Export.image.toDrive({
image: dataset.mean().uint8().select(['R', 'G', 'B']),
...
However, another option is to use ee.Image.visualize
to simply apply the same transformations that Map.addLayer
will:
Export.image.toDrive({
image: trueColor.mean().visualize(trueColorVis),
...
Note that I'm starting from your trueColor
, not dataset
, to pick up the band selections. An equivalent option would be to change trueColorVis
to specify bands; this makes it even simpler to ensure that your map and export share the same characteristics. In this version, note that the variable trueColor
is gone:
var dataset = ee.ImageCollection('USDA/NAIP/DOQQ')
.filter(ee.Filter.date('2012-01-01', '2013-12-31'));
var trueColorVis = {
bands: ['R', 'G', 'B'],
min: 0.0,
max: 255.0,
};
Map.addLayer(dataset, trueColorVis, 'True Color');
Export.image.toDrive({
image: dataset.mean().visualize(trueColorVis),
description: 'Kingfire_RGB_pre',
scale: 30,
region: geometry,
fileFormat: 'GeoTIFF',
formatOptions: {
cloudOptimized: true
}
});