接上一篇博客《洪涝有源淹没算法及结果分析》。可以输出洪涝淹没范围图、深度图以及淹没面积等信息,下一步输出历时图。代码很简单,下面直接给出源代码,欢迎大家留言交流。
/// <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() + "公顷");
}
结果图:范围图与深度图