I am trying to take an image at a native resolution scale of 250m and reproject it to 5000m and sum the values in the smaller pixels to the larger one.

I can do this in Earth Engine with the following, but it's just re-sampling the data (I'm guessing it's just calculating an average value):

var imageForAnalysis = ee.Image('JRC/GHSL/P2016/POP_GPW_GLOBE_V1/2015');
var proj = imageForAnalysis.projection();

var reprojectedImage = imageForAnalysis
      reducer: ee.Reducer.sum(),
      maxPixels: 1024
      crs: proj,

I've tried changing the reducer to ee.Reducer.sum(), but it does not yield a total value for the larger pixel size.

Any ideas?


You simply need to use the fact that you can calculate the mean using reduceResolutions, and reproject directly on the 5000m pixels. The amount of pixels inside a 5000m is known for the sum.

Here https://developers.google.com/earth-engine/resample is explained that other reducers than ee.reducer.mean() can result in unexpected answers. Probably that explains why the performance is better when using first ee.reducer.mean, and then sum the values using multiply and the known amount of pixels.

// population image
var imageForAnalysis = ee.Image('JRC/GHSL/P2016/POP_GPW_GLOBE_V1/2015');
var proj = imageForAnalysis.projection();

// amount of small pixels inside the reprojected one
var maxPix = ee.Number((5000/250)*(5000/250));

// reproject the image to 5000 m
var reprojectedImage = imageForAnalysis.reduceResolution({
  reducer: ee.Reducer.mean(),
  maxPixels: maxPix
  crs: proj,

// as reproject calculated the average of all 250m pixels inside the 5000m pixels reprojection,
// the sum of 250m pixels inside a 5000m pixel is simply the average times the amount of pixels
var summedImage = reprojectedImage.multiply(maxPix);

// print and add the images to the map
Map.addLayer(imageForAnalysis, {min: 0, max: 100});
Map.addLayer(reprojectedImage, {min: 0, max: 100});
Map.addLayer(summedImage, {min: 0, max: 1000});
  • This was a hypothesis I had, but was unsure whether EE did a random sample within the 5000px area vs. an average. Is this something covered in the docs? – mdaniels Oct 31 '18 at 13:00
  • i think you were right. I updated the answer. See the link in the answer why ee.Reducer.sum() gives unwanted answers. – Kuik Oct 31 '18 at 13:36
  • Ah this makes sense. Going to try it out! – mdaniels Oct 31 '18 at 14:14

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.