1

I'm trying to calculate the population within a certain radius around a specific pixel, but I don't know how to define the geometry of the region to reduce.

This is what I would imagine it might look like, where "clipped" is the overall region:

var radiusPop = clipped.reduceRegion({

reducer: ee.Reducer.sum(),

geometry:

scale: 30,

maxPixels: 1e9

});

Essentially I'm trying to add a band to my image that contains the population within a certain radius around the pixel. I can't figure out how to define the geometry for each pixel.

3
  • My suggestion is that you convert the pixel to a featureCollection using image.reduceToVectors() and then apply a buffer around the new featureCollection using ee.Feature.buffer()
    – sermomon
    Aug 28, 2022 at 20:21
  • @sermomon thanks! Which reducer do you suggest using here? I'm envisioning just a sum of individual pixel values, but I'm not sure how to reduce. Would it be "null," then operating over the selected geometry?
    – geor4nge
    Aug 28, 2022 at 22:10
  • If you want to obtain the mean of the pixels population you should use ee.Reducer.mean(). This tutorial Will clarify developers.google.com/earth-engine/tutorials/community/…
    – sermomon
    Aug 29, 2022 at 7:40

1 Answer 1

1

There are several ways to do this. You can for instance use reduceNeighborhood() to calculate the sum around all the pixels in the image, controlling the "geometry of the region to reduce" with the kernel. Then you extract the value for a specific pixel with reduceRegion().

var populationSum = clipped.reduceNeighborhood({
  reducer: ee.Reducer.sum(), 
  kernel: ee.Kernel.circle(200, 'meters'), // Control 
  inputWeight: 'mask'
})

var populationAroundPoint = populationSum.reduceRegion({
  reducer: ee.Reducer.first(), 
  geometry: point, 
  scale: 100, 
}).getNumber('population_sum')

https://code.earthengine.google.com/329c5e5109cecae8dcb70ab44bf81609

1
  • Perfect, thanks, this is super helpful! I'm wondering one other thing - when I display the map, the data appear to show correctly. But when I zoom in or out, the color changes in certain places. Is this because of some scaling issue? Why would there be a different display depending on the zoom level? See here for an example: zoomed out (i.imgur.com/SsWJREG.png), zoomed in (i.imgur.com/OMPg2Hp.png). Is one of these inaccurate?
    – geor4nge
    Aug 29, 2022 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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