void calcuRain(int time, List <string[]> RainRecordList) { if (RainRecordList.Count == 0) { return; } string[] record = RainRecordList[0]; int rainTime = Convert.ToInt32(record[0]); string path = record[1]; if (time < rainTime) { for (int i = 0; i < rowCount; i++) { for (int j = 0; j < colCount; j++) { ////如果到达数据边界就不参与计算 if (i - 1 < 0 || i + 1 > rowCount - 1 || j - 1 < 0 || j + 1 > colCount - 1) { canCuculate[i, j] = false; continue; } if (dem[i - 1, j - 1] == nodataValue || dem[i - 1, j + 1] == nodataValue || dem[i + 1, j - 1] == nodataValue || dem[i + 1, j + 1] == nodataValue) { canCuculate[i, j] = false; continue; } if (rainDeepMat[i, j] != -9999 && dem[i, j] != -9999 && canCuculate[i, j]) { waterDeep[i, j] += rainDeepMat[i, j] * stepTime; } } } } else { RainRecordList.RemoveAt(0); if (RainRecordList.Count > 0) { record = RainRecordList[0]; rainTime = Convert.ToInt32(record[0]); path = record[1]; GISdataManager.readRaster(path, ref rainDeepRaster); rainDeepMat = GISdataManager.Raster2Mat(rainDeepRaster); for (int i = 0; i < rowCount; i++) { for (int j = 0; j < colCount; j++) { if (i - 1 < 0 || i + 1 > rowCount - 1 || j - 1 < 0 || j + 1 > colCount - 1) { canCuculate[i, j] = false; continue; } if (dem[i - 1, j - 1] == nodataValue || dem[i - 1, j + 1] == nodataValue || dem[i + 1, j - 1] == nodataValue || dem[i + 1, j + 1] == nodataValue) { canCuculate[i, j] = false; continue; } if (rainDeepMat[i, j] != -9999 && dem[i, j] != -9999 && canCuculate[i, j]) { if (canCuculate[i, j]) { waterDeep[i, j] += rainDeepMat[i, j] * stepTime; } } } } } else { return; } } }
void FloodStart() { //读入dem,manning,rain DemPath = txbDemIpute.Text; GISdataManager.readRaster(DemPath, ref demRaster); dem = GISdataManager.Raster2Mat(demRaster); ManningPath = txbManingInput.Text; GISdataManager.readRaster(ManningPath, ref manningRaster); manNing = GISdataManager.Raster2Mat(manningRaster); RainRecordPath = txbRaintxt.Text; rainRecordList = TxTReader.txt2List2(RainRecordPath); if (rainRecordList.Count > 0) { string[] record = rainRecordList[0]; string path; path = record[1]; GISdataManager.readRaster(path, ref rainDeepRaster); rainDeepMat = GISdataManager.Raster2Mat(rainDeepRaster); } else { MessageBox.Show("请重新输入有效降雨数据!"); return; } //获取栅格分辨率 IRasterInfo rasterinfo = (demRaster.Raster as IRawBlocks).RasterInfo; flowLength = Convert.ToInt32(rasterinfo.CellSize.X); flowLength2 = flowLength * 1.141f; //判断DEM与曼宁系数栅格是否一致! if (demRaster.ColumnCount != manningRaster.ColumnCount || demRaster.RowCount != manningRaster.RowCount) { MessageBox.Show("请保证曼宁糙率栅格行列是否与DEM一致,请对应后重新输入!"); return; } rowCount = demRaster.RowCount; colCount = demRaster.ColumnCount; //初始化中间参数 slope = new float[rowCount, colCount]; flowDir = new byte[rowCount, colCount]; canCuculate = new bool[rowCount, colCount]; waterDeep = new float[rowCount, colCount]; tempDeep = new float[rowCount, colCount]; flowVel = new float[rowCount, colCount]; arrived = new bool[rowCount, colCount]; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < colCount; j++) { slope[i, j] = 0f; flowDir[i, j] = 0; waterDeep[i, j] = 0f; tempDeep[i, j] = 0f; flowVel[i, j] = 0f; arrived[i, j] = false; } } DBpointPath = txbDBpoint.Text; GISdataManager.readSHP(DBpointPath, ref DBpointshp); IFeatureClass featureClass = DBpointshp.FeatureClass; int count = featureClass.FeatureCount(new QueryFilter()); for (int i = 0; i < count; i++) { IFeature feature = featureClass.GetFeature(i); IGeometry Geo = feature.Shape; IPoint point = Geo as IPoint; double x, y; x = point.X; y = point.Y; //获取出水点在Mit中的位置 IRaster raster = demRaster.Raster; IRaster2 raster2 = raster as IRaster2; DPcolIndex = raster2.ToPixelColumn(x); DProwIndex = raster2.ToPixelRow(y); dbPointList.Add(new int[2] { DProwIndex, DPcolIndex }); arrived[DProwIndex, DPcolIndex] = true; } //读取流量过程线表格 HydroPath = txbHydroghraph.Text; HydroRecordList = TxTReader.txt2List3(HydroPath, dbPointList.Count); //初始化计算范围 for (int i = 0; i < rowCount; i++) { for (int j = 0; j < colCount; j++) { if (dem[i, j] != nodataValue) { canCuculate[i, j] = true; } } } }
private void calculateDepth() { pm = new ProcessManager(); this.Invoke(pm.createProcessWindow()); try { this.Invoke(pm.addInfomation, new object[] { "正在读取最大下渗量图层..." }); GISdataManager.readRaster(tBInfilPath.Text, ref infilLayer); mann = GISdataManager.Raster2Mat(infilLayer); this.Invoke(pm.addInfomation, new object[] { "读取最大下渗量图层成功" }); } catch (Exception e) { } output = new float[infilLayer.ColumnCount, infilLayer.RowCount]; int.TryParse(tBRainTime.Text, out rainTime); DirectoryInfo dirInfo = new DirectoryInfo(tBRainPath.Text); this.Invoke(pm.setProcess, new object [] { 0, dirInfo.GetFiles("*.img").Length }); int key = 0; foreach (var info in dirInfo.GetFiles("*.img")) { try { this.Invoke(pm.updateProcess, new object[] { String.Format("正在读取{0}图层...", info.Name), key }); GISdataManager.readRaster(info.FullName, ref rainLayer); rain = GISdataManager.Raster2Mat(rainLayer); this.Invoke(pm.addInfomation, new object[] { String.Format("读取{0}图层成功", info.Name) }); } catch (Exception e) { } if (infilLayer.ColumnCount != rainLayer.ColumnCount || infilLayer.RowCount != rainLayer.RowCount) { this.Invoke(pm.addInfomation, new object[] { String.Format("该雨量图层与最大下渗量图层不匹配,跳过") }); continue; } this.Invoke(pm.updateProcess, new object[] { String.Format("正在存储第{0}图层...", key + 1), key }); Parallel.For(0, infilLayer.ColumnCount, i => { for (int j = 0; j < infilLayer.RowCount; j++) { if (mann[i, j] > noDataValue) { float pureRain = rain[i, j] - mann[i, j] * 0.2f; if (pureRain > 0) { output[i, j] = (pureRain * pureRain / (pureRain + mann[i, j])) / (rainTime * 1000); } else { output[i, j] = 0f; } } else { output[i, j] = 0f; } } }); var name = info.FullName; var groups = Regex.Match(name, @"(\d+.img)").Groups; GISdataManager.exportRasterData(tBSavePath.Text + "\\rain" + groups[0].Value, infilLayer, output); this.Invoke(pm.addInfomation, new object[] { String.Format("存储第{0}图层成功", key + 1) }); key++; } }
Boolean calcuRain(int time, List <string[]> RainRecordList) { if (rainRecordList.Count != 0) { string[] record = RainRecordList[0]; int rainTime = Convert.ToInt32(record[0]); if (time == 0) { rainTime = 0; } if (time >= rainTime) { if (time != 0) { RainRecordList.RemoveAt(0); } if (rainRecordList.Count == 0) { return(true); } record = RainRecordList[0]; int nextTime = Convert.ToInt32(record[0]); string path = record[1]; this.Invoke(pm.addInfomation, new object[] { String.Format("正在读取{1}-{2}s雨量数据,路径为:{0}", path, rainTime, nextTime) }); try { GISdataManager.readRaster(path, ref rainDeepRaster); rainDeepMat = GISdataManager.Raster2Mat(rainDeepRaster); Parallel.For(0, colCount, i => { for (int j = 0; j < rowCount; j++) { ////如果到达数据边界就不参与计算 if (i - 1 < 0 || i + 1 > colCount - 1 || j - 1 < 0 || j + 1 > rowCount - 1) { canCuculate[i, j] = false; continue; } if (dem[i - 1, j - 1] < nodataValue || dem[i - 1, j + 1] < nodataValue || dem[i + 1, j - 1] < nodataValue || dem[i + 1, j + 1] < nodataValue || dem[i - 1, j] < nodataValue || dem[i, j + 1] < nodataValue || dem[i, j - 1] < nodataValue || dem[i + 1, j] < nodataValue || dem[i, j] < nodataValue) { canCuculate[i, j] = false; continue; } if (rainDeepMat[i - 1, j - 1] < nodataValue || rainDeepMat[i - 1, j + 1] < nodataValue || rainDeepMat[i + 1, j - 1] < nodataValue || rainDeepMat[i + 1, j + 1] < nodataValue || rainDeepMat[i - 1, j] < nodataValue || rainDeepMat[i, j + 1] < nodataValue || rainDeepMat[i, j - 1] < nodataValue || rainDeepMat[i + 1, j] < nodataValue || rainDeepMat[i, j] < nodataValue) { canCuculate[i, j] = false; continue; } if (manNing[i - 1, j - 1] < nodataValue || manNing[i - 1, j + 1] < nodataValue || manNing[i + 1, j - 1] < nodataValue || manNing[i + 1, j + 1] < nodataValue || manNing[i - 1, j] < nodataValue || manNing[i, j + 1] < nodataValue || manNing[i, j - 1] < nodataValue || manNing[i + 1, j] < nodataValue || manNing[i, j] < nodataValue) { canCuculate[i, j] = false; continue; } } }); this.Invoke(pm.addInfomation, new object[] { String.Format("读取{0}-{1}s的净雨强度读取成功", rainTime, nextTime) }); } catch (Exception e) { this.Invoke(pm.addInfomation, new object[] { String.Format("读取{0}-{1}s的净雨强度读取失败,错误代码为{2}", rainTime, nextTime, e.ToString()) }); return(false); } } for (int i = 0; i < colCount; i++) { for (int j = 0; j < rowCount; j++) { if (rainDeepMat[i, j] != -9999 && dem[i, j] != -9999 && canCuculate[i, j]) { waterDeep[i, j] += rainDeepMat[i, j] * stepTime; } } } } return(true); }
Boolean FloodStart() { //读入dem,manning,rain this.Invoke(pm.addInfomation, new object[] { "正在读取DEM文件..." }); DemPath = txbDemIpute.Text; GISdataManager.readRaster(DemPath, ref demRaster); dem = GISdataManager.Raster2Mat(demRaster); this.Invoke(pm.addInfomation, new object[] { "DEM数据读取完毕,并写入DEM数组中" }); this.Invoke(pm.addInfomation, new object[] { "正在读取曼宁系数文件..." }); ManningPath = txbManingInput.Text; GISdataManager.readRaster(ManningPath, ref manningRaster); manNing = GISdataManager.Raster2Mat(manningRaster); this.Invoke(pm.addInfomation, new object[] { "曼宁系数数据读取完毕,并写入曼宁系数数组中" }); RainRecordPath = txbRaintxt.Text; rainRecordList = TxTReader.txt2List2(RainRecordPath); this.Invoke(pm.addInfomation, new object[] { "正在判断雨量格式是否正确..." }); if (rainRecordList.Count > 0) { this.Invoke(pm.addInfomation, new object[] { "雨量数据格式正确" }); } else { this.Invoke(pm.addInfomation, new object[] { "请重新输入有效降雨数据" }); return(false); } //获取栅格分辨率 IRasterInfo rasterinfo = (demRaster.Raster as IRawBlocks).RasterInfo; flowLength = Convert.ToInt32(rasterinfo.CellSize.X); this.Invoke(pm.addInfomation, new object[] { String.Format("DEM栅格宽度为:{0}m", flowLength) }); //maxSpeed = (float)Math.Sqrt(flowLength * 10); maxSpeed = 10f; flowLength2 = flowLength * 1.141f; //判断DEM与曼宁系数栅格是否一致! if (demRaster.ColumnCount != manningRaster.ColumnCount || demRaster.RowCount != manningRaster.RowCount) { this.Invoke(pm.addInfomation, new object[] { "曼宁糙率栅格行列与DEM不一致,请对应后重新输入!" }); return(false); } rowCount = demRaster.RowCount; colCount = demRaster.ColumnCount; Console.WriteLine(rowCount + "," + colCount); //初始化中间参数 slope = new float[colCount, rowCount]; //坡度矩阵 flowDir = new Dirction[colCount, rowCount]; //流向矩阵 canCuculate = new bool[colCount, rowCount]; //用于判断矩阵中的点是否在DEM范围内 waterDeep = new float[colCount, rowCount]; //水深矩阵 tempDeep = new float[colCount, rowCount]; // flowVel = new float[colCount, rowCount]; for (int i = 0; i < colCount; i++) { for (int j = 0; j < rowCount; j++) { slope[i, j] = 0f; flowDir[i, j] = new Dirction() { x = 0, y = 0 }; if (dem[i, j] == nodataValue) { waterDeep[i, j] = nodataValue; } else { waterDeep[i, j] = 0f; } tempDeep[i, j] = 0f; flowVel[i, j] = 0f; } } for (int i = 0; i < colCount; i++) { for (int j = 0; j < rowCount; j++) { if (dem[i, j] != nodataValue) { canCuculate[i, j] = true; } } } return(true); }
void DemBreakStart() { //读入dem,manning DemPath = txbDemIpute.Text; GISdataManager.readRaster(DemPath, ref demRaster); // //IRasterProps rasterprops = demRaster.Raster as IRasterProps; //object nodataValue1 = rasterprops.NoDataValue; //float[] mit = nodataValue1 as float[]; //nodataValue = mit[0]; // dem = GISdataManager.Raster2Mat(demRaster); ManningPath = txbManingInput.Text; GISdataManager.readRaster(ManningPath, ref manningRaster); manNing = GISdataManager.Raster2Mat(manningRaster); //获取栅格分辨率 IRasterInfo rasterinfo = (demRaster.Raster as IRawBlocks).RasterInfo; flowLength = Convert.ToInt32(rasterinfo.CellSize.X); flowLength2 = flowLength * 1.141f; //判断DEM与曼宁系数栅格是否一致! if (demRaster.ColumnCount != manningRaster.ColumnCount || demRaster.RowCount != manningRaster.RowCount) { MessageBox.Show("请在检查DEM与曼宁糙率栅格行列是否对应后重新输入!"); return; } rowCount = demRaster.RowCount; colCount = demRaster.ColumnCount; //初始化中间参数 slope = new float[rowCount, colCount]; flowDir = new byte[rowCount, colCount]; waterDeep = new float[rowCount, colCount]; tempDeep = new float[rowCount, colCount]; flowVel = new float[rowCount, colCount]; arrived = new bool[rowCount, colCount]; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < colCount; j++) { slope[i, j] = 0f; flowDir[i, j] = 0; waterDeep[i, j] = 0f; tempDeep[i, j] = 0f; flowVel[i, j] = 0f; arrived[i, j] = false; } } DBpointPath = txbDBpoint.Text; GISdataManager.readSHP(DBpointPath, ref DBpointshp); IFeatureClass featureClass = DBpointshp.FeatureClass; int count = featureClass.FeatureCount(new QueryFilter()); for (int i = 0; i < count; i++) { IFeature feature = featureClass.GetFeature(i); IGeometry Geo = feature.Shape; IPoint point = Geo as IPoint; double x, y; x = point.X; y = point.Y; //获取出水点在Mit中的位置 IRaster raster = demRaster.Raster; IRaster2 raster2 = raster as IRaster2; DPcolIndex = raster2.ToPixelColumn(x); DProwIndex = raster2.ToPixelRow(y); dbPointList.Add(new int[2] { DProwIndex, DPcolIndex }); arrived[DProwIndex, DPcolIndex] = true; waterGrids.Add(new int[2] { DProwIndex, DPcolIndex }); } //读取流量过程线表格 HydroPath = txbHydroghraph.Text; HydroRecordList = TxTReader.txt2List3(HydroPath, dbPointList.Count); }