1

I want to export an NDVI map for the Quebec province, Canada, from GEE so that I can select my sampling locations after importing the map on QGIS. But I get this error:

Error: Export too large: specified 8030040147504 pixels (max: 1000). Specify higher maxPixels value if you intend to export a large area. (Error code: 3)

I tried to look at videos on YouTube and read answers to similar questions on StackExchange, but the examples are for one type of Landsat and not for a mix of two Landsats. I will really appreciate it if someone can help me with modifying the code.

Here is the link to the script: https://code.earthengine.google.com/0ca4247b9b45abbece8491289b65a878

Here is the code:

var S2 = ee.ImageCollection("LANDSAT/LT05/C02/T1_L2")
var S9 = ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")


// to add Geometry
var addNDVI = function(image) {
  var ndvi = image
    .clip(geometry)
    .normalizedDifference(['SR_B4', 'SR_B3'])
    .rename('NDVI');
  return image.addBands(ndvi);
};

var addNDVI2 = function(image) {
  var ndvi = image
    .normalizedDifference(['SR_B5', 'SR_B4'])
    .rename('NDVI');
  return image.addBands(ndvi);
};
// Filter par date et calculer la mosaique
var withNDVI = S2.map(addNDVI).filterDate('1988-06-15', '2012-08-30').qualityMosaic('NDVI').select('NDVI');
var withNDVI_2 = S9.map(addNDVI2).filterDate('2013-06-15', '2022-08-30').qualityMosaic('NDVI').select('NDVI');

var NDVI_diff = withNDVI_2.subtract(withNDVI)

var ndviParams = {min: -1.5, max: 1.5, palette: ['black', 'white', 'green']};

//visualiser sur la carte
Map.centerObject(geometry)
Map.addLayer(NDVI_diff, ndviParams, 'NDVI image');

// Exporter l'image vers Drive.
Export.image.toDrive({
  image: withNDVI,
  description: 'NDVI-1985',
  scale: 10,
  fileFormat: 'GeoTIFF',
  formatOptions: {
    cloudOptimized: true
  },
  maxPixels: 1e13
});

1 Answer 1

1

You are trying to export the whole world in 10m scale:

print(NDVI_diff.geometry())

Polygon, 5 vertices type: Polygon coordinates: List (1 element) 0: List (5 elements) 0: [-180,-90] 1: [180,-90] 2: [180,90] 3: [-180,90] 4: [-180,-90]

You can explicitly specify the region when exporting.

Export.image.toDrive({
  image: withNDVI,
  description: 'NDVI-1985',
  region: geometry,
  scale: 10,
  fileFormat: 'GeoTIFF',
  formatOptions: {
    cloudOptimized: true
  },
  maxPixels: 1e13
})

Also, avoid clip() until the last step of your processing, as it's quite costly. Here, you're doing it when mapping over the collection. Instead, clip the image you add to the map.

5
  • Thanks for your response. Actually, I am almost an amateur in GEE, and I am not familiar with the scale and max pixel. I want to export the map for the Quebec province, Canada, as the main part of my Ph.D. project. I tried to specify the geometry by drawing a rectangle as you can see in the link. But I am not sure if I did it correctly. Can you please help me more so that we can export the image for only Quebec? Thanks a lot
    – Mobina
    May 30 at 11:42
  • Just add region when exporting - i've got the code snippet in my answer. That will limit the export to only your geometry. The scale is the resolution in meters per pixel and maxPixels is the maximum number of pixels you want to allow in your export. May 30 at 11:48
  • Thanks for the clarification. I added the region, but still I get the same error. code.earthengine.google.com/87bff44626a48eee10dedd40612c308a
    – Mobina
    May 30 at 12:20
  • I don't see any errors when running your script. Are you sure it's the same error, not something else, like running out of Google Drive space? May 31 at 12:47
  • Thank you so much, Daniel. I have just tried it once again and I noticed that it works. Thanks a million
    – Mobina
    Jun 1 at 14:07

Your Answer

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

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