zoukankan      html  css  js  c++  java
  • 洪涝淹没分析输出淹没范围图、深度图及面积体积等信息【转】

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

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

    [csharp] view plain copy
    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.       }  

    结果图:范围图与深度图

  • 相关阅读:
    再叙存储设备
    分布式文件系统---测试
    分布式文件系统
    Solr 分布式(复制)配置--成功验证
    搜索服务之离线处理思路
    我为公司做的总体架构,欢迎提建议
    python的面向对象
    python异常处理
    迭代器和生成器
    python函数
  • 原文地址:https://www.cnblogs.com/mazhenyu/p/8119068.html
Copyright © 2011-2022 走看看