private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { string[] args = e.Argument as string[]; double avgLength = 0; double avgSlope = 0; if (File.Exists(args[0]) && File.Exists(args[1])) { FormOutput.AppendLog("开始获取线的交点..."); RasterReader reader = new RasterReader(args[1]); List <Point3d> pts = CalPoints(args[0], reader); FormOutput.AppendLog("开始计算平均坡度和坡长..."); CalAvgSlopeLength(pts, reader, ref avgLength, ref avgSlope); reader.Dispose(); FormOutput.AppendLog("平均坡长:" + avgLength.ToString("f3")); FormOutput.AppendLog("平均坡度:" + avgSlope.ToString("f3")); } double?r = null; if (File.Exists(args[1]) && File.Exists(args[2])) { FormOutput.AppendLog("开始计算坡面流速系数..."); r = RasterCoefficientReader.ReadCoeficient(args[2], args[1]); if (r.HasValue) { FormOutput.AppendLog("结果--坡面流速系数为:" + r.Value.ToString()); } } e.Result = new double[] { avgLength, avgSlope, r.GetValueOrDefault(0) }; }
private void ShowResult0(IntPtr windowPtr) { SubCure cv = XmlHelper.Deserialize <SubCure>(Path.Combine(Application.StartupPath, ConfigNames.SubCure0)); if (cv != null) { if (this.InvokeRequired) { this.Invoke(new Action(() => { this.DockFigure(windowPtr); _currentPtr = windowPtr; StringBuilder build = new StringBuilder(); build.AppendLine("计算结果:"); build.AppendLine("暴雨雨力Sd = " + cv.Sd); build.AppendLine("衰减指数nd = " + cv.nd); build.AppendLine("斜率n = " + cv.n1); build.AppendLine("截距s = " + cv.j1); FormOutput.AppendLog(build.ToString()); SdData2.Text = cv.Sd.ToString(); ndData2.Text = cv.nd.ToString(); Jieju.Text = cv.j1.ToString(); Xielv.Text = cv.n1.ToString(); tabControl1.SelectedTab = tabControl1.Tabs[2]; })); } } }
private void ShowResult(IntPtr windowPtr) { CvCure cv = XmlHelper.Deserialize <CvCure>(Path.Combine(Application.StartupPath, ConfigNames.SvCure)); StringBuilder builder = new StringBuilder(); builder.AppendLine("计算结果:"); builder.AppendLine("统计样本平均值X = " + cv.X); builder.AppendLine("变差系数Cv = " + cv.Cv); builder.AppendLine("偏态系数Cs = " + cv.Cs); builder.AppendLine("拟合度N = " + cv.Nihe); FormOutput.AppendLog(builder.ToString()); if (cv != null) { if (_parent.InvokeRequired) { _parent.Invoke(new Action(() => { if (_resutUI == null) { _resutUI = new CaculatePercentUI(); _resutUI.Dock = DockStyle.Fill; _parent.ShowDock("暴雨频率计算", _resutUI); } cv.State = txtState.Text; cv.Time = cmbPercent.SelectedValue.ToString(); _resutUI.BindResult(cv, windowPtr); })); } } }
/// <summary> /// 计算影像数据单元格的投影面积 /// (区分了文件为投影坐标还是地理坐标) /// </summary> /// <param name="reader"></param> /// <param name="_widthNum"></param> /// <param name="_heightNum"></param> /// <returns></returns> private double CaculateCellAera(RasterReader reader, int _widthNum, int _heightNum) { try { int ti, tj; ti = _widthNum / 2; tj = _heightNum / 2; iTelluro.GlobeEngine.DataSource.Geometry.Point3d p00, p01, p10; if (reader.IsProjected) { p00 = new Point3d(_terrainTile[ti, tj].Longitude, _terrainTile[ti, tj].Latitude, _terrainTile[ti, tj].Altitude); p01 = new Point3d(_terrainTile[ti, tj + 1].Longitude, _terrainTile[ti, tj + 1].Latitude, _terrainTile[ti, tj + 1].Altitude); p10 = new Point3d(_terrainTile[ti + 1, tj].Longitude, _terrainTile[ti + 1, tj].Latitude, _terrainTile[ti + 1, tj].Altitude); } else { double r = _globeView.GlobeViewSetting.EquatorialRadius + _terrainTile[ti, tj].Altitude; p00 = MathEngine.SphericalToCartesianD(Angle.FromDegrees(_terrainTile[ti, tj].Latitude), Angle.FromDegrees(_terrainTile[ti, tj].Longitude), r); p01 = MathEngine.SphericalToCartesianD(Angle.FromDegrees(_terrainTile[ti, tj + 1].Latitude), Angle.FromDegrees(_terrainTile[ti, tj + 1].Longitude), r); p10 = MathEngine.SphericalToCartesianD(Angle.FromDegrees(_terrainTile[ti + 1, tj].Latitude), Angle.FromDegrees(_terrainTile[ti + 1, tj].Longitude), r); } double area = (p00 - p01).Length * (p00 - p10).Length; return(area); } catch (Exception ex) { FormOutput.AppendLog(ex.Message); return(0); } }
private void bgwCaculate_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Result != null) { FormOutput.AppendLog(e.Result.ToString()); } }
private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) { Dictionary <int, double[]> dicArgs = e.Argument as Dictionary <int, double[]>; //将数据按照大于一小时和小于一小时来分类 string minHour = string.Empty; string minHourValue = string.Empty; string maxHour = string.Empty; string maxHourValue = string.Empty; StringBuilder builder = new StringBuilder(); builder.AppendLine("*******************计算参数***********************"); foreach (var item in dicArgs) { double during = item.Value[0]; //范围-值 double value = item.Value[1]; minHour += during; minHourValue += value; minHour += ","; minHourValue += ","; builder.AppendLine(string.Format("a{0} = {1}", item.Key, value)); builder.AppendLine(string.Format("t{0} = {1}", item.Key, during)); } builder.AppendLine("***************************************************"); builder.AppendLine("开始计算暴雨衰减参数..."); FormOutput.AppendLog(builder.ToString()); builder = new StringBuilder(); builder.Append(MethodName.RainStormSub0); builder.Append(" "); builder.Append(minHour.Substring(0, minHour.Length - 1)); builder.Append(" "); builder.Append(minHourValue.Substring(0, minHourValue.Length - 1)); RunExeHelper.RunMethod(builder.ToString()); e.Result = "1"; }
private void backgroundWorker2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Result != null) { FormOutput.AppendLog(string.Format("提取结束,共耗时{0}秒..", (DateTime.Now - _currentTime).TotalSeconds)); System.Diagnostics.Process.Start("Explorer.exe", Path.GetDirectoryName(e.Result.ToString())); } FormOutput.AppendProress(false); currentDem = fileChooseControl1.FilePath; }
private void backgroundWorker2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { FormOutput.AppendLog("计算期间发生异常:" + e.Error.Message); return; } if (e.Result != null) { RunExeHelper.FindFigureAndTodo(ShowResult0); } }
private void button1_Click(object sender, EventArgs e) { if (!backgroundWorker1.IsBusy) { string state = txtState.Text; string level = cmbLevel.SelectedValue.ToString(); backgroundWorker1.RunWorkerAsync(new string[] { state, level }); } else { FormOutput.AppendLog("当前后台正在计算..."); } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { string[] args = e.Argument as string[]; //state-percent FormOutput.AppendLog(string.Format("读取数据库站点【{0}】时间段为【{1}】的年统计最大值...", args[0], args[1])); //读取数据库某个站点某个统计频率的年统计最大值 string commandText = string.Format("select {0} from RAINFALL_YEAR_MAX where MONITORNUM='{1}' order by {0} desc", args[1], args[0]); DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, commandText); //整理数据 List <PercentStaticsModel> lstStatics = new List <PercentStaticsModel>(); string points = string.Empty; if (ds.Tables[0].Rows.Count == 0) { FormOutput.AppendLog("统计数据不足,请重新选择统计条件!"); return; } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (ds.Tables[0].Rows[i][0] == DBNull.Value) { continue; } PercentStaticsModel temp = new PercentStaticsModel() { RowIndex = i + 1, MaxValue = Convert.ToDecimal(ds.Tables[0].Rows[i][0]), CArg = ((decimal)(i + 1)) / ds.Tables[0].Rows.Count }; lstStatics.Add(temp); points += ds.Tables[0].Rows[i][0]; if (i < ds.Tables[0].Rows.Count - 1) { points += ","; } } FormOutput.AppendLog(string.Format("统计值的数量为{0}个..", ds.Tables[0].Rows.Count)); FormOutput.AppendLog(string.Format("统计值为[{0}]", points)); string filePath = Path.Combine(Application.StartupPath, "SStatic.xls"); if (File.Exists(filePath)) { File.Delete(filePath); } //保存数据到xls XmlHelper.SaveDataToExcelFile <PercentStaticsModel>(lstStatics, filePath); FormOutput.AppendLog("开始计算暴雨频率曲线.."); RunExeHelper.RunMethod(MethodName.SWCure); e.Result = "1"; }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { string[] args = e.Argument as string[]; //FormOutput.AppendLog(string.Format("开始从数据库中获取站号【{0}】频率为【{1}%】的单点雨量值", args[0], args[1])); string commandText = string.Format("select During,VALUE from rainfall_percent where MONITORNUM='{0}' and [PERCENT]={1} order by During", args[0], args[1]); DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, commandText); if (ds.Tables[0].Rows.Count == 0) { FormOutput.AppendLog("未查询到数据.."); } e.Result = ds; }
/// <summary> /// 适线计算 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCaculate_Click(object sender, EventArgs e) { FormOutput.AppendLog("开始重新适配曲线,获取新的拟合度和曲线.."); StringBuilder builder = new StringBuilder(); builder.Append(MethodName.NiHeCure); builder.Append(" "); builder.Append(numX.Value.ToString()); builder.Append(" "); builder.Append(numCv.Value.ToString()); builder.Append(" "); builder.Append(numCs.Value.ToString()); RunExeHelper.RunMethod(builder.ToString()); RunExeHelper.FindFigureAndTodo(ShowNiHe); }
private void button1_Click(object sender, EventArgs e) { if (!backgroundWorker1.IsBusy) { FormOutput.AppendLog("开始计算..."); //progressBar1.Visible = true; string state = txtState.Text; string percent = cmbPercent.SelectedValue.ToString(); backgroundWorker1.RunWorkerAsync(new string[] { state, percent }); } else { FormOutput.AppendLog("当前后台正在计算..."); } }
private void ShowResult(IntPtr windowPtr) { SubCure cv = XmlHelper.Deserialize <SubCure>(Path.Combine(Application.StartupPath, ConfigNames.SubCure)); if (cv != null) { if (this.InvokeRequired) { this.Invoke(new Action(() => { this.DockFigure(windowPtr); _currentPtr = windowPtr; StringBuilder build = new StringBuilder(); build.AppendLine("计算结果:"); build.AppendLine("暴雨雨力Sd = " + cv.Sd); build.AppendLine("衰减指数nd = " + cv.nd); build.AppendLine("衰减时间参数d = " + cv.d); build.AppendLine("t<=1时拟合曲线特性"); build.AppendLine("斜率n1 = " + cv.n1); build.AppendLine("截距s1 = " + cv.j1); build.AppendLine("t>1时拟合曲线特性"); build.AppendLine("斜率n2 = " + cv.n2); build.AppendLine("截距s2 = " + cv.j2); build.AppendLine("n2与n1的比为n2/n1 = " + cv.n2 / cv.n1); if (cv.n2 / cv.n1 > 1.5) { build.AppendLine("斜率比大于1.5,结果无效!"); } else { build.AppendLine("斜率比小于1.5,结果有效!"); } FormOutput.AppendLog(build.ToString()); dData.Text = cv.d.ToString(); SdData.Text = cv.Sd.ToString(); ndData.Text = cv.nd.ToString(); JiejuS1.Text = cv.j1.ToString(); JiejuS2.Text = cv.j2.ToString(); Xielvn1.Text = cv.n1.ToString(); Xielvn2.Text = cv.n2.ToString(); tabControl1.SelectedTab = tabControl1.Tabs[1]; })); } } }
/// <summary> /// 用于接取后台数据 /// </summary> /// <param name="windowPtr"></param> private void ShowNiHe(IntPtr windowPtr) { string cv = XmlHelper.Deserialize <string>(Path.Combine(Application.StartupPath, ConfigNames.TempName)); FormOutput.AppendLog(string.Format("计算结果:拟合度{0}", cv)); if (cv != null) { if (panel2.InvokeRequired) { panel2.Invoke(new Action(() => { txtNihe.Text = cv; this.DockFigure(windowPtr); })); } } }
/// <summary> /// 暴雨损失参数计算 /// </summary> /// <param name="shppath"></param> /// <param name="inputDemPath"></param> /// <param name="outDemPath"></param> public void RainLoss(string Rshppath, string rshppath, string inputDemPath, string areaShp, ref DoWorkEventArgs e) { //计算流域面积 double F = 0; double?sf = null; double?N = null; if (File.Exists(areaShp)) { FormOutput.AppendLog("开始计算流域面积和折减系数"); WatershedArea(areaShp, inputDemPath, ref F, ref sf); sf = sf / 1000000; FormOutput.AppendLog(string.Format("流域表面积SF = {0}km²", sf.Value.ToString("f3"))); F = F / 1000000; FormOutput.AppendLog(string.Format("流域投影面积F = {0}km²", F.ToString("f3"))); N = 1 / (1 + 0.016 * F * 0.6);//折减系数 FormOutput.AppendLog("折减系数N = " + N.Value.ToString("f3")); } //计算折减系数 double?R = null; if (File.Exists(Rshppath)) { FormOutput.AppendLog("开始计算损失系数"); R = RasterCoefficientReader.ReadCoeficient(Rshppath, inputDemPath); if (R.HasValue) { FormOutput.AppendLog("损失系数R = " + R.Value.ToString("f3")); } } double?r = null; if (File.Exists(rshppath)) { FormOutput.AppendLog("开始计算损失指数"); r = RasterCoefficientReader.ReadCoeficient(rshppath, inputDemPath); if (r.HasValue) { FormOutput.AppendLog("损失指数r = " + r.Value.ToString("f3")); } } e.Result = new double?[] { F, N, R, r }; }
public void BindResult(string filePath, IntPtr windowPtr) { _filePath = filePath; //开启一个线程来读取xml文件,因为数据是在图形绘制完之后才出来 Thread thread = new Thread(new ThreadStart(delegate { while (true) { if (File.Exists(filePath)) { this.Invoke(new Action(() => { MainResult cv = XmlHelper.Deserialize <MainResult>(filePath); //初始化参数 if (cv != null) { StringBuilder builder = new StringBuilder(); builder.AppendLine("计算结果:"); builder.AppendLine("洪峰流量Qm = " + cv.Qm); builder.AppendLine("洪峰历时系数p1_0 = " + cv.p1); builder.AppendLine("造峰历时tQ = " + cv.tQ); builder.AppendLine("洪峰上涨历时t = " + cv.t); builder.AppendLine("产流期净雨强a1tc = " + cv.a1tc); builder.AppendLine("迭代次数:" + cv.d1 + "-" + cv.d2); FormOutput.AppendLog(builder.ToString()); txtQm.Text = cv.Qm.ToString(); txtP1.Text = cv.p1.ToString(); txttQ.Text = cv.tQ.ToString(); txtt.Text = cv.t.ToString(); txta1tc.Text = cv.a1tc.ToString(); txtd1.Text = cv.d1.ToString(); txtd2.Text = cv.d2.ToString(); } })); break; } } })); thread.IsBackground = true; thread.Start(); //初始化曲线 this.DockFigure(windowPtr); }
/// <summary> /// 将当前时间段当前站点的数据入库 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnInsert_Click(object sender, EventArgs e) { if (bgwCaculate.IsBusy == false) { FormOutput.AppendLog(string.Format("开始入库时间段为{0},站号为{1}的概率数据", _currentTime, _cuurentState)); CvCure arg = new CvCure() { State = _cuurentState, Time = _currentTime, X = Convert.ToDouble(numX.Value), Cv = Convert.ToDouble(numCv.Value), Cs = Convert.ToDouble(numCs.Value) }; bgwCaculate.RunWorkerAsync(arg); } else { FormOutput.AppendLog("当前后台正在入库,请稍候"); } }
/// <summary> /// 计算 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { if (!backgroundWorker1.IsBusy) { FormOutput.AppendLog("开始计算..."); FormOutput.AppendProress(true); _currentTime = DateTime.Now; SaveCaculateArg(); //获取计算参数 string tifPath = fileChooseControl1.FilePath; //影像路径 string areaShp = fileChooseControl2.FilePath; //流域面积shp string RShp = fileChooseControl3.FilePath; //系数R string rShp = fileChooseControl4.FilePath; //指数r //progressBar1.Visible = true; backgroundWorker1.RunWorkerAsync(new string[] { tifPath, areaShp, RShp, rShp }); } else { FormOutput.AppendLog("当前后台正在计算..."); } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { string[] args = e.Argument as string[]; double riverlength = 0; double j = 0; if (File.Exists(args[0]) && File.Exists(args[1])) { FormOutput.AppendLog("开始递归所有沟道分支..."); List <Dictionary <Point2d, Geometry> > results = GetAllRivers(args[0]); FormOutput.AppendLog(string.Format("共得到{0}条支流...", results.Count)); FormOutput.AppendLog("开始获取主沟道,并计算其长度..."); riverlength = CaculateRiver(results, args[1], ref _mainRiver); riverlength = riverlength / 1000; FormOutput.AppendLog("主河道长度:" + riverlength.ToString("f3")); FormOutput.AppendLog("开始计算主沟道纵降比..."); j = GetLonGradient(_mainRiver, args[1]); FormOutput.AppendLog("主河道纵降比:" + j.ToString("f3")); } double?r = null; if (File.Exists(args[2]) && File.Exists(args[1])) { FormOutput.AppendLog("开始计算沟道流域系数..."); r = RasterCoefficientReader.ReadCoeficient(args[2], args[1]); if (r.HasValue) { FormOutput.AppendLog("沟道流速系数:" + r.Value.ToString("f3")); } } e.Result = new double[] { riverlength, j, r.GetValueOrDefault(0) }; }
/// <summary> /// 开始计算 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { if (!backgroundWorker1.IsBusy) { FormOutput.AppendLog("开始计算..."); FormOutput.AppendProress(true); //保存计算参数 List <NodeModel> result = new List <NodeModel>(); NodeModel model = fileChooseControl1.SelectedValue; if (model != null) { CopyAddNodeModel(result, model); } NodeModel model1 = fileChooseControl2.SelectedValue; if (model1 != null) { CopyAddNodeModel(result, model1); } NodeModel model2 = fileChooseControl3.SelectedValue; if (model2 != null) { CopyAddNodeModel(result, model2); } _parent.OporateCaculateNode(Guids.PMHL, result.ToArray()); //获取计算参数 string tifPath = fileChooseControl1.FilePath; //影像路径 string mainShp = fileChooseControl3.FilePath; //主沟道shp string argShp = fileChooseControl2.FilePath; //流速系数 //progressBar1.Visible = true; backgroundWorker1.RunWorkerAsync(new string[] { mainShp, tifPath, argShp }); } else { FormOutput.AppendLog("当前后台正在计算..."); } }
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Dictionary <int, double[]> dicArgs = new Dictionary <int, double[]>(); //获取参数值 for (int i = 1; i < 11; i++) { double[] temp = this.GetArgControl(i); if (temp != null && temp.Length == 2 && temp[0] != 0 && temp[1] != 0) { dicArgs.Add(i, temp); } } if (!backgroundWorker2.IsBusy) { FormOutput.AppendLog("开始计算..."); backgroundWorker2.RunWorkerAsync(dicArgs); } else { FormOutput.AppendLog("当前后台正在计算..."); } }
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { //F,N,R,r double?[] result = e.Result as double?[]; if (result != null && result.Length >= 4) { if (result[0].HasValue) { textBox1.Text = result[0].GetValueOrDefault(0).ToString("f3"); textBox2.Text = result[1].GetValueOrDefault(0).ToString("f3"); } if (result[2].HasValue) { textBox3.Text = result[2].GetValueOrDefault(0).ToString("f3"); } if (result[3].HasValue) { txtr1.Text = result[3].GetValueOrDefault(0).ToString("f3"); } } FormOutput.AppendLog(string.Format("计算结束,共耗时{0}秒..", (DateTime.Now - _currentTime).TotalSeconds)); FormOutput.AppendProress(false); }
/// <summary> /// 河网提取 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnGetHeWang_Click(object sender, EventArgs e) { if (!backgroundWorker1.IsBusy) { //获取河网参数 if (formRiver == null) { formRiver = new FormRiverArg(); } if (formRiver.ShowDialog() == DialogResult.OK) { RiverPath = formRiver.RiverPath; RiverThreshold = formRiver.RiverThreshold; FillPath = formRiver.FillPath; DirectionPath = formRiver.DirectionPath; AccumulationPath = formRiver.AccumulationPath; FormOutput.AppendLog("开始计算..."); _currentTime = DateTime.Now; SaveCaculateArg(); string srcPath = fileChooseControl1.FilePath; //已经计算过,直接从缓存读取 if (currentDem == srcPath) { RasterReader read = new RasterReader(srcPath); if (!string.IsNullOrEmpty(FillPath)) { DEMReader.SaveDem(read, fillGrid, null, FillPath); } if (!string.IsNullOrEmpty(DirectionPath)) { DEMReader.SaveDem(read, directionDev, null, DirectionPath); } if (!string.IsNullOrEmpty(AccumulationPath)) { DEMReader.SaveDem(read, Accumulation, null, AccumulationPath); } FormOutput.AppendLog("开始根据回流阀值提取河网.."); FormOutput.AppendLog($"当前阀值为{RiverThreshold}.."); RiverGrid = new int[Accumulation.GetLength(0), Accumulation.GetLength(1)]; for (int i = 0; i < Accumulation.GetLength(0); i++) { for (int j = 0; j < Accumulation.GetLength(1); j++) { if (Accumulation[i, j] < RiverThreshold) { RiverGrid[i, j] = -1; } else { RiverGrid[i, j] = 1; } } } DEMReader.SaveDem(read, RiverGrid, null, RiverPath); FormOutput.AppendLog("河网提取完成.."); FormOutput.AppendLog(string.Format("提取结束,共耗时{0}秒..", (DateTime.Now - _currentTime).TotalSeconds)); System.Diagnostics.Process.Start("Explorer.exe", Path.GetDirectoryName(RiverPath)); } else { backgroundWorker2.RunWorkerAsync(srcPath); } } } else { FormOutput.AppendLog("当前后台正在计算..."); } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { //bysj,byss,hchl,pmhl,Qm,p1,eps1,eps2,tc object[] args = e.Argument as object[]; BYSJResult bysj = args[0] as BYSJResult; BYSSResult byss = args[1] as BYSSResult; HCHLResult hchl = args[2] as HCHLResult; PMHLResult pmhl = args[3] as PMHLResult; //获取计算需要的参数值 //p1,Qm,eps1,sd,R,d,nd,r1,F,L1,L2,I1,I2,A1,A2,tc,eps2 StringBuilder builder = new StringBuilder(); StringBuilder logBuilder = new StringBuilder(); logBuilder.AppendLine("*********洪峰流量计算参数**********"); builder.Append(MethodName.FloodPeak); builder.Append(" "); builder.Append(args[5]); logBuilder.AppendLine("P1:" + args[5]); builder.Append(" "); builder.Append(args[4]); logBuilder.AppendLine("Qm:" + args[4]); builder.Append(" "); builder.Append(args[6]); logBuilder.AppendLine("eps1:" + args[6]); builder.Append(" "); builder.Append(bysj.Sd); logBuilder.AppendLine("Sd:" + bysj.Sd); builder.Append(" "); builder.Append(byss.R); logBuilder.AppendLine("R:" + byss.R); builder.Append(" "); builder.Append(bysj.d); logBuilder.AppendLine("d:" + bysj.d); builder.Append(" "); builder.Append(bysj.nd); logBuilder.AppendLine("nd:" + bysj.nd); builder.Append(" "); builder.Append(byss.r1); logBuilder.AppendLine("r:" + byss.r1); builder.Append(" "); builder.Append(byss.F); logBuilder.AppendLine("F:" + byss.F); builder.Append(" "); builder.Append(hchl.L1); logBuilder.AppendLine("L1:" + hchl.L1); builder.Append(" "); builder.Append(pmhl.L2); logBuilder.AppendLine("L2:" + pmhl.L2); builder.Append(" "); builder.Append(hchl.l1); logBuilder.AppendLine("I1:" + hchl.l1); builder.Append(" "); builder.Append(pmhl.l2); logBuilder.AppendLine("I2:" + pmhl.l2); builder.Append(" "); builder.Append(hchl.A1); logBuilder.AppendLine("A1:" + hchl.A1); builder.Append(" "); builder.Append(pmhl.A2); logBuilder.AppendLine("A2:" + pmhl.A2); builder.Append(" "); builder.Append(args[8]); logBuilder.AppendLine("tc:" + args[8]); builder.Append(" "); builder.Append(args[7]); logBuilder.AppendLine("eps2:" + args[7]); builder.Append(" "); builder.Append(Path.Combine(_projectForlder, ConfigNames.FloodPeak)); FormOutput.AppendLog(logBuilder.ToString()); FormOutput.AppendLog("***********************************"); RunExeHelper.RunMethod(builder.ToString()); e.Result = "1"; }
private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtQm.Text) || string.IsNullOrWhiteSpace(txtp1.Text) || string.IsNullOrWhiteSpace(txteps1.Text) || string.IsNullOrWhiteSpace(txteps2.Text) || string.IsNullOrWhiteSpace(txttc.Text)) { MsgBox.ShowInfo("请确定参数完整!"); return; } _projectForlder = Path.GetDirectoryName(_parent.ProjectModel.ProjectPath); //保存基础参数 XmlHelper.Serialize <DefaultArgModel>(new DefaultArgModel() { Qm = txtQm.Text, p1 = txtp1.Text, esp1 = txteps1.Text, esp2 = txteps2.Text, tc = txttc.Text }, Path.Combine(_projectForlder, ConfigNames.DefaultArgModel)); //根据文件夹来获取里面的参数文件 string xmlPath = Path.Combine(_projectForlder, ConfigNames.RainStormSub); //暴雨衰减赋值 BYSJResult bysj; if (File.Exists(xmlPath)) { bysj = XmlHelper.Deserialize <BYSJResult>(xmlPath); } else { MsgBox.ShowInfo("请确定参数完整!"); return; } //暴雨损失赋值 xmlPath = Path.Combine(_projectForlder, ConfigNames.RainStormLoss); BYSSResult byss; if (File.Exists(xmlPath)) { byss = XmlHelper.Deserialize <BYSSResult>(xmlPath); } else { MsgBox.ShowInfo("请确定参数完整!"); return; } //沟道汇流赋值 xmlPath = Path.Combine(_projectForlder, ConfigNames.RiverConfluence); HCHLResult hchl; if (File.Exists(xmlPath)) { hchl = XmlHelper.Deserialize <HCHLResult>(xmlPath); } else { MsgBox.ShowInfo("请确定参数完整!"); return; } //坡面汇流赋值 xmlPath = Path.Combine(_projectForlder, ConfigNames.SlopeConfluence); PMHLResult pmhl; if (File.Exists(xmlPath)) { pmhl = XmlHelper.Deserialize <PMHLResult>(xmlPath); } else { MsgBox.ShowInfo("请确定参数完整!"); return; } if (!backgroundWorker1.IsBusy) { FormOutput.AppendLog("开始计算..."); object[] args = new object[] { bysj, byss, hchl, pmhl, txtQm.Text, txtp1.Text, txteps1.Text, txteps2.Text, txttc.Text }; backgroundWorker1.RunWorkerAsync(args); } else { FormOutput.AppendLog("当前后台正在计算..."); } }
private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) { //读取高程矩阵 RasterReader read = new RasterReader(e.Argument as string); double[,] src = DEMReader.GetElevation(read); DEMReader.SaveDem(read, src, null, RiverPath); FormOutput.AppendLog("1.计算洼地"); List <MyGrid> SourceGrid = new List <MyGrid>(); MyGrid.Src = src; SourceGrid = MyGrid.GetSourceGrids(); FormOutput.AppendLog($"栅格点有{SourceGrid.Count},其中洼地点有{SourceGrid.Where(t => t.IsFill == false).Count()}"); FormOutput.AppendLog("2.开始填充洼地"); #region 指定填洼 int times = 1; while (SourceGrid.Where(t => t.IsFill == false).Count() > 0) { double[,] tempSrc = new double[src.GetLongLength(0), src.GetLongLength(1)]; foreach (var item in SourceGrid) { if (item.IsFill) { tempSrc[item.Row, item.Col] = item.ALT; } else { tempSrc[item.Row, item.Col] = item.FilledALT; } } MyGrid.Src = tempSrc; SourceGrid = MyGrid.GetSourceGrids(); FormOutput.AppendLog($"第{times}次填充洼地,栅格点有{SourceGrid.Count},其中洼地点有{SourceGrid.Where(t => t.IsFill == false).Count()}"); src = tempSrc; times++; } #endregion fillGrid = src; var ss = SourceGrid.OrderByDescending(t => t.ALT).ToList(); if (!string.IsNullOrEmpty(FillPath)) { DEMReader.SaveDem(read, fillGrid, null, FillPath); } FormOutput.AppendLog("填充洼地完成"); //计算流向 FormOutput.AppendLog("2.开始计算流向.."); FormOutput.AppendLog($"未确定流向的点有{SourceGrid.Where(t => t.IsFlat).Count()}"); directionDev = new int[src.GetLength(0), src.GetLength(1)]; int index = 0; FormOutput.AppendProress(true); foreach (var item in SourceGrid) { directionDev[item.Row, item.Col] = item.Direction; index++; FormOutput.AppendProress(index * 100 / SourceGrid.Count); } if (!string.IsNullOrEmpty(DirectionPath)) { DEMReader.SaveDem(read, directionDev, null, DirectionPath); } FormOutput.AppendLog("流向计算完成.."); FormOutput.AppendLog("3.开始计算汇流量.."); Accumulation = new int[src.GetLength(0), src.GetLength(1)]; for (int i1 = 0; i1 < src.GetLength(0); i1++) { FormOutput.AppendProress(i1 * 100 / src.GetLength(0)); for (int j1 = 0; j1 < src.GetLength(1); j1++) { int i = i1; int j = j1; bool flag = true; List <Point> caledPoint = new List <Point>(); while (flag) { //计算之后不计算,防止死循环 if (caledPoint.Where(t => t.X == i && t.Y == j).Any()) { break; } int direction = directionDev[i, j]; caledPoint.Add(new Point(i, j)); switch (direction) { case 1: Accumulation[i, j + 1]++; j = j + 1; break; case 2: Accumulation[i = 1, j + 1]++; i = i + 1; j = j + 1; break; case 4: Accumulation[i + 1, j]++; i = i + 1; break; case 8: Accumulation[i + 1, j - 1]++; i = i + 1; j = j - 1; break; case 16: Accumulation[i, j - 1]++; j = j - 1; break; case 32: Accumulation[i - 1, j - 1]++; i = i - 1; j = j - 1; break; case 64: Accumulation[i - 1, j]++; i = i - 1; break; case 128: Accumulation[i - 1, j + 1]++; i = i - 1; j = j + 1; break; default: break; } flag = direction != 0 && i < src.GetLength(0) && j < src.GetLength(1); } } } if (!string.IsNullOrEmpty(AccumulationPath)) { DEMReader.SaveDem(read, Accumulation, null, AccumulationPath); } FormOutput.AppendLog("计算汇流量完成.."); FormOutput.AppendLog("4.开始根据回流阀值提取河网.."); FormOutput.AppendLog($"当前阀值为{RiverThreshold}.."); RiverGrid = new int[src.GetLength(0), src.GetLength(1)]; for (int i = 0; i < Accumulation.GetLength(0); i++) { for (int j = 0; j < Accumulation.GetLength(1); j++) { if (Accumulation[i, j] < RiverThreshold) { RiverGrid[i, j] = -1; } else { RiverGrid[i, j] = 1; } } } DEMReader.SaveDem(read, RiverGrid, null, RiverPath); FormOutput.AppendLog("河网提取完成.."); e.Result = RiverPath; }
/// <summary> /// 用于计算shp文件中的系数平均值 /// </summary> /// <param name="shppath">shp路径</param> /// <param name="inputDemPath">tif路径</param> /// <returns></returns> public static double?ReadCoeficient(string shppath, string inputDemPath) { FormOutput.AppendLog("按规定范围裁剪栅格.."); //创建一个临时目录 string outDemPath = Path.Combine(Path.GetTempPath(), "WDEM.tif"); RasterReader raster = null; Band band = null; try { ImgCut.CutTiff(shppath, inputDemPath, outDemPath); if (File.Exists(outDemPath) == false) { FormOutput.AppendLog("裁剪失败!"); return(null); } FormOutput.AppendLog("开始读取裁剪后的栅格数据.."); raster = new RasterReader(outDemPath); int row = raster.RowCount; int col = raster.ColumnCount; // int count = raster.RasterCount; int xsize = raster.DataSet.RasterXSize; int ysize = raster.DataSet.RasterYSize; band = raster.DataSet.GetRasterBand(1); //无效值 //FormOutput.AppendLog("获取栅格数据无效值.."); double nodatavalue; int hasval; band.GetNoDataValue(out nodatavalue, out hasval); // FormOutput.AppendLog("栅格数据无效值为" + nodatavalue); double[] readData = new double[row * col]; band.ReadRaster(0, 0, xsize, ysize, readData, row, col, 0, 0); //FormOutput.AppendLog("开始整理损失指数数据.."); var res = readData.GroupBy(t => t).Select(t => new { count = t.Count(), Key = t.Key }).ToArray(); double total = 0; double totalcount = 0; foreach (var s in res) { if (s.Key != nodatavalue) { total += s.Key * s.count; totalcount += s.count; } } double R = total / totalcount; R = R / 1000; //转换?? return(R); } catch (Exception ex) { FormOutput.AppendLog("获取栅格数据异常:" + ex.Message); return(null); } finally { //销毁 if (raster != null) { band.Dispose(); raster.Dispose(); } } }