1

I'm using the GlobalSurfaceWater-Dataset in GEE for creating a mask layer. The mask I do need should only contain water areas bigger than a certain threshold, so I need to get an information on the area of each of the patches. I did try the .reduceConnectedComponents() function using a sum reducer:

var double= extentGSW.addBands(extentGSW);
var patchreduce= double.reduceConnectedComponents({
  labelBand: "max_extent",
  reducer: ee.Reducer.sum(), //sum up nr of pixels per patch 
maxSize: 2000,
});

I would think this should lead to each pixel in one patch getting assigned the value of the total number of pixel in that patch, which would represent the area. However in the output layer pixels in a patch that visibly consist of e.g. two pixels have values of 300. Is there some error in the code? Or rather some problems with scale/projection maybe? Requesting the scale (pixel size) of the output layer returns 30m, which actually is the correct resolution for GSW.

Did also try the .connectedPixelCount() function, but it lead to the same problem. Some hints? If my question isn't very understandable, I'm sorry but ready to answer any querys..

1 Answer 1

1

You need to .reproject() the patchreduce var so that you can specify the resolution to perform the .reduceConnectedComponents() operation at. When you are viewing/inspecting patchreduce in the Map, the result depends on the Map scale. You can ensure the analysis is done at the data's native scale by calling:

patchreduce.reproject(patchreduce.projection())

I've added .reproject() to your example:

var double= extentGSW.addBands(extentGSW);
var patchreduce= double.reduceConnectedComponents({
  labelBand: "max_extent",
  reducer: ee.Reducer.sum(), //sum up nr of pixels per patch 
maxSize: 2000,
});

Map.addLayer(
  patchreduce.reproject(patchreduce.projection()).selfMask(),
  {min: 0, max: 10},
  'Patch size'
);

Please see the Scale and Projections sections of the Earth Engine Developer Guide for more information.

Your Answer

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

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