洪澇淹沒分析輸出淹沒範圍圖、深度圖及面積體積
阿新 • • 發佈:2018-11-14
[csharp] view plain copy
- /// <summary>
- /// 輸出洪澇淹沒範圍圖
- /// </summary>
- public void OutPutFloodRegion()
- {
- //建立洪澇淹沒範圍影像
- string m_FloodRegionPath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\FloodSimulation\\FloodedRegion.tif";
- if (System.IO.File.Exists(m_FloodRegionPath))
- {
- System.IO.File.Delete(m_FloodRegionPath);
- }
- //在GDAL中建立影像,先需要明確待建立影像的格式,並獲取到該影像格式的驅動
- driver = Gdal.GetDriverByName("GTiff");
- //呼叫Creat函式建立影像
- m_FloodSimulationRegionDataSet = driver.Create(m_FloodRegionPath, m_XSize, m_YSize, 1, DataType.GDT_Float32, null);
- //設定影像屬性
- m_FloodSimulationRegionDataSet.SetGeoTransform(m_adfGeoTransform); //影像轉換引數
- m_FloodSimulationRegionDataSet.SetProjection(m_DEMDataSet.GetProjectionRef()); //投影
- //輸出影像
- m_FloodSimulationRegionDataSet.GetRasterBand(1).WriteRaster(0, 0, m_XSize, m_YSize, m_FloodRegionBuffer, m_XSize, m_YSize, 0, 0);
- m_FloodSimulationRegionDataSet.GetRasterBand(1).FlushCache();
- m_FloodSimulationRegionDataSet.FlushCache();
- }
- /// <summary>
- /// 輸出洪澇淹沒深度圖
- /// </summary>
- public void OutPutFloodDepth()
- {
- for (int i = 0; i < m_XSize; i++)
- {
- for (int j = 0; j < m_YSize; j++)
- {
- Point m_point = new Point();
- m_point.X = i;
- m_point.Y = j;
- if (m_FloodRegionBuffer[getIndex(m_point)] == 1)
- {
- int evaluation = m_DEMdataBuffer[getIndex(m_point)]; //淹沒格網高程值
- int value = pFloodLevel - evaluation;
- m_FloodDepthBuffer[getIndex(m_point)] = value;
- }
- }
- }
- //輸出洪澇淹沒深度圖
- string m_FloodDepthPath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\FloodSimulation\\FloodedDepth.tif";
- if (System.IO.File.Exists(m_FloodDepthPath))
- {
- System.IO.File.Delete(m_FloodDepthPath);
- }
- //在GDAL中建立影像,先需要明確待建立影像的格式,並獲取到該影像格式的驅動
- driver = Gdal.GetDriverByName("GTiff");
- //呼叫Creat函式建立影像
- m_FloodSimulationDepthDateSet = driver.Create(m_FloodDepthPath, m_XSize, m_YSize, 1, DataType.GDT_Float32, null);
- //設定影像屬性
- m_FloodSimulationDepthDateSet.SetGeoTransform(m_adfGeoTransform); //影像轉換引數
- m_FloodSimulationDepthDateSet.SetProjection(m_DEMDataSet.GetProjectionRef()); //投影
- //輸出影像
- m_FloodSimulationDepthDateSet.GetRasterBand(1).WriteRaster(0, 0, m_XSize, m_YSize, m_FloodDepthBuffer, m_XSize, m_YSize, 0, 0);
- m_FloodSimulationDepthDateSet.GetRasterBand(1).FlushCache();
- m_FloodSimulationDepthDateSet.FlushCache();
- }
- /// <summary>
- /// 輸出洪澇淹沒面積及水量
- /// </summary>
- public void OutPutFloodInfo()
- {
- int count = 0;
- for (int i = 0; i < m_XSize; i++)
- {
- for (int j = 0; j < m_YSize; j++)
- {
- Point m_point = new Point();
- m_point.X = i;
- m_point.Y = j;
- if (m_FloodRegionBuffer[getIndex(m_point)] == 1)
- {
- count++;
- }
- }
- }
- //統計面積
- double S = count * 90; //平方米
- if (S > 10000)
- {
- S = S / 10000; //公頃
- }
- MessageBox.Show("淹沒面積:" + S.ToString() + "公頃");
- }
結果圖:範圍圖與深度圖