0

Using this code https://code.earthengine.google.com/36d0af209d34063ff109c57c40d1901e I calculate the area of pixels inside a set of 5km radius Features.

From the code results printed in the console, it is evident that the calculation leads to cases where the sum of area pixels calculated is substantially larger than the area of the feature itself (5^2 * pi), which makes no sense.

Where is the issue?

var getCentroid = function(feature) {
  var centroid = feature.geometry().centroid()
  return ee.Feature(centroid)
}

var table = ee.FeatureCollection("users/giacomofalchetta/UC_cities_global")

var table = table.map(getCentroid)

var bufferBy = function(size) {
  return function(feature) {
    return feature.buffer(size);   
  };
};

var table = table.map(bufferBy(5000))

var area = ee.Image.pixelArea().divide(1000000)

var aFeatureCollection = area.reduceRegions({
  collection: table,
  reducer: ee.Reducer.sum(),
  scale: area.projection().nominalScale(),
});

print(aFeatureCollection.reduceColumns({
  reducer: ee.Reducer.max(),
  selectors: ['sum'],
}));

print(ee.Number.expression("(3.14159*5000*5000)/1e6"))

1 Answer 1

1
var area = ee.Image.pixelArea().divide(1000000)
...
  scale: area.projection().nominalScale(),

The default projection of ee.Image.pixelArea() is EPSG:4326 — WGS 84 longitude and latitude in degrees. Print the nominalScale() and you'll learn that the a degree at the equator is 111319.5 meters. Your 5000-meter-radius buffered point features fit inside a single one of these 111-km pixels — the reason you're getting a plausible value at all is solely because of weighting in the reduction.

If you use a smaller scale for the reduction, you will get a more accurate result.

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.