2

I am new to the earth engine. My question is on how to obtain statistics from the overlapping region of two areas.

I have uploaded a table that contains the locations of river basins (https://code.earthengine.google.com/?asset=users/basins/AqueductBasins). These commonly lie in several countries. I want to obtain the information on the mean population density for these basin areas in a specific country (so: mean for Basin1 in CountryA, mean for Basin1 in CountryB, mean in Basin2 in CountryA and so on).

I have taken this feature collection on the country borders:

var countries = ee.FeatureCollection('ft:1tdSwUL7MVpOauSgRzqVTOwdfy17KDbw-1d9omPw');

This image contains information on the people per cell:

var Pop2015 = ee.Image('JRC/GHSL/P2016/POP_GPW_GLOBE_V1/2015');

I want to print a table with the average people per cell in the basin area in the different riparian states.

1

This should be possible as follows, where 'table' is the feature collection of river basins:

// First, we need to het the geometry of the intersection between every country and basin
// We will save every intersection to a new feature with a property named 'Country' and 'OBJECTID'
// we will add a property 'area' to filter intersection without area and 
// 'avgPeople' as the mean of the pop2015 image in the area of intersection
var mapping = countries.map(function(feat){
  feat = ee.Feature(feat);
  var Country = feat.get('Country');
  var mapping2 = table.map(function(feat2){
    feat2 = ee.Feature(feat2);
    var OBJECTID = feat2.get('OBJECTID');
    var intersection = feat.geometry().intersection(feat2.geometry());
    var avgPeople = Pop2015.reduceRegion({
      reducer: 'mean',
      geometry: intersection, 
      scale: 250,
      maxPixels: 10e9
    }).values().get(0);
    return ee.Feature(intersection, {OBJECTID: OBJECTID, Country: Country, 
                                      area: intersection.area(), avgPeople: avgPeople});
  });  
  return mapping2;
})
  // filter on intersections which did not return any overlapping area
  .flatten().filter(ee.Filter.gt('area', 0));

You will have to export the resulting feature collection to your assets/drive, as it will run out of memory for a worldwide calculation. In the example I show you in the link I filtered both feature collection (basins, countries) on a area of interest, so the result can be printed in the console: link script

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.