I am working in the Google Earth Engine Javascript API and have defined grid cells covering my region of interest. It is:
var lat_start = 32.31644;
var lat_end = 37.31914;
var lon_start = 35.61394;
var lon_end = 42.38504;
// 2) Decide no. of (in this case: equally sized) cells
var num_cells = 10;
var lon_edge = (lon_end-lon_start)/Math.sqrt(num_cells);
var lat_edge = (lat_end-lat_start)/Math.sqrt(num_cells);
// 3) Create the grid
var polys = [];
var polys_line = [];
var cell_id = 0;
for (var lon = lon_start; lon < lon_end; lon += lon_edge) {
var x1 = lon;
var x2 = lon + lon_edge;
for (var lat = lat_start; lat < lat_end; lat += lat_edge) {
cell_id = cell_id + 1;
var y1 = lat;
var y2 = lat + lat_edge;
polys.push(ee.Feature(ee.Geometry.Rectangle(x1, y1, x2, y2), {label: cell_id}));
}
}
var grid = ee.FeatureCollection(polys);
I am using Worldpop population estimates data, an Image Collection with years as layers (2000-2016).
var pop = ee.ImageCollection("WorldPop/GP/100m/pop").filterBounds(grid);
My goal is to obtain a feature collection at the grid cell level that identifies the total population in each grid for a given year. I don't think I can use the "reduce" function over the image collection, since that would sum population across years for the cells defined by the image collection (my grid cells are larger).
My approach so far has been to isolate image layers with the hope of piecing them back together in a dataframe. Which so far, for each year, looks like this:
pop_01 = pop.filterDate('2001');
var pop_01_img = pop_01.reduce(ee.Reducer.sum());
var pop_grid_01 = pop_01_img.reduceRegions({collection: grid,reducer:
ee.Reducer.sum(), scale: 6000,});
This results in a series of feature collections and I can use inner joins to merge two feature collections. But how do I merge more? I was working off of the following basic inner join function:
var toyFilter = ee.Filter.equals({
leftField: 'system:index',
rightField: 'system:index'
});
var innerJoin = ee.Join.inner('primary', 'secondary');
var toyJoin = innerJoin.apply(pop_grid_00, pop_grid_01, toyFilter);
If you were trying to complete the task I described above, how would you approach it? Do you think it's most efficient to create the separate images and corresponding feature collections and put them back together, and if yes, how do we conduct inner joins for what would be 10 separate feature collections? Or is there a way for me to calculate the sum within my defined grid cells for each year layer in the image collection? If yes, how?
Thank you!!