1

Given a 30 m resolution Image in Google Earth Engine, I would like to export it to Google Drive at a 1000 m resolution such that within each 1000 m pixel I obtain the sum of the underlying 30 m pixels.

I know the reduceResolution function, which however is suitable only for small areas (up to 65536 pixels) and does not allow to specify the output resolution.

In other words, I would like to achieve what in R can be done with the function aggregate of the raster package.

Take the following example:

var image = image.clip(geometry)
Map.addLayer(image);
Export.image.toDrive({
  image: image,
  description: 'image',
  scale: 30,
  maxPixels: 10000000000000, 
  fileFormat: 'GeoTIFF',
  crs : 'EPSG:4326'
});

If I change the scale parameter in the export function to 1000, which is my objective, GEE will interpolate pixels to decrease the resolution, but not sum their value, which is my objective.

1

reduceResolution works for your application. The 65536 pixel limit you mentioned is the limit on number of small pixels to be aggregated into a large pixels, and not the total number of pixels in the image. Since you are combining 30 m pixels into 1000 m pixels, it represents an aggregation of only 1000/30*1000/30 = ~1100.

Since you wish to aggregate the values of small pixels into the large pixel, I would use reduceResolution with ee.Reducer.mean() reducer but then multiply the output by the total number of small pixels within a large pixels. This makes use of the simple algebraic property:

number of pixels x average value = sum of pixels.

The psuedo-code would be something like:

  1. .unmask() the original image to replace masked pixels with zeroes
  2. use .reduceResolution() with two reducers: ee.Reducer.mean() and ee.Reducer.count(). This results in an image with two bands
  3. .reproject() the resultant image into the new resolution (1000 m)
  4. Multiply the two bands to get the required output.

Here is an implementation of the same.

And here is the input versus output comparison

Input image (color scale: 0 to 50)

enter image description here

Output image (color scale: 0 to 5000) enter image description here

3
  • WOW, I am so grateful! Thanks! I believe such a detailed answer to this type of problem was missing from GIS Stackexchange. – Jackk Mar 10 at 21:35
  • Just one clarification question: in the maxPixels parameters in your example shouldn't 1000/30 = 1112 be specified instead of 50*50? – Jackk Mar 11 at 8:29
  • 1
    Yes it should be 1000/30*1000/30 = 33*33. But I just ramped it up to 50*50 to be on the safe side since it is just the "maxPixels" and not the exact number of pixels used to scale the resolution. – kkrao Mar 11 at 17:04

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.