Skip to content

Instantly share code, notes, and snippets.

@henrique
Created January 4, 2020 12:17
Show Gist options
  • Save henrique/cdbde6182df98f660f7ec94cb652ff1b to your computer and use it in GitHub Desktop.
Save henrique/cdbde6182df98f660f7ec94cb652ff1b to your computer and use it in GitHub Desktop.
// Make a suitable image for `reduceConnectedComponents()`
// by adding a label band to the `img_pop3` image.
img_pop3 = img_pop3.addBands(patchid.select('labels'));
// Calculate the total population in demand area
// defined by the previously added "labels" band
// and reproject to original scale
var patchPop = img_pop3.reduceConnectedComponents({
reducer: ee.Reducer.sum(),
labelBand: 'labels',
}).rename(['pop_total']).reproject(img_pop3.projection())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment