#冲刺创作新星#PIE-Engine:房山区洪涝灾害风险评价 原创
房山区洪涝灾害风险评价这个可以说不是一个APP,要改进的话可以通过UI控件设定来在MAP上完成,剩余的其它部分都可以实现在,这里灾害风险评价时暴露性结果统计与展示、脆弱性结果统计与展示、危险性结果统计与展示以及洪涝灾害风险结果统计与展示。代码的整个流程主要是受埃希纳加载研究区和数据,然后对DEM、slope、降水强度等进行归一化处理,在这里的每一个归一化处理中,都会通过获取min和max然后通过归一化公式来获取。
处理完DEM然后处理影像数据,这里用的是Landsat 8数据,并计算FVC,地表产流能力 ,但后进行监督分类,并进行河网密度,加载土壤类型数据集,紧接着脆弱性计算,GDP的计算,到道路网的距离的计算,人口密度在计算晚以上的内容后就可以直接进行4个评价分析。
函数:
minMax()得到的结果时"B1_min","B1_max"的波段名称,这里就可以利用这个参数进行归一化处理
得到一个返回最大、最小值的统计器。
方法参数:
返回值:Reducer
reduceRegion(reducer,geometry,scale)
对特定区域的所有像素进行统计,返回结果为一个JSON对象;目前可完成最大、最小和求和统计计算。
方法参数:
- image(Image)
Image实例。
- reducer(Reducer)
统计类型,包括最大值、最小值和求和。
- geometry(Geometry)
统计区域范围。默认是影像第一个波段的范围。
- scale(Number)
统计采样比例。
返回值:Dictionary
代码:
/**
* @Name : 房山区洪涝灾害风险评价
* @Author : 首都师范大学云开发——“图”以致用组
* @Source : 航天宏图第四届 “航天宏图杯”PIE软件二次开发大赛云开发组二等奖获奖作品
*/
var studyArea = pie.FeatureCollection('user/pieadmin/CNUelites')
.first()
.geometry();
Map.addLayer(studyArea, { color: 'black', fillColor: '00000000' }, "roi");
//定位地图中心
Map.centerObject(studyArea, 11);
//加载SRTM30m数据
var SRTM = pie.ImageCollection('DEM/SRTM_30')
.filterBounds(studyArea)
.select("elevation")
.mean()
.clip(studyArea);
//DEM数据归一化
var srtm_band = SRTM.select('elevation')
var srtm_minmax = SRTM.reduceRegion(pie.Reducer.minMax(), studyArea, 1000);
srtm_minmax = pie.Dictionary(srtm_minmax);
var elevation_min = pie.Number(srtm_minmax.get("elevation_min"));
var elevation_max = pie.Number(srtm_minmax.get("elevation_max"));
var dem_result = pie.Image(elevation_max).subtract(srtm_band).divide(elevation_max.subtract(elevation_min));
var vis_DEM = {
min:0,
max:1,
palette: ['#BF812D', '#DFC27D', '#F6E8C3', '#A1D99B', '#41AB5D']
};
Map.addLayer(dem_result, vis_DEM, "dem", false);
/***********************************************************************/
//Slope归一化//计算坡度
var Slope = pie.Terrain.slope(SRTM).rename("slope");
var slope_band = Slope.select('slope')
var slope_minmax = Slope.reduceRegion(pie.Reducer.minMax(), studyArea, 1000);
slope_minmax = pie.Dictionary(slope_minmax);
var slope_min = pie.Number(slope_minmax.get("slope_min"));
var slope_max = pie.Number(slope_minmax.get("slope_max"));
var slope_result = pie.Image(slope_max).subtract(slope_band).divide(slope_max.subtract(slope_min));
var vis_slope = {
min:0,
max:1,
palette: ['#C7E9C0', '#F6E8C3', '#DFC27D', '#CD853F', '#BF812D']
};
Map.addLayer(slope_result, vis_slope, "slope", false);
/***********************************************************************/
// 降水强度
var precipitation = pie.ImageCollection('TPDC/CHINA_1KM_PRE_MONTH')
.filterDate("2017-06-01", "2017-08-31")
.select("B1")
.mean()
.clip(studyArea);
var pre_band = precipitation.select('B1')
var pre_value = precipitation.reduceRegion(pie.Reducer.minMax(), studyArea, 1000)
pre_value = pie.Dictionary(pre_value);
var pre_min = pie.Number(pre_value.get("B1_min"));
var pre_max = pie.Number(pre_value.get("B1_max"));
//计算公式 result = x-min/max-min
var pre_result = pre_band.subtract(pre_min).divide(pre_max.subtract(pre_min));
var vis_pre = {
min:0,
max:1,
palette: ["#ADD8E6", "#87CEEB", "#87CEFA", "#6495ED", "#4169E1"]
};
Map.addLayer(pre_result, vis_pre, "pre", false);
/***********************************************************************/
//危险性计算
var danger = ((dem_result.multiply(0.332)).add(slope_result.multiply(0.308)))
.add(pre_result.multiply(0.360))
//计算植被覆盖度,加载landsat8影像数据
var L8 = pie.ImageCollection("LC08/01/T1/LC08_123032_20170710")
.filterBounds(studyArea)
.select(["B5", "B4"])
.filterDate("2017-6-1", "2017-10-1")
.filter(pie.Filter.lt("cloudCover", 5))
.first()
.clip(studyArea);
var B4 = L8.select("B4");
var B5 = L8.select("B5");
var NDVI = (B5.subtract(B4)).divide(B5.add(B4)).rename("NDVI");
//计算FVC
var info = NDVI.reduceRegion(pie.Reducer.minMax(), studyArea, 1000)
info = pie.Dictionary(info);
var NDVI_min = pie.Number(info.get("NDVI_min"));
var NDVI_max = pie.Number(info.get("NDVI_max"));
var FVC = pie.Image(NDVI_max).subtract(NDVI).divide(NDVI_max.subtract(NDVI_min));
//加载FVC影像
var vis_fvc = {
min:0,
max:1,
palette: ['#006837', '#66BD63', '#FFCC33', '#D6604D', '#A50026']
};
Map.addLayer(FVC, vis_fvc, "FVC", false);
/***********************************************************************/
//地表产流能力
//加载landsat影像数据
var L8 = pie.ImageCollection("LC08/01/T1")
.filterBounds(studyArea)
.select(["B9", "B8", "B7", "B6", "B5", "B4", "B3", "B2", "B1"])
.filterDate("2017-6-1", "2017-11-1")
.filter(pie.Filter.lt("cloudCover", 10))
.median()
.clip(studyArea);
//分类样本
var featureCollection = pie.FeatureCollection('user/pieadmin/ROIpoint');
featureCollection = featureCollection.randomColumn('random');
//SVM监督分类
var sampleFeatureCollection = L8.sampleRegions(featureCollection, ["type", "random"], 50);
var sampleTrainingFeatures = sampleFeatureCollection.filter(pie.Filter.lte("random", 0.8));
var sampleTestingFeatures = sampleFeatureCollection.filter(pie.Filter.gt("random", 0.2));
var classifer = pie.Classifier.svm()
.train(sampleTrainingFeatures, "type", ["B9", "B8", "B7", "B6", "B5", "B4", "B3", "B2", "B1"]);
var resultImage = L8.classify(classifer, "GFclassify");
var classifer_result = resultImage.divide(1000);
/***********************************************************************/
//河网密度
var Rivernetwork_density = pie.Image('user/pieadmin/Den_river100')
.select('B1')
.clip(studyArea);
var vis_RND = {
min:0,
max:1,
palette: ["#ADD8E6", "#87CEEB", "#87CEFA", "#6495ED", "#4169E1"]
};
var RND_band = Rivernetwork_density.select('B1');
var RND_minmax = Rivernetwork_density.reduceRegion(pie.Reducer.minMax(), studyArea, 30);
RND_minmax = pie.Dictionary(RND_minmax);
var RND_min = pie.Number(RND_minmax.get("B1_min"));
var RND_max = pie.Number(RND_minmax.get("B1_max"));
var RND_result = RND_band.subtract(RND_min).divide(RND_max.subtract(RND_min));
Map.addLayer(RND_result, vis_RND, "rnd", false);
/***********************************************************************/
//土壤类型
var Soiltype = pie.Image('user/pieadmin/soiltype')
.select('B1')
.clip(studyArea);
var vis_soil = {
min:0,
max:1,
palette: ["#1A9850", "#66BD63", "#A6D96A", "#FFFFBF", "#FDAE61"]
};
var soiltype_band = Soiltype.select('B1');
//计算公式 result = (x/1000)-0.1
var soil_result = (soiltype_band.divide(1000)).subtract(0.1)
Map.addLayer(soil_result, vis_soil, "soil", false);
/***********************************************************************/
//脆弱性计算
var Vulnerability = FVC.multiply(0.207)
.add(classifer_result.multiply(0.256))
.add(RND_result.multiply(0.354))
.add(soil_result.multiply(0.183))
//GDP的计算
var GDP2015 = pie.Image('user/pieadmin/GDP2015_100')
.select("B1")
.clip(studyArea);
var vis_GDP = {
min:0,
max:1,
palette: ['#FCC5C0', '#FA9FB5', '#F768A1', '#DD3497', '#AE017E']
};
var gdp_band = GDP2015.select('B1');
var GDP2017 = gdp_band.multiply((681.7 - 568.4) / 568.4 + 1)
var gdp_minmax = GDP2017.reduceRegion(pie.Reducer.minMax(), studyArea, 30);
gdp_minmax = pie.Dictionary(gdp_minmax);
var GDP_min = pie.Number(gdp_minmax.get("B1_min"));
var GDP_max = pie.Number(gdp_minmax.get("B1_max"));
//计算公式 result =(x-min)/(max-min)
var GDP_result = (gdp_band.subtract(GDP_min)).divide(GDP_max.subtract(GDP_min));
Map.addLayer(GDP_result, vis_GDP, "gdp", false);
/***********************************************************************/
//到道路网的距离的计算
var road = pie.Image('user/pieadmin/Dist_road100')
.select('B1')
.clip(studyArea);
var road_band = road.select('B1');
var road_minmax = road_band.reduceRegion(pie.Reducer.minMax(), studyArea, 100);
road_minmax = pie.Dictionary(road_minmax);
var road_min = pie.Number(road_minmax.get("B1_min"));
var road_max = pie.Number(road_minmax.get("B1_max"));
var road_result = pie.Image(road_max).subtract(road_band).divide(road_max.subtract(road_min));
var vis_road = {
min:0,
max:1,
palette: ['#D9D9D9', '#BDBDBD', '#969696', '#737373', '#525252']
};
Map.addLayer(road_result, vis_road, "road", false);
/***********************************************************************/
//人口密度
var pop_des = pie.ImageCollection("WorldPop/Global_100m_UNadj")
.filterDate("2017-1-1", "2017-12-30")
.first()
.select('population')
.clip(studyArea);
var pop_band = pop_des.select('population');
var pop_minmax = pop_des.reduceRegion(pie.Reducer.minMax(), studyArea, 100);
pop_minmax = pie.Dictionary(pop_minmax);
var pop_min = pie.Number(pop_minmax.get("population_min"));
var pop_max = pie.Number(pop_minmax.get("population_max"));
//计算公式 result = (x-min)/(max-min)
var pop_result = (pop_band.subtract(pop_min)).divide(pop_max.subtract(pop_min));
/***********************************************************************/
//暴露性计算
var Exposure = ((pop_result.multiply(0.411)).add(GDP_result.multiply(0.327)))
.add(road_result.multiply(0.262))
/***********************************************************************/
//洪涝灾害风险计算
var FloodDisasterrisk_cal = ((danger.multiply(0.416)).add(Vulnerability.multiply(0.362)))
.add(Exposure.multiply(0.222))
/**button模块 */
function generatePIEChart(image, chartOption) {
var conditions = [
{min:null, max:0.2},
{min:0.2, max:0.4},
{min:0.4, max:0.6},
{min:0.6, max:0.8},
{min:0.8, max:null},
];
for (let i=0; i<conditions.length; i++) {
var newImg;
if (conditions[i].min == null) {
newImg = image.lte(conditions[i].max);
} else if (conditions[i].max == null) {
newImg = image.gt(conditions[i].min);
} else {
newImg = image.gt(conditions[i].min).and(image.lte(conditions[i].max));
}
var areaImage = pie.Image().pixelArea().multiply(newImg);
var data = areaImage.reduceRegion(pie.Reducer.sum(), studyArea, 1000);
image = image.set("class_"+i, data.get("constant"));
}
image.getInfo(function(data) {
let properties = data.properties;
let xValues = [];
let yValues = [];
let labels = chartOption.legend
for (let i=0; i<conditions.length; i++) {
xValues.push(labels[i]);
yValues.push(parseFloat((properties["class_"+i]/1000000).toFixed(2)));
}
let chart = ui.Chart.PIEArray.values({
array: yValues,
axis: 0,
xLabels: xValues
});
chart = chart.setChartType("pie")
.setSeriesNames(xValues)
.setOptions({
title: {
name: chartOption.title
},
xAxis: {
name: chartOption.seriesName
}
});
print(chart);
});
}
var productLayer = null;
var productLegend = null;
function addProductLegend(title, labels, colors) {
if (productLegend != null) {
Map.removeUI(productLegend);
}
// 图例
var data = {
title: title,
colors: colors,
labels: labels,
step: 30
};
var style = {
right: "150px",
bottom: "10px",
height: "70px",
width: "350px"
};
productLegend = ui.Legend(data, style);
Map.addUI(productLegend);
}
function addProductLayer(layer, vis, layerName) {
if (productLayer != null) {
Map.removeLayer(productLayer);
}
productLayer = Map.addLayer(layer, vis, layerName);
}
/**暴露性 */
var ExposureShow = ui.Button({
label: '暴露性等级分布图',
onClick: showExposureShow
})
function showExposureShow() {
var vis_exposure = {
min:0,
max:1,
palette: ["1A9850", "A6D96A", "FFFFBF", 'EF6548', 'D7301F']
};
addProductLayer(Exposure, vis_exposure, "Exposure");
addProductLegend('暴露性等级',
['very low', 'low', 'medium', 'high', 'very high'],
["#1A9850", "#A6D96A", "#FFFFBF", '#EF6548', '#D7301F']);
print("暴露性结果统计与展示");
//暴露性结果统计与展示
var pie_options_Exposure = {
title: '暴露性结果统计图',
legend: ["very low", "low", "medium", "high", "very high"],
seriesName: "暴露性等级",
}
generatePIEChart(Exposure, pie_options_Exposure);
}
print(ExposureShow);
/**脆弱性 */
var VulnerabilityShow = ui.Button({
label: '脆弱性等级分布图',
onClick: showVulnerability
})
function showVulnerability() {
var vis_Vulnerability = {
min:0,
max:1,
palette: ["#1A9850", "#66BD63", "#A6D96A", "#F46D43", "#D73027"]
};
addProductLayer(Vulnerability, vis_Vulnerability, 'Vulnerability');
addProductLegend('脆弱性等级',
['very low', 'low', 'medium', 'high', 'very high'],
["#1A9850", "#66BD63", "#A6D96A", "#F46D43", "#D73027"]);
print("脆弱性结果统计与展示");
//脆弱性结果统计与展示
var pie_options_Vulnerability = {
title: '脆弱性结果统计图',
legend: ["very low", "low", "medium", "high", "very high"],
seriesName: "脆弱性等级",
}
generatePIEChart(Vulnerability, pie_options_Vulnerability);
}
print(VulnerabilityShow);
/**危险性 */
var dangerShow = ui.Button({
label: '危险性等级分布图',
onClick: showdanger
})
function showdanger() {
var vis_danger = {
min:0,
max:1,
palette: ["#35978F", "#80CDC1", "#C7EAE5", "#FF7F50", "#D73027"]
};
addProductLayer(danger, vis_danger, 'Hazard');
addProductLegend('危险性等级',
['very low', 'low', 'medium', 'high', 'very high'],
["#35978F", "#80CDC1", "#C7EAE5", "#FF7F50", "#D73027"]);
print("危险性结果统计与展示");
//危险性结果统计与展示
var pie_options_danger = {
title: '危险性结果统计图',
legend: ["very low", "low", "medium", "high", "very high"],
seriesName: "危险性等级",
}
generatePIEChart(danger, pie_options_danger);
}
print(dangerShow);
/**总指标 */
var FDRCShow = ui.Button({
label: '洪涝灾害风险分布图',
onClick: showfdrc
})
function showfdrc() {
var FDRC = {
min:0,
max:1,
palette: ['#2166AC', '#4393C3', '#92C5DE', '#D6604D', '#AE182B']
};
addProductLayer(FloodDisasterrisk_cal, FDRC, 'FloodDisasterrisk_cal');
addProductLegend('风险性等级',
['very low', 'low', 'medium', 'high', 'very high'],
['#2166AC', '#4393C3', '#92C5DE', '#D6604D', '#AE182B']);
print("洪涝灾害风险结果统计与展示");
//洪涝灾害风险结果统计与展示
var pie_options_FloodDisasterrisk = {
title: '风险性结果统计图',
legend: ["very low", "low", "medium", "high", "very high"],
seriesName: "风险等级",
}
generatePIEChart(FloodDisasterrisk_cal, pie_options_FloodDisasterrisk);
}
print(FDRCShow);
洪涝灾害风险分布图
危险性等级分布图
相应的饼图结果: