• 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

    代码:

    1. /**
    2. * @Name : 房山区洪涝灾害风险评价
    3. * @Author : 首都师范大学云开发——“图”以致用组
    4. * @Source : 航天宏图第四届 “航天宏图杯”PIE软件二次开发大赛云开发组二等奖获奖作品
    5. */
    6. var studyArea = pie.FeatureCollection('user/pieadmin/CNUelites')
    7. .first()
    8. .geometry();
    9. Map.addLayer(studyArea, { color: 'black', fillColor: '00000000' }, "roi");
    10. //定位地图中心
    11. Map.centerObject(studyArea, 11);
    12. //加载SRTM30m数据
    13. var SRTM = pie.ImageCollection('DEM/SRTM_30')
    14. .filterBounds(studyArea)
    15. .select("elevation")
    16. .mean()
    17. .clip(studyArea);
    18. //DEM数据归一化
    19. var srtm_band = SRTM.select('elevation')
    20. var srtm_minmax = SRTM.reduceRegion(pie.Reducer.minMax(), studyArea, 1000);
    21. srtm_minmax = pie.Dictionary(srtm_minmax);
    22. var elevation_min = pie.Number(srtm_minmax.get("elevation_min"));
    23. var elevation_max = pie.Number(srtm_minmax.get("elevation_max"));
    24. var dem_result = pie.Image(elevation_max).subtract(srtm_band).divide(elevation_max.subtract(elevation_min));
    25. var vis_DEM = {
    26. min:0,
    27. max:1,
    28. palette: ['#BF812D', '#DFC27D', '#F6E8C3', '#A1D99B', '#41AB5D']
    29. };
    30. Map.addLayer(dem_result, vis_DEM, "dem", false);
    31. /***********************************************************************/
    32. //Slope归一化//计算坡度
    33. var Slope = pie.Terrain.slope(SRTM).rename("slope");
    34. var slope_band = Slope.select('slope')
    35. var slope_minmax = Slope.reduceRegion(pie.Reducer.minMax(), studyArea, 1000);
    36. slope_minmax = pie.Dictionary(slope_minmax);
    37. var slope_min = pie.Number(slope_minmax.get("slope_min"));
    38. var slope_max = pie.Number(slope_minmax.get("slope_max"));
    39. var slope_result = pie.Image(slope_max).subtract(slope_band).divide(slope_max.subtract(slope_min));
    40. var vis_slope = {
    41. min:0,
    42. max:1,
    43. palette: ['#C7E9C0', '#F6E8C3', '#DFC27D', '#CD853F', '#BF812D']
    44. };
    45. Map.addLayer(slope_result, vis_slope, "slope", false);
    46. /***********************************************************************/
    47. // 降水强度
    48. var precipitation = pie.ImageCollection('TPDC/CHINA_1KM_PRE_MONTH')
    49. .filterDate("2017-06-01", "2017-08-31")
    50. .select("B1")
    51. .mean()
    52. .clip(studyArea);
    53. var pre_band = precipitation.select('B1')
    54. var pre_value = precipitation.reduceRegion(pie.Reducer.minMax(), studyArea, 1000)
    55. pre_value = pie.Dictionary(pre_value);
    56. var pre_min = pie.Number(pre_value.get("B1_min"));
    57. var pre_max = pie.Number(pre_value.get("B1_max"));
    58. //计算公式 result = x-min/max-min
    59. var pre_result = pre_band.subtract(pre_min).divide(pre_max.subtract(pre_min));
    60. var vis_pre = {
    61. min:0,
    62. max:1,
    63. palette: ["#ADD8E6", "#87CEEB", "#87CEFA", "#6495ED", "#4169E1"]
    64. };
    65. Map.addLayer(pre_result, vis_pre, "pre", false);
    66. /***********************************************************************/
    67. //危险性计算
    68. var danger = ((dem_result.multiply(0.332)).add(slope_result.multiply(0.308)))
    69. .add(pre_result.multiply(0.360))
    70. //计算植被覆盖度,加载landsat8影像数据
    71. var L8 = pie.ImageCollection("LC08/01/T1/LC08_123032_20170710")
    72. .filterBounds(studyArea)
    73. .select(["B5", "B4"])
    74. .filterDate("2017-6-1", "2017-10-1")
    75. .filter(pie.Filter.lt("cloudCover", 5))
    76. .first()
    77. .clip(studyArea);
    78. var B4 = L8.select("B4");
    79. var B5 = L8.select("B5");
    80. var NDVI = (B5.subtract(B4)).divide(B5.add(B4)).rename("NDVI");
    81. //计算FVC
    82. var info = NDVI.reduceRegion(pie.Reducer.minMax(), studyArea, 1000)
    83. info = pie.Dictionary(info);
    84. var NDVI_min = pie.Number(info.get("NDVI_min"));
    85. var NDVI_max = pie.Number(info.get("NDVI_max"));
    86. var FVC = pie.Image(NDVI_max).subtract(NDVI).divide(NDVI_max.subtract(NDVI_min));
    87. //加载FVC影像
    88. var vis_fvc = {
    89. min:0,
    90. max:1,
    91. palette: ['#006837', '#66BD63', '#FFCC33', '#D6604D', '#A50026']
    92. };
    93. Map.addLayer(FVC, vis_fvc, "FVC", false);
    94. /***********************************************************************/
    95. //地表产流能力
    96. //加载landsat影像数据
    97. var L8 = pie.ImageCollection("LC08/01/T1")
    98. .filterBounds(studyArea)
    99. .select(["B9", "B8", "B7", "B6", "B5", "B4", "B3", "B2", "B1"])
    100. .filterDate("2017-6-1", "2017-11-1")
    101. .filter(pie.Filter.lt("cloudCover", 10))
    102. .median()
    103. .clip(studyArea);
    104. //分类样本
    105. var featureCollection = pie.FeatureCollection('user/pieadmin/ROIpoint');
    106. featureCollection = featureCollection.randomColumn('random');
    107. //SVM监督分类
    108. var sampleFeatureCollection = L8.sampleRegions(featureCollection, ["type", "random"], 50);
    109. var sampleTrainingFeatures = sampleFeatureCollection.filter(pie.Filter.lte("random", 0.8));
    110. var sampleTestingFeatures = sampleFeatureCollection.filter(pie.Filter.gt("random", 0.2));
    111. var classifer = pie.Classifier.svm()
    112. .train(sampleTrainingFeatures, "type", ["B9", "B8", "B7", "B6", "B5", "B4", "B3", "B2", "B1"]);
    113. var resultImage = L8.classify(classifer, "GFclassify");
    114. var classifer_result = resultImage.divide(1000);
    115. /***********************************************************************/
    116. //河网密度
    117. var Rivernetwork_density = pie.Image('user/pieadmin/Den_river100')
    118. .select('B1')
    119. .clip(studyArea);
    120. var vis_RND = {
    121. min:0,
    122. max:1,
    123. palette: ["#ADD8E6", "#87CEEB", "#87CEFA", "#6495ED", "#4169E1"]
    124. };
    125. var RND_band = Rivernetwork_density.select('B1');
    126. var RND_minmax = Rivernetwork_density.reduceRegion(pie.Reducer.minMax(), studyArea, 30);
    127. RND_minmax = pie.Dictionary(RND_minmax);
    128. var RND_min = pie.Number(RND_minmax.get("B1_min"));
    129. var RND_max = pie.Number(RND_minmax.get("B1_max"));
    130. var RND_result = RND_band.subtract(RND_min).divide(RND_max.subtract(RND_min));
    131. Map.addLayer(RND_result, vis_RND, "rnd", false);
    132. /***********************************************************************/
    133. //土壤类型
    134. var Soiltype = pie.Image('user/pieadmin/soiltype')
    135. .select('B1')
    136. .clip(studyArea);
    137. var vis_soil = {
    138. min:0,
    139. max:1,
    140. palette: ["#1A9850", "#66BD63", "#A6D96A", "#FFFFBF", "#FDAE61"]
    141. };
    142. var soiltype_band = Soiltype.select('B1');
    143. //计算公式 result = (x/1000)-0.1
    144. var soil_result = (soiltype_band.divide(1000)).subtract(0.1)
    145. Map.addLayer(soil_result, vis_soil, "soil", false);
    146. /***********************************************************************/
    147. //脆弱性计算
    148. var Vulnerability = FVC.multiply(0.207)
    149. .add(classifer_result.multiply(0.256))
    150. .add(RND_result.multiply(0.354))
    151. .add(soil_result.multiply(0.183))
    152. //GDP的计算
    153. var GDP2015 = pie.Image('user/pieadmin/GDP2015_100')
    154. .select("B1")
    155. .clip(studyArea);
    156. var vis_GDP = {
    157. min:0,
    158. max:1,
    159. palette: ['#FCC5C0', '#FA9FB5', '#F768A1', '#DD3497', '#AE017E']
    160. };
    161. var gdp_band = GDP2015.select('B1');
    162. var GDP2017 = gdp_band.multiply((681.7 - 568.4) / 568.4 + 1)
    163. var gdp_minmax = GDP2017.reduceRegion(pie.Reducer.minMax(), studyArea, 30);
    164. gdp_minmax = pie.Dictionary(gdp_minmax);
    165. var GDP_min = pie.Number(gdp_minmax.get("B1_min"));
    166. var GDP_max = pie.Number(gdp_minmax.get("B1_max"));
    167. //计算公式 result =(x-min)/(max-min)
    168. var GDP_result = (gdp_band.subtract(GDP_min)).divide(GDP_max.subtract(GDP_min));
    169. Map.addLayer(GDP_result, vis_GDP, "gdp", false);
    170. /***********************************************************************/
    171. //到道路网的距离的计算
    172. var road = pie.Image('user/pieadmin/Dist_road100')
    173. .select('B1')
    174. .clip(studyArea);
    175. var road_band = road.select('B1');
    176. var road_minmax = road_band.reduceRegion(pie.Reducer.minMax(), studyArea, 100);
    177. road_minmax = pie.Dictionary(road_minmax);
    178. var road_min = pie.Number(road_minmax.get("B1_min"));
    179. var road_max = pie.Number(road_minmax.get("B1_max"));
    180. var road_result = pie.Image(road_max).subtract(road_band).divide(road_max.subtract(road_min));
    181. var vis_road = {
    182. min:0,
    183. max:1,
    184. palette: ['#D9D9D9', '#BDBDBD', '#969696', '#737373', '#525252']
    185. };
    186. Map.addLayer(road_result, vis_road, "road", false);
    187. /***********************************************************************/
    188. //人口密度
    189. var pop_des = pie.ImageCollection("WorldPop/Global_100m_UNadj")
    190. .filterDate("2017-1-1", "2017-12-30")
    191. .first()
    192. .select('population')
    193. .clip(studyArea);
    194. var pop_band = pop_des.select('population');
    195. var pop_minmax = pop_des.reduceRegion(pie.Reducer.minMax(), studyArea, 100);
    196. pop_minmax = pie.Dictionary(pop_minmax);
    197. var pop_min = pie.Number(pop_minmax.get("population_min"));
    198. var pop_max = pie.Number(pop_minmax.get("population_max"));
    199. //计算公式 result = (x-min)/(max-min)
    200. var pop_result = (pop_band.subtract(pop_min)).divide(pop_max.subtract(pop_min));
    201. /***********************************************************************/
    202. //暴露性计算
    203. var Exposure = ((pop_result.multiply(0.411)).add(GDP_result.multiply(0.327)))
    204. .add(road_result.multiply(0.262))
    205. /***********************************************************************/
    206. //洪涝灾害风险计算
    207. var FloodDisasterrisk_cal = ((danger.multiply(0.416)).add(Vulnerability.multiply(0.362)))
    208. .add(Exposure.multiply(0.222))
    209. /**button模块 */
    210. function generatePIEChart(image, chartOption) {
    211. var conditions = [
    212. {min:null, max:0.2},
    213. {min:0.2, max:0.4},
    214. {min:0.4, max:0.6},
    215. {min:0.6, max:0.8},
    216. {min:0.8, max:null},
    217. ];
    218. for (let i=0; ilength; i++) {
    219. var newImg;
    220. if (conditions[i].min == null) {
    221. newImg = image.lte(conditions[i].max);
    222. } else if (conditions[i].max == null) {
    223. newImg = image.gt(conditions[i].min);
    224. } else {
    225. newImg = image.gt(conditions[i].min).and(image.lte(conditions[i].max));
    226. }
    227. var areaImage = pie.Image().pixelArea().multiply(newImg);
    228. var data = areaImage.reduceRegion(pie.Reducer.sum(), studyArea, 1000);
    229. image = image.set("class_"+i, data.get("constant"));
    230. }
    231. image.getInfo(function(data) {
    232. let properties = data.properties;
    233. let xValues = [];
    234. let yValues = [];
    235. let labels = chartOption.legend
    236. for (let i=0; ilength; i++) {
    237. xValues.push(labels[i]);
    238. yValues.push(parseFloat((properties["class_"+i]/1000000).toFixed(2)));
    239. }
    240. let chart = ui.Chart.PIEArray.values({
    241. array: yValues,
    242. axis: 0,
    243. xLabels: xValues
    244. });
    245. chart = chart.setChartType("pie")
    246. .setSeriesNames(xValues)
    247. .setOptions({
    248. title: {
    249. name: chartOption.title
    250. },
    251. xAxis: {
    252. name: chartOption.seriesName
    253. }
    254. });
    255. print(chart);
    256. });
    257. }
    258. var productLayer = null;
    259. var productLegend = null;
    260. function addProductLegend(title, labels, colors) {
    261. if (productLegend != null) {
    262. Map.removeUI(productLegend);
    263. }
    264. // 图例
    265. var data = {
    266. title: title,
    267. colors: colors,
    268. labels: labels,
    269. step: 30
    270. };
    271. var style = {
    272. right: "150px",
    273. bottom: "10px",
    274. height: "70px",
    275. width: "350px"
    276. };
    277. productLegend = ui.Legend(data, style);
    278. Map.addUI(productLegend);
    279. }
    280. function addProductLayer(layer, vis, layerName) {
    281. if (productLayer != null) {
    282. Map.removeLayer(productLayer);
    283. }
    284. productLayer = Map.addLayer(layer, vis, layerName);
    285. }
    286. /**暴露性 */
    287. var ExposureShow = ui.Button({
    288. label: '暴露性等级分布图',
    289. onClick: showExposureShow
    290. })
    291. function showExposureShow() {
    292. var vis_exposure = {
    293. min:0,
    294. max:1,
    295. palette: ["1A9850", "A6D96A", "FFFFBF", 'EF6548', 'D7301F']
    296. };
    297. addProductLayer(Exposure, vis_exposure, "Exposure");
    298. addProductLegend('暴露性等级',
    299. ['very low', 'low', 'medium', 'high', 'very high'],
    300. ["#1A9850", "#A6D96A", "#FFFFBF", '#EF6548', '#D7301F']);
    301. print("暴露性结果统计与展示");
    302. //暴露性结果统计与展示
    303. var pie_options_Exposure = {
    304. title: '暴露性结果统计图',
    305. legend: ["very low", "low", "medium", "high", "very high"],
    306. seriesName: "暴露性等级",
    307. }
    308. generatePIEChart(Exposure, pie_options_Exposure);
    309. }
    310. print(ExposureShow);
    311. /**脆弱性 */
    312. var VulnerabilityShow = ui.Button({
    313. label: '脆弱性等级分布图',
    314. onClick: showVulnerability
    315. })
    316. function showVulnerability() {
    317. var vis_Vulnerability = {
    318. min:0,
    319. max:1,
    320. palette: ["#1A9850", "#66BD63", "#A6D96A", "#F46D43", "#D73027"]
    321. };
    322. addProductLayer(Vulnerability, vis_Vulnerability, 'Vulnerability');
    323. addProductLegend('脆弱性等级',
    324. ['very low', 'low', 'medium', 'high', 'very high'],
    325. ["#1A9850", "#66BD63", "#A6D96A", "#F46D43", "#D73027"]);
    326. print("脆弱性结果统计与展示");
    327. //脆弱性结果统计与展示
    328. var pie_options_Vulnerability = {
    329. title: '脆弱性结果统计图',
    330. legend: ["very low", "low", "medium", "high", "very high"],
    331. seriesName: "脆弱性等级",
    332. }
    333. generatePIEChart(Vulnerability, pie_options_Vulnerability);
    334. }
    335. print(VulnerabilityShow);
    336. /**危险性 */
    337. var dangerShow = ui.Button({
    338. label: '危险性等级分布图',
    339. onClick: showdanger
    340. })
    341. function showdanger() {
    342. var vis_danger = {
    343. min:0,
    344. max:1,
    345. palette: ["#35978F", "#80CDC1", "#C7EAE5", "#FF7F50", "#D73027"]
    346. };
    347. addProductLayer(danger, vis_danger, 'Hazard');
    348. addProductLegend('危险性等级',
    349. ['very low', 'low', 'medium', 'high', 'very high'],
    350. ["#35978F", "#80CDC1", "#C7EAE5", "#FF7F50", "#D73027"]);
    351. print("危险性结果统计与展示");
    352. //危险性结果统计与展示
    353. var pie_options_danger = {
    354. title: '危险性结果统计图',
    355. legend: ["very low", "low", "medium", "high", "very high"],
    356. seriesName: "危险性等级",
    357. }
    358. generatePIEChart(danger, pie_options_danger);
    359. }
    360. print(dangerShow);
    361. /**总指标 */
    362. var FDRCShow = ui.Button({
    363. label: '洪涝灾害风险分布图',
    364. onClick: showfdrc
    365. })
    366. function showfdrc() {
    367. var FDRC = {
    368. min:0,
    369. max:1,
    370. palette: ['#2166AC', '#4393C3', '#92C5DE', '#D6604D', '#AE182B']
    371. };
    372. addProductLayer(FloodDisasterrisk_cal, FDRC, 'FloodDisasterrisk_cal');
    373. addProductLegend('风险性等级',
    374. ['very low', 'low', 'medium', 'high', 'very high'],
    375. ['#2166AC', '#4393C3', '#92C5DE', '#D6604D', '#AE182B']);
    376. print("洪涝灾害风险结果统计与展示");
    377. //洪涝灾害风险结果统计与展示
    378. var pie_options_FloodDisasterrisk = {
    379. title: '风险性结果统计图',
    380. legend: ["very low", "low", "medium", "high", "very high"],
    381. seriesName: "风险等级",
    382. }
    383. generatePIEChart(FloodDisasterrisk_cal, pie_options_FloodDisasterrisk);
    384. }
    385. print(FDRCShow);

    洪涝灾害风险分布图

     危险性等级分布图

     脆弱性等级分布图

     暴露性等级分布图

     相应的饼图结果:

     

  • 相关阅读:
    振动监测:物联网预测性维护的“听诊器”
    工程压缩与解压缩
    Git Commit Message规范
    Spring 常用注解及作用
    基于spring boot 的学生科研项目共享平台毕业设计源码271611
    【Linux 网络】高级 IO -- 详解
    【GIT版本控制】--高级分支策略
    开源与在线 M3U8 Downloader 项目介绍及使用指南
    Google Chrome 任意文件读取 (CVE-2023-4357)漏洞
    【学习笔记之我要C】预处理
  • 原文地址:https://blog.csdn.net/qq_31988139/article/details/127112794