google-earth-engine – Exporting All Images from VIIRS ImageCollection to Google Drive

exportgoogle-earth-enginegoogle-earth-engine-javascript-api

I am trying to export all images of the image collection of VIIRS. I am following the answer from this post. Instead of setting a bounding box as a clipping layer I have a .shp of my study area. When I run the code I am receiving this error:

In users/fitoprincipe/geetools:batch
Line 133: collection.size is not a function

Here is the code:

 var batch = require('users/fitoprincipe/geetools:batch');
    // Load the VIIRS ImageCollection.
    var dataset = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG')
    .filterBounds(table)
    .select('avg_rad')
    .first()
    .clip(table);
    batch.Download.ImageCollection.toDrive(dataset, 'Folder',
    {scale: 460,
    region: (table),
    type: 'float'})

Why that error? I believe I am following exactly the steps like others did and when I download a single monthly image I do not have any issue.

Best Answer

There is no problem with Principe's code. Here is the solution:

//var table = ee.FeatureCollection("users/nikostziokas/manchester");
var batch = require('users/fitoprincipe/geetools:batch')

// Load Landsat 8 imagery and filter it  
var collection = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG')
  .filter(ee.Filter.date('2013-05-01', '2021-12-31'))
  .filterBounds(table)
  .select('avg_rad')
/* from here I was transforming the collection into an Image
  .first()
  .clip(table); // clip is an ee.Image method
*/
  
var count = collection.size()
print("Collection", count)

// export collection to google drive
batch.Download.ImageCollection.toDrive(
  collection, 
 'Folder', 
  {name: 'ntl_{system:index}',
  crs: 'EPSG: 27700',
  type: 'float',
  scale: 460,
  region: table});