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

[csharp] view plain​ copy


  1. /// <summary>
  2. /// 输出洪涝淹没范围图
  3. /// </summary>
  4. public void OutPutFloodRegion()
  5. {

  6. //创建洪涝淹没范围影像
  7. string m_FloodRegionPath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\FloodSimulation\\FloodedRegion.tif";
  8. if (System.IO.File.Exists(m_FloodRegionPath))
  9. {
  10. System.IO.File.Delete(m_FloodRegionPath);
  11. }

  12. //在GDAL中创建影像,先需要明确待创建影像的格式,并获取到该影像格式的驱动
  13. driver = Gdal.GetDriverByName("GTiff");
  14. //调用Creat函数创建影像
  15. m_FloodSimulationRegionDataSet = driver.Create(m_FloodRegionPath, m_XSize, m_YSize, 1, DataType.GDT_Float32, null);
  16. //设置影像属性
  17. m_FloodSimulationRegionDataSet.SetGeoTransform(m_adfGeoTransform); //影像转换参数
  18. m_FloodSimulationRegionDataSet.SetProjection(m_DEMDataSet.GetProjectionRef()); //投影

  19. //输出影像
  20. m_FloodSimulationRegionDataSet.GetRasterBand(1).WriteRaster(0, 0, m_XSize, m_YSize, m_FloodRegionBuffer, m_XSize, m_YSize, 0, 0);
  21. m_FloodSimulationRegionDataSet.GetRasterBand(1).FlushCache();
  22. m_FloodSimulationRegionDataSet.FlushCache();

  23. }

  24. /// <summary>
  25. /// 输出洪涝淹没深度图
  26. /// </summary>
  27. public void OutPutFloodDepth()
  28. {

  29. for (int i = 0; i < m_XSize; i++)
  30. {
  31. for (int j = 0; j < m_YSize; j++)
  32. {
  33. Point m_point = new Point();
  34. m_point.X = i;
  35. m_point.Y = j;
  36. if (m_FloodRegionBuffer[getIndex(m_point)] == 1)
  37. {
  38. int evaluation = m_DEMdataBuffer[getIndex(m_point)]; //淹没格网高程值
  39. int value = pFloodLevel - evaluation;
  40. m_FloodDepthBuffer[getIndex(m_point)] = value;
  41. }
  42. }

  43. }
  44. //输出洪涝淹没深度图
  45. string m_FloodDepthPath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\FloodSimulation\\FloodedDepth.tif";
  46. if (System.IO.File.Exists(m_FloodDepthPath))
  47. {
  48. System.IO.File.Delete(m_FloodDepthPath);
  49. }

  50. //在GDAL中创建影像,先需要明确待创建影像的格式,并获取到该影像格式的驱动
  51. driver = Gdal.GetDriverByName("GTiff");

  52. //调用Creat函数创建影像
  53. m_FloodSimulationDepthDateSet = driver.Create(m_FloodDepthPath, m_XSize, m_YSize, 1, DataType.GDT_Float32, null);
  54. //设置影像属性
  55. m_FloodSimulationDepthDateSet.SetGeoTransform(m_adfGeoTransform); //影像转换参数
  56. m_FloodSimulationDepthDateSet.SetProjection(m_DEMDataSet.GetProjectionRef()); //投影

  57. //输出影像
  58. m_FloodSimulationDepthDateSet.GetRasterBand(1).WriteRaster(0, 0, m_XSize, m_YSize, m_FloodDepthBuffer, m_XSize, m_YSize, 0, 0);
  59. m_FloodSimulationDepthDateSet.GetRasterBand(1).FlushCache();
  60. m_FloodSimulationDepthDateSet.FlushCache();

  61. }
  62. /// <summary>
  63. /// 输出洪涝淹没面积及水量
  64. /// </summary>
  65. public void OutPutFloodInfo()
  66. {
  67. int count = 0;
  68. for (int i = 0; i < m_XSize; i++)
  69. {
  70. for (int j = 0; j < m_YSize; j++)
  71. {
  72. Point m_point = new Point();
  73. m_point.X = i;
  74. m_point.Y = j;
  75. if (m_FloodRegionBuffer[getIndex(m_point)] == 1)
  76. {
  77. count++;
  78. }
  79. }

  80. }
  81. //统计面积
  82. double S = count * 90; //平方米
  83. if (S > 10000)
  84. {
  85. S = S / 10000; //公顷
  86. }
  87. MessageBox.Show("淹没面积:" + S.ToString() + "公顷");
  88. }



结果图:范围图与深度图

洪涝淹没分析输出淹没范围图、深度图及面积体积等信息【转】_i++

洪涝淹没分析输出淹没范围图、深度图及面积体积等信息【转】_深度图_02