1

I am new to GIS and Google Earth Engine Platform. I am trying to get the night lights for all counties in a country. I have uploaded the shapefile as an asset to the platform. I want to export the avg_vis for the region as per the boundaries defined by the shapefile for each county. I want to export them hopefully as an excel file. Additionally, I want to do this for 35 years for which data is available. The code I have till now is:

var shp = ee.FeatureCollection(table);
var dataset=imageCollection.filter(ee.Filter.date('1992-01-01', '1992-12-31')).map(function(image){return image.clip(shp)});
var nighttimeLights = dataset.select('avg_vis');
var nighttimeLightsVis = {
  min: 3.0,
  max: 63.0,
};
var nl=dataset.reduceRegions({ 


collection: shp,
  reducer:ee.Reducer.mean()

});

    print(table.size());
    Map.addLayer(nighttimeLights, nighttimeLightsVis, 'Nighttime Lights');

imageCollection is the DMSP Nightlights Image Collection and table is the shapefile that I have. I am getting an error that reduceRegions function does not exist. I understand that it maybe happening due to casting but how do I resolve it and also, how to export it subsequently?

1

Reduceregions should be applied to single images, instead of an image collection. Therefore, you shoul dmap over the image collection:

// map over the collection (reduceRegions works on single imagery)
var nl = nighttimeLights.map(function(image){
  var year = image.date().format('YYYY');
  var feats = image.reduceRegions({ 
    collection: shp,
    reducer:ee.Reducer.mean(),
    scale: 1000 // scale to do reduce region, depends on the accuracy/location on earth 
  })
  // return a feature collection 
  .map(function(feat){
    return ee.Feature(ee.Feature(feat).set('year', year)
            // copy the image properties
            .copyProperties(image, image.propertyNames()));
  });
  return feats;
  // flatte nthe feature collection of collection
}).flatten();

Then export as follows:

// export
Export.table.toDrive(nl, 'nightlight', 'SPECIFYFOLDER', '', 'CSV');
print(nl)

link code note that I used a random made geometry for testing this. You should use your own, which you should share if it throws an error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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