0

I am trying to get a number of the sum of all pixels in google earth engine, this is what I tried

var PopulationCount = ee.ImageCollection("CIESIN/GPWv411/GPW_Population_Count");
function filterbyyear(image, year) {
  return image.date().get('year').eq(year);
}

var year = 2020;
var pop = PopulationCount.filter(ee.Filter.calendarRange(year, year, 'year')).first();

function SumAllPixels(image) {
  var sum = image.reduceRegion({
    reducer: ee.Reducer.sum(),
    geometry: image.geometry(),
    scale: 30,
    maxPixels: 1e9
  });
  return sum;
}

var sum = SumAllPixels(pop);

print(sum);

But I get the following error:

Dictionary (Error) Image.reduceRegion: Provide 'geometry' parameter when aggregating over an unbounded image.

It seems that it wants me to crop the image to a smaller unit, but I am not sure

Derek Corcoran
  • 3,930
  • 2
  • 25
  • 54

1 Answers1

0

You're trying to estimate the population count for the whole globe. Is that what you intend to do? If so, explicitly specify the geometry and use it when reducing the region. The image is unbounded, like the error message says, so you cannot use it's geometry for the reduction.

  var geometry = ee.Geometry.BBox(-180, -90, 180, 90)
  ...

  var sum = image.reduceRegion({
    reducer: ee.Reducer.sum(),
    geometry: geometry,
    scale: 30,
    // maxPixels: 1e9,
    bestEffort: true,
    maxPixels: 1e6
  });
  return sum;

The reduction will fail though. At scale: 30 you will need a lot more than the maxPixels: 1e9 you specified. You either have to increase maxPixels or scale.

Daniel Wiell
  • 253
  • 2
  • 5