最近看到好多小伙伴在找Worldpop人口数据。小编之前去看的时候,全国的影像一张就4G左右,太大了。不过小编已经为大家搜集好了全国的数据,关注微信公众号:GEEer成长日记。即可获取。
今天我们主要讲讲如何利用GEE下载数据。
首先看看Worldpop数据的介绍吧:
Global high-resolution, contemporary data on human population distributions are a prerequisite for the accurate measurement of the impacts of population growth, for monitoring changes, and for planning interventions. The WorldPop project aims to meet these needs through the provision of detailed and open access population distribution datasets built using transparent and peer-reviewed approaches.
Full details on the methods and datasets used in constructing the data, along with open access publications, are provided on the WorldPop website. In brief, recent census-based population counts matched to their associated administrative units are disaggregated to ~100x100m grid cells through machine learning approaches that exploit the relationships between population densities and a range of geospatial covariate layers. The mapping approach is Random Forest-based dasymetric redistribution.
This dataset depict estimated number of people residing in each grid cell in 2010, 2015, and other years.
For 2020, the breakdown of population by age and sex is available in the WorldPop/GP/100m/pop_age_sex and WorldPop/GP/100m/pop_age_sex_cons_unadj collections.
我们数据集筛选结果可以看到,目前有三个数据集,后两个数据集包含了估计年龄和性别结构。不过只有2020年的数据,方便下载数据的演示,我们还是以最基础的人口数据为例进行研究。
//还是老样子哈,以广东省为目标
var geometry = ee.FeatureCollection('users/ZhengkunWang/guangdongsheng')
Map.centerObject(geometry,6)
//此功能是为了将每年的影像按照区域进行裁剪
var clipToCol = function(image){
return image.clip(geometry);
};
// import worldpop data
// 并且按照我国的缩写进行过滤,大家可以试试不加国家限制的话,影像集是什么情况
var worldpop = ee.ImageCollection("WorldPop/GP/100m/pop").filterBounds(geometry).map(clipToCol)
.filter(ee.Filter.eq('country', 'CHN')).select('population')
print(worldpop)
// set the start and end dates
var start = ee.Date.fromYMD(2020,1,1);
var end = ee.Date.fromYMD(2020,12,31);
//以2020年的平均值为例进行展示
// filter for the period of interest
var worldpop2020 = ee.Image(worldpop.filterDate(start,end).mean());
// clip for the area of interest
worldpop2020 = worldpop2020.clip(geometry);
Map.addLayer(worldpop2020,{min:0,max:100,palette: ['24126c', '1fff4f', 'd4ff50']},"population 2020");
结果如图:
我们再看看二十年的人口数量变化如何:
var chart =
ui.Chart.image.seriesByRegion
({
imageCollection:worldpop,
regions: geometry,
reducer: ee.Reducer.sum(),
scale: 100,
xProperty: 'system:time_start'
})
.setSeriesNames(['population'])
.setOptions({
title: 'population dynamics',
hAxis: {title: 'Date', titleTextStyle: {italic: false, bold: true}},
vAxis: {
title: 'total population',
titleTextStyle: {italic: false, bold: true}
},
lineWidth: 5,
colors: ['e37d05'],
curveType: 'function'
});
print(chart);
不看不知道,一看吓一跳啊。人口直奔1.1Y了!!!
接下来,就是数据下载的环节
大家学会这个方法之后,其他数据集也与此雷同,万能公式直接套用。
//导出影像数据函数,三个参数
function exportImage(image, region, fileName) {
Export.image.toDrive({
image: image, //设置要输出的影像
description: fileName, // 设置下载任务tasks的名称
fileNamePrefix: fileName, //设置下载影像的名称
folder: "population", //设置下载影像在Drive中存储的文件夹名称(可不设置)
scale: 100, //空间分辨率,单位:米
region: geometry, //要下载影像的范围
maxPixels: 1e13, //单幅影像输出的最大像元数
fileFormat:"GeoTIFF", //设置影像导出格式,注意GeoTIFF格式需要所有波段存储类型一致(如不能同时存Int16和Int32)
crs: "EPSG:4326" //投影信息,一般是采用默认方式,通常可以设置为EPSG:4326
});
}
//获取每幅影像对应的时间
var indexList = worldpop.reduceColumns(ee.Reducer.toList(), ["system:index"]).get("list");
print("indexList", indexList);
//循环导出影像,用影像时间对其命名
indexList.evaluate(function(indexs) {
for (var i=0; i<indexs.length; i++) {
var image = worldpop.filter(ee.Filter.eq("system:index", indexs[i])) //筛选对应时间的影像
.first() //选取第一幅影像
.int16() //将所有波段存储格式都转换Int16,使其保持一致(哨兵2号数据QA20波段为Int32,与其他不一致会出错)
exportImage(image, geometry, "Worldpop-"+indexs[i]);
}
});
这时候Task已经发亮了,快去看看吧!
鉴于一个一个点比较笨,数据少的时候还可以,数据量大的时候可真麻烦。所以小编也为大家准备了批量RUN的代码,但是在使用的时候会有卡顿,因电脑而异,耐心等待就好。而且,小心自己的磁盘空间不足,先下载两幅看看大小吧。
批量运行的代码需要在CODE页面按F12,在控制台输入即可。输入之后效果是这样的:
回车之后就这样了,单击RUN之后会卡,大家耐心等等:
小编运行试了试,一张图四五分钟的样子,大小也就5M,是真的方便。快去下载吧~
代码已经更新,获取Worldpop人口数据可视化及数据下载的代码请在公众号回复:123101。
获取批量运行下载任务的代码请在公众号回复123102。
如果真的可以帮到你,记得给小编点个赞哦~
参考博客:https://mygeoblog.com/2021/09/16/population-dynamics/
更多精彩内容请关注: