0

I am getting an error when trying execute the task to export the animation which states

Error: Image collection must have at least one image to create video (Error code: 3)

// Load the administrative boundary dataset for the entire world.
var adminBoundaries = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017');

// Filter the dataset to get Afghanistan's administrative boundary.
var afghanistanBoundary = adminBoundaries.filterMetadata('COUNTRY_NA', 'equals', 'Afghanistan');

// Define the region of interest (ROI) as the boundary of Afghanistan.
var roi = afghanistanBoundary.geometry();

// Load the MODIS NDVI collection from 2005 to 2006.
var modisNDVI = ee.ImageCollection('MODIS/006/MOD13Q1')
                  .filterDate('2005-01-01', '2006-12-31')
                  .select('NDVI')
                  .filterBounds(roi);

// Define a function to add the date as a band to each image.
function addDate(image) {
  var date = ee.Date(image.get('system:time_start'));
  var year = ee.Image(ee.Number(date.get('year'))).rename('year');
  return image.addBands(year);
}

// Map the addDate function over the collection.
var modisNDVIwithDate = modisNDVI.map(addDate);

// Define the visualization parameters for NDVI.
var ndviParams = {min: 0, max: 9000, palette: ['red', 'yellow', 'green']};

// Define the image collection to animate.
var collectionToAnimate = modisNDVIwithDate.select('NDVI').map(function(image) {
  return image.clip(roi).visualize(ndviParams).set('year', image.get('year'));
});

// Define the animation parameters.
var animationParams = {
  'dimensions': '720',
  'region': roi,
  'framesPerSecond': 2,
  'crs': 'EPSG:3857'
};

// Create and download the video.
print('Generating and downloading the video...');
Export.video.toDrive({
  collection: collectionToAnimate,
  description: 'afghanistan_ndvi_animation',
  dimensions: animationParams.dimensions,
  framesPerSecond: animationParams.framesPerSecond,
  region: animationParams.region,
  crs: animationParams.crs,
  maxPixels: 1e13
});
1

1 Answer 1

0

That's because your geometry is empty. The property name to filter should be 'country_na' instead of 'COUNTRY_NA'

enter image description here

Replace 5th line with

var afghanistanBoundary = adminBoundaries.filterMetadata('country_na', 'equals', 'Afghanistan');

It will work.

1
  • Thank you Oliver Lopez and Saumaya, it is working now
    – Mas
    Apr 17, 2023 at 7:24

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.