1

I have uploaded a table containing information on river basins within countries (https://code.earthengine.google.com/?asset=users/basins/TFDD_BCU). I want to calculate the mean population density in the basins from an image. However, I obtain many missing values though the image covers the whole world. Is there a way to obtain the mean for all regions?

According to Taras' and Ricacardo's proposal, I changed the code to this:

var Pop1975 = ee.Image('JRC/GHSL/P2016/POP_GPW_GLOBE_V1/1975');
var BCU = ee.FeatureCollection('users/basins/TFDD_BCU');

var Pop1975filtered = Pop1975.filter(ee.Filter.gt('BCU', 0));

var Pop1975mean = Pop1975filtered.reduceRegions({
  collection: BCU,
  reducer: ee.Reducer.mean(),
  scale: 50,
});

Export.table.toDrive({
  collection: Pop1975mean,
  description: 'Pop1975mean',
  fileFormat: 'CSV'
});

However, I get this error message when execuding the code: "Pop1975.filter is not a function". Any suggestions?

0

I am not used to working with EE but why not creating a prefiltered feature collection for pixels with a valid measurement (pseudo code, not tested): // Filter to get only valid numbers if 'BCU' is your attribute of choice.

var Pop1975filtered = Pop1975.filter(ee.Filter.gt('BCU', 0));
| improve this answer | |
  • This does not work as "Pop1975" is an image. I tried this: var Pop1975filtered = Pop1975.gte(0); But this also not the solution. The values are still missing and for those few observations that are not missing I now get a 1. – Sven Christens Jul 4 '19 at 9:25
  • updateMask is required. .gte is a boolean operator and returns 0 (not greater than 0) or 1 (greater than 0). – Jobbo90 Nov 15 '19 at 13:11
0

I'm guessing your mean calculation is correct but it includes 0 values. You want to mask those values first:

var Pop1975 = ee.Image('JRC/GHSL/P2016/POP_GPW_GLOBE_V1/1975');
var BCU = ee.FeatureCollection('users/basins/TFDD_BCU');


Map.addLayer(Pop1975.updateMask(Pop1975.neq(0))) // see all zero pixels removed.
Map.addLayer(ee.Feature(BCU.first()))

// select first feature for testing
var testCollect = ee.FeatureCollection(ee.Feature(BCU.first())) 

var Pop1975mean = Pop1975.updateMask(Pop1975.neq(0)).reduceRegions({
    collection: BCU,
    reducer: ee.Reducer.mean(),
    scale: 250 , // native resolution is in 250 meters according to metadata
})

print(Pop1975mean, 'Pop1975mean')

Export.table.toDrive({
  collection: Pop1975mean,
  description: 'Pop1975mean',
  fileFormat: 'CSV'
});
| improve this answer | |

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.