Estimate future / historic population density

apply linear regression on the worldPop data.

code below and here.


var worldPop = ee.ImageCollection("WorldPop/POP")

// function to add time as a band
var addTime = function(image) {
  // Scale milliseconds by a large constant to avoid very small slopes
  // in the linear regression output.
  return image.addBands(image.metadata('system:time_start').divide(1e18));
};

// select country and add time bands
var wp =  worldPop
  .filter(ee.Filter.inList('country', ['VNM']))
  .filter(ee.Filter.equals('UNadj', 'yes')).map(addTime)
  .select(['system:time_start', 'population']);

var display = {
  title: "worldpop data",
  fontSize: 12,
  hAxis: {title: 'Year'},
  vAxis: {title: "population density"}};

// plot a chart
print(ui.Chart.image.series({imageCollection:wp,
                             region:geometry,
                             reducer:ee.Reducer.mean(),
                             scale:100}).setOptions(display));<span id="mce_SELREST_start" style="overflow:hidden;line-height:0;">&#65279;</span>

// apply the linear fit on the data
var wp =  worldPop
  .filter(ee.Filter.inList('country', ['VNM']))
  .filter(ee.Filter.equals('UNadj', 'yes')).map(addTime)
  .select(['system:time_start', 'population'])
  .reduce(ee.Reducer.linearFit());  

// create a list with years
var years = ee.List.sequence(1980,2100,1);

// map of the years and calculate a + bx
var collection = ee.ImageCollection(years.map(function(y){
  var t = ee.Date.fromYMD(y,1,1).millis();
  var img = wp.select("offset").add(wp.select("scale").multiply(t.divide(1e18)));
  return img.set("system:time_start",t);
  }));

// plot a chart
print(ui.Chart.image.series({imageCollection:collection,
                             region:geometry,
                             reducer:ee.Reducer.mean(),
                             scale:100}).setOptions(display));

// set viz paramater
var viz = {min:0.0, max:50, palette:"F3FEEE,00ff04,075e09,0000FF,FDFF92,FF2700,FF00E7"};

// estimate 1980 and 2100 population
var img1980 = collection.filterDate(ee.Date.fromYMD(1980,1,1),ee.Date.fromYMD(1980,12,31));
var img2100 = collection.filterDate(ee.Date.fromYMD(2100,1,1),ee.Date.fromYMD(2100,12,31)); 

// add the maps
Map.addLayer(ee.Image(img1980.first()),viz,"1980");
Map.addLayer(ee.Image(img2100.first()),viz,"2100");

One comment

  1. To start with, thank you for creating this blog, very useful for professionals who is into GIS and remote sensing.

    Is it possible if you could share the code in exporting the population density geotiffs (also for the flood maps), as I am having trouble in exporting them.

    Thank you very much, and please continue in doing more tutorials.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s