博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
洪涝淹没分析输出淹没范围图、深度图及面积体积等信息【转】
阅读量:6956 次
发布时间:2019-06-27

本文共 2797 字,大约阅读时间需要 9 分钟。

http://blog.csdn.net/giser_whu/article/details/41308771

接上一篇博客。可以输出洪涝淹没范围图、深度图以及淹没面积等信息,下一步输出历时图。代码很简单,下面直接给出源代码,欢迎大家留言交流。

[csharp]
  1. /// <summary>  
  2.       /// 输出洪涝淹没范围图  
  3.       /// </summary>  
  4.       public void OutPutFloodRegion()  
  5.       {  
  6.   
  7.           //创建洪涝淹没范围影像  
  8.           string m_FloodRegionPath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\FloodSimulation\\FloodedRegion.tif";  
  9.           if (System.IO.File.Exists(m_FloodRegionPath))  
  10.           {  
  11.               System.IO.File.Delete(m_FloodRegionPath);  
  12.           }  
  13.   
  14.           //在GDAL中创建影像,先需要明确待创建影像的格式,并获取到该影像格式的驱动  
  15.           driver = Gdal.GetDriverByName("GTiff");  
  16.           //调用Creat函数创建影像  
  17.           m_FloodSimulationRegionDataSet = driver.Create(m_FloodRegionPath, m_XSize, m_YSize, 1, DataType.GDT_Float32, null);  
  18.           //设置影像属性  
  19.           m_FloodSimulationRegionDataSet.SetGeoTransform(m_adfGeoTransform); //影像转换参数  
  20.           m_FloodSimulationRegionDataSet.SetProjection(m_DEMDataSet.GetProjectionRef()); //投影  
  21.   
  22.           //输出影像  
  23.           m_FloodSimulationRegionDataSet.GetRasterBand(1).WriteRaster(0, 0, m_XSize, m_YSize, m_FloodRegionBuffer, m_XSize, m_YSize, 0, 0);  
  24.           m_FloodSimulationRegionDataSet.GetRasterBand(1).FlushCache();  
  25.           m_FloodSimulationRegionDataSet.FlushCache();  
  26.   
  27.       }  
  28.   
  29.       /// <summary>  
  30.       /// 输出洪涝淹没深度图  
  31.       /// </summary>  
  32.       public void OutPutFloodDepth()  
  33.       {  
  34.   
  35.           for (int i = 0; i < m_XSize; i++)  
  36.           {  
  37.               for (int j = 0; j < m_YSize; j++)  
  38.               {  
  39.                   Point m_point = new Point();  
  40.                   m_point.X = i;  
  41.                   m_point.Y = j;  
  42.                   if (m_FloodRegionBuffer[getIndex(m_point)] == 1)  
  43.                   {  
  44.                       int evaluation = m_DEMdataBuffer[getIndex(m_point)]; //淹没格网高程值  
  45.                       int value = pFloodLevel - evaluation;  
  46.                       m_FloodDepthBuffer[getIndex(m_point)] = value;  
  47.                   }  
  48.               }  
  49.   
  50.           }  
  51.           //输出洪涝淹没深度图  
  52.           string m_FloodDepthPath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\FloodSimulation\\FloodedDepth.tif";  
  53.           if (System.IO.File.Exists(m_FloodDepthPath))  
  54.           {  
  55.               System.IO.File.Delete(m_FloodDepthPath);  
  56.           }  
  57.   
  58.           //在GDAL中创建影像,先需要明确待创建影像的格式,并获取到该影像格式的驱动  
  59.           driver = Gdal.GetDriverByName("GTiff");  
  60.           
  61.           //调用Creat函数创建影像  
  62.           m_FloodSimulationDepthDateSet = driver.Create(m_FloodDepthPath, m_XSize, m_YSize, 1, DataType.GDT_Float32, null);  
  63.           //设置影像属性  
  64.           m_FloodSimulationDepthDateSet.SetGeoTransform(m_adfGeoTransform); //影像转换参数  
  65.           m_FloodSimulationDepthDateSet.SetProjection(m_DEMDataSet.GetProjectionRef()); //投影  
  66.    
  67.           //输出影像  
  68.           m_FloodSimulationDepthDateSet.GetRasterBand(1).WriteRaster(0, 0, m_XSize, m_YSize, m_FloodDepthBuffer, m_XSize, m_YSize, 0, 0);  
  69.           m_FloodSimulationDepthDateSet.GetRasterBand(1).FlushCache();  
  70.           m_FloodSimulationDepthDateSet.FlushCache();  
  71.   
  72.       }  
  73.       /// <summary>  
  74.       /// 输出洪涝淹没面积及水量  
  75.       /// </summary>  
  76.       public void OutPutFloodInfo()  
  77.       {  
  78.           int count = 0;  
  79.           for (int i = 0; i < m_XSize; i++)  
  80.           {  
  81.               for (int j = 0; j < m_YSize; j++)  
  82.               {  
  83.                   Point m_point = new Point();  
  84.                   m_point.X = i;  
  85.                   m_point.Y = j;  
  86.                   if (m_FloodRegionBuffer[getIndex(m_point)] == 1)  
  87.                   {  
  88.                       count++;  
  89.                   }  
  90.               }  
  91.   
  92.           }  
  93.           //统计面积  
  94.           double S = count * 90; //平方米  
  95.           if (S > 10000)  
  96.           {  
  97.               S = S / 10000;  //公顷  
  98.           }  
  99.           MessageBox.Show("淹没面积:" + S.ToString() + "公顷");  
  100.       }  

 

结果图:范围图与深度图

 

你可能感兴趣的文章
体验下 Go 语言的魅力(初试)
查看>>
Docker 快速入门
查看>>
UIBarButtonItem 在 iOS 11 上的改变及应对方案
查看>>
再聊神经网络与深度学习
查看>>
OkHttp源码解析
查看>>
React全家桶+Egg 做一个协作聊天室~
查看>>
小程序从手动埋点到自动埋点
查看>>
vue-devtools的安装与使用
查看>>
iOS ARKit录制视频(AVAssetWriter & 有声音)
查看>>
### bootstrap-datepicker 与bootstrapValidator同时使用时,选择日期后,无法正常触发校验...
查看>>
2019最新前端面试宝典
查看>>
Puppeteer爬取网页数据
查看>>
flutter 语言篇四
查看>>
月薪80K前端大佬笔记学习vue的心得,网友:两个字“完美”!
查看>>
「中高级前端面试」JavaScript手写代码无敌秘籍
查看>>
【通用技术】Git 完全自学手册
查看>>
unable to access 'https://github.com/DajuanM/DHAlgorithms.git/': The requested U
查看>>
iOS 之VLC使用RTSP流做监控或者直播视频
查看>>
restful+springmvc+mybatis+ webservice 分布式架构
查看>>
组件传值eventHub设置全局的使用
查看>>