1

I am quite new to Google Earth Engine.

I am trying to export a VIIRS night-time light image with an attribute table attached (displaying the mean, median etc) which is also clipped to India (I am using a shapefile). I am completely lost when it comes to exporting the image and attributes.

Below is my code so far:

var variable =  'NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG';
var region = ee.FeatureCollection("users/user/india_adm").geometry();
var start_date = '2018-01-01';
var finish_date = '2018-12-31';
var bands = 'avg_rad';
var image = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG');

// Load input imagery. NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG
var dataset = ee.ImageCollection(variable)
                  .filterDate(start_date, finish_date)
                  .select(bands)
                  .filterBounds(region);

// Convert the layer
dataset = dataset.map(function(img){
  var date = img.get('system:time_start');
  return img.set('system_time_start', date);
});

// Create a function that takes an image, calculates the mean over a geometry and returns the value and the corresponding date as a feature.
var createData = function(img){
  var date = img.get('system_time_start');
  var valueMean = img.reduceRegion({reducer: ee.Reducer.mean(), geometry: region, scale: 30, maxPixels: 16016779});
  var valueSum = img.reduceRegion({reducer: ee.Reducer.sum(), geometry: region, scale: 30, maxPixels: 16016779});
  var valueMedian = img.reduceRegion({reducer: ee.Reducer.median(), geometry: region, scale: 30, maxPixels: 16016779});
  var valueStdDev = img.reduceRegion({reducer: ee.Reducer.stdDev(), geometry: region, scale: 30, maxPixels: 16016779});
  var valueVariance = img.reduceRegion({reducer: ee.Reducer.variance(), geometry: region, scale: 30, maxPixels: 16016779});

  var ft = ee.Feature(null, {'system:time_start': date,
                             'date': ee.Date(date).format('Y/M/d'),
                             'Mean': valueMean.get('avg_rad'),
                             'Sum': valueSum.get('avg_rad'),
                             'Median': valueMedian.get('avg_rad'),
                             'stdDev': valueStdDev.get('avg_rad'),
                             'Variance': valueVariance.get('avg_rad'),
  });
  return ft;
};
// Apply the function to each image in dataset
var serie = dataset.map(createData);

var collection = ee.ImageCollection(variable)
                  .filterDate(start_date, finish_date)
                  .select(bands)
                  .filterBounds(region);
                  
var composite = collection.reduce(ee.Reducer.sum());

var canny = ee.Algorithms.CannyEdgeDetector({
  image: composite, threshold: 100, sigma: 1
});

var nighttimeVis = {min: 0.0, max: 60.0};

print('composite', composite);

Map.setCenter(78.40263161385201, 21.17558399803013, 4.5);

Map.addLayer(composite.clip(region),{min:0,max:60.0,bands:"avg_rad_sum"});

1 Answer 1

1

You'd probably export the composite image as an image file and separately the table with information as e.g. a CSV file:

Export.table.toDrive({collection: serie, 
                      description: 'datatable', 
                      fileFormat: 'CSV'})
Export.image.toDrive({image: composite, 
                      description: 'exportImage', 
                      region: region, 
                      scale: 30,
                      maxPixels: 10e10})
3
  • Hi, thanks for your response! However, is it possible to adjust my export.table.toDrive to include a geometry column, so it is easier to import into ArcGIS?
    – Naomi
    Commented Jun 17, 2020 at 14:29
  • You'd probably best export it as SHP file. Change 'CSV' to 'SHP'
    – Kuik
    Commented Jun 17, 2020 at 14:35
  • Hi, i used 'SHP' and the export looked like it was downloading but this went on for over 4 hours so I think there is something wrong with my code as it should not be taking that long
    – Naomi
    Commented Jun 17, 2020 at 19:41

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.