//计算污染返现点下游水系 private void button4_Click(object sender, EventArgs e) { try { if (comboBox1.Text == "") { MessageBox.Show("请输入污染发现点数据", "输入污染发现点数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (comboBox2.Text == "") { MessageBox.Show("请输入河流网络数据", "输入河流网络数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (comboBox3.Text == "") { MessageBox.Show("请选择输出污染发现点下游水系数据", "输出污染发现点下游水系数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else { IFeatureLayer pFeatureLayerPollutionpoint = CDataImport.ImportFeatureLayerFromControltext(comboBox1.Text); IFeatureLayer pFeatureLayerRivernetwork = CDataImport.ImportFeatureLayerFromControltext(comboBox2.Text); RiverDownstream riverpath = new RiverDownstream(); List <IPolyline> listlines = new List <IPolyline>(); listlines = riverpath.pollutionpointdownstreamriver(pFeatureLayerPollutionpoint, pFeatureLayerRivernetwork); SaveVector.polylinetoFeatureLayer(comboBox3.Text, listlines, pFeatureLayerRivernetwork); MessageBox.Show("处理完毕!"); } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常"); } }
//计算污染物排放的空间位置 private void button5_Click(object sender, EventArgs e) { try { if (comboBox1.Text == "") { MessageBox.Show("请输入污染源数据库数据", "输入污染源数据库数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (comboBox2.Text == "") { MessageBox.Show("请输入污染发现点上游水系数据", "输入污染源发现点上游水系数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (comboBox3.Text == "") { MessageBox.Show("请输入子流域数据", "输入子流域数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (textBox1.Text == "") { MessageBox.Show("请输入污染发现点所发生的污染类型", "输入污染发现点所发生的污染类型", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (comboBox4.Text == "") { MessageBox.Show("请输出可能排放污染物的空间位置数据", "输出可能排放污染物的空间位置数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else { //将可能已发生污染的水系合并成一个要素 IFeatureLayer pFeatureLayerline = CDataImport.ImportFeatureLayerFromControltext(comboBox2.Text); IPolyline polyline = new PolylineClass(); polyline = LineUnion(pFeatureLayerline); IGeometry pGeometry = polyline as IGeometry; //根据可能已发生的污染水系查找其子流域 IFeatureLayer pFeatureLayerpolygon = CDataImport.ImportFeatureLayerFromControltext(comboBox3.Text); List <IFeature> pFeaturelist = new List <IFeature>(); pFeaturelist = GetLineOverlapPolygon(pFeatureLayerpolygon, pGeometry); IPolygon polygon = PolygonUnion(pFeaturelist); //根据肯能已发生污染的子流域查找其可能引起的污染源的空间位置 IFeatureLayer pFeatureLayerpoint = CDataImport.ImportFeatureLayerFromControltext(comboBox1.Text); IGeometry pGeometrypolygon = polygon as IGeometry; List <IFeature> pFeatureListpoint = new List <IFeature>(); pFeatureListpoint = GetPolygonContainPoint(pFeatureLayerpoint, pGeometrypolygon, textBox1.Text); SaveVector.pointtoFeatureLayer(comboBox4.Text, pFeatureListpoint, pFeatureLayerpoint); MessageBox.Show("处理完毕!"); } } catch (Exception ex) { MessageBox.Show(ex.Message + "/n" + ex.ToString(), "异常"); } }
//Loads the level from file and sets spawn + exit positions public void LoadLevel() { LevelFile save = LevelEditor.singleton.LoadFromFile(); levelTexture = new Texture2D(0, 0); levelTexture.LoadImage(save.levelTexture); SaveVector spawn = save.spawnPosition; if (spawn != null) { Vector3 posit = Vector3.zero; posit.x = spawn.x; posit.y = spawn.y; levelEditor.spawnPoint.transform.position = posit; } SaveVector exit = save.exitPosition; if (exit != null) { Vector3 posexit = Vector3.zero; posexit.x = exit.x; posexit.y = exit.y; levelEditor.exitPoint.transform.position = posexit; } /*SaveVector eSpawn = save.enemySpawnPosition; * * if(eSpawn != null) * { * Vector3 posESpawn = Vector3.zero; * posESpawn.x = eSpawn.x; * posESpawn.y = eSpawn.y; * levelEditor.enemySpawnPoint.transform.position = posESpawn; * }*/ }
//通过第一处置点和即将污染的水系,把第一处置点下游按照应急处置空间位置相距进行切分,获得每段的中心点 //并判断这些点是否在可供选择的应急处置河段,则获得可供选择的应急处置空间位置 private void button7_Click(object sender, EventArgs e) { try { if (comboBox1.Text == "") { MessageBox.Show("请输入可供选择的首个应急处置空间位置数据", "输入可供选择的首个应急处置空间位置数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (comboBox2.Text == "") { MessageBox.Show("请输入即将污染的河流数据", "输入即将污染的河流数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (comboBox3.Text == "") { MessageBox.Show("请输入可选择应急处置河段数据", "输入可选择应急处置河段数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (textBox1.Text == "") { MessageBox.Show("请输入应急处置空间位置相距的距离", "输入应急处置空间位置相距的距离", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (comboBox6.Text == "") { MessageBox.Show("请输出应急处置空间位置的数据", "输出应急处置空间位置的数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else { IFeatureLayer pFeatureLayerSpacepoint = CDataImport.ImportFeatureLayerFromControltext(comboBox1.Text); IFeatureClass pFeatureClassSpacepoint = pFeatureLayerSpacepoint.FeatureClass; IFeatureCursor pFeatureCursorSpacepoint = pFeatureClassSpacepoint.Search(null, false); IFeature pFeatureSpacepoint = pFeatureCursorSpacepoint.NextFeature(); IPoint pFirstpoint = new PointClass(); while (pFeatureSpacepoint != null) { pFirstpoint = pFeatureSpacepoint.Shape as IPoint; pFeatureSpacepoint = pFeatureCursorSpacepoint.NextFeature(); } //根据应急处置点最短的距离,获取即将污染河流分段的各个点 double distance = Convert.ToDouble(textBox1.Text); List <IPoint> pointlist = new List <IPoint>(); IFeatureLayer pFeatureLayerPollutionRiver = CDataImport.ImportFeatureLayerFromControltext(comboBox2.Text); IFeatureClass pFeatureClassPollutionRiver = pFeatureLayerPollutionRiver.FeatureClass; IFeatureCursor pFeatureCursorPollutionRiver = pFeatureClassPollutionRiver.Search(null, false); IFeature pFeaturePollutionRiver = pFeatureCursorPollutionRiver.NextFeature(); while (pFeaturePollutionRiver != null) { IPolyline pLine = new PolylineClass(); pLine = pFeaturePollutionRiver.Shape as IPolyline; pLine = GetPointSplitAtPoint(pLine, pFirstpoint); IPolyline retureline = new PolylineClass(); IPoint returepoint = new PointClass(); for (double i = distance; i < pLine.Length;) { GetPointSplitAtDistance(pLine, i, ref retureline, ref returepoint); pLine = retureline; pointlist.Add(returepoint); } pFeaturePollutionRiver = pFeatureCursorPollutionRiver.NextFeature(); } //SaveVector.pointtoFeatureLayer(comboBox6.Text, pointlist, pFeatureLayerPollutionRiver); //根据可供选择的河段和即将污染的河流分段的点,获取可供选择的应急处置空间位置点 List <IPoint> pointresultlist = new List <IPoint>(); IFeatureLayer pFeatureLayerPossibleSelectionRiver = CDataImport.ImportFeatureLayerFromControltext(comboBox3.Text); for (int j = 0; j < pointlist.Count; j++) { if (LineContainPoint(pointlist[j], pFeatureLayerPossibleSelectionRiver) == true) { pointresultlist.Add(pointlist[j]); } } SaveVector.pointtoFeatureLayer(comboBox6.Text, pointresultlist, pFeatureLayerPossibleSelectionRiver); MessageBox.Show("程序运行结束!"); } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常"); } }
//进行计算时间上可行的第一个空间位置 private void button4_Click(object sender, EventArgs e) { try { if (comboBox1.Text == "") { MessageBox.Show("请输入应急资源仓库数据", "输入应急资源仓库数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (comboBox2.Text == "") { MessageBox.Show("请输入道路网络数据", "输入道路网络数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (comboBox3.Text == "") { MessageBox.Show("请输入污染物扩散模拟过程数据", "输入污染物扩散模拟过程数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (textBox1.Text == "") { MessageBox.Show("请输入应急处置工程建设时间(单位:分钟):", "输入应急处置工程建设时间(单位:分钟):", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (comboBox4.Text == "") { MessageBox.Show("请输出可供选择首个应急处置空间位置", "输出可供选择首个应急处置空间位置", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else { int row = 0, column = 0; double X = 0.0, Y = 0.0; double pixelvalue = 0.0; IRasterLayer pRasterLayer = CDataImport.ImportRasterLayerFromControltext(comboBox3.Text); IFeatureLayer pFeatureLayerDepot = CDataImport.ImportFeatureLayerFromControltext(comboBox1.Text); IFeatureLayer pFeatureLayerroad = CDataImport.ImportFeatureLayerFromControltext(comboBox2.Text); //获取污染物模拟河流的外包络线 IRaster pRaster = pRasterLayer.Raster; IRasterProps pRasterprops = pRaster as IRasterProps; IEnvelope pEnvelope = pRasterprops.Extent; IPoint p1 = new PointClass(); IPoint p2 = new PointClass(); IPoint p3 = new PointClass(); IPoint p4 = new PointClass(); p1 = pEnvelope.UpperLeft; p2 = pEnvelope.LowerLeft; p3 = pEnvelope.LowerRight; p4 = pEnvelope.UpperRight; IPointCollection pointCollection = new PolygonClass(); object missing = Type.Missing; pointCollection.AddPoint(p1, ref missing, ref missing); pointCollection.AddPoint(p2, ref missing, ref missing); pointCollection.AddPoint(p3, ref missing, ref missing); pointCollection.AddPoint(p4, ref missing, ref missing); pointCollection.AddPoint(p1, ref missing, ref missing); IPolygon polygon = (IPolygon)pointCollection; IGeometry pGeometry = new PolygonClass(); pGeometry = polygon as IGeometry; //获取应急资源仓库到达各个节点的最短路径 List <IFeature> listFeature = new List <IFeature>(); listFeature = GetPolygonFeatureList(pFeatureLayerroad, pGeometry); RoutePlanResult startNoderesult = null, EndNoderesult = null, minStartNodeResult = null, minEndNodeResult = null; DijkstraDepotToAllNodeMethod path = new DijkstraDepotToAllNodeMethod(); path.InitializationRoadNetwork(pFeatureLayerDepot); List <PlanCourse> resultplancourse = path.DepotToAllNode(); RasterManagement.GetRasterCount(pRasterLayer, ref row, ref column); double[] desttime = new double[2]; int sign = 0; //IFeature pFeature = null; string strStartID = null, strEndID = null; double time = 0.0; double returnX = 0.0, returnY = 0.0; double pFrompointToOutpointLength = 0.0, pOutpointToEndpointLength = 0.0; IPolyline polyline = new PolylineClass(); //对污染物模拟栅格从[0,0]进行循环,选取从时间上作为应急处置空间位置的可行性的点 for (int i = 0; i < row; i++) { for (int j = 0; j < column; j++) { pixelvalue = Convert.ToDouble(RasterManagement.GetPixelValue(pRasterLayer, 0, j, i)); if (pixelvalue != 0) { IFeature pFeature = null; RasterManagement.NumbercovertXY(pRasterLayer, ref X, ref Y, j, i); IPoint point = new PointClass(); point.PutCoords(X, Y); IPoint ppoint = new PointClass(); GetMindistanceandpoint(point, listFeature, ref returnX, ref returnY, ref pFeature, ref pFrompointToOutpointLength); ppoint.PutCoords(returnX, returnY); strStartID = Convert.ToString(pFeature.get_Value(pFeature.Fields.FindField("StartNodeI"))); strEndID = Convert.ToString(pFeature.get_Value(pFeature.Fields.FindField("EndNodeID"))); time = Convert.ToDouble(pFeature.get_Value(pFeature.Fields.FindField("Minutes"))); polyline = pFeature.Shape as IPolyline; pOutpointToEndpointLength = polyline.Length - pFrompointToOutpointLength; //获取应急仓库到达应急处置点最短时间的点 minStartNodeResult = startNoderesult = RoutePlanner.GetResult(resultplancourse[0], strStartID); minEndNodeResult = EndNoderesult = RoutePlanner.GetResult(resultplancourse[0], strEndID); for (int m = 1; m < resultplancourse.Count; m++) { startNoderesult = RoutePlanner.GetResult(resultplancourse[m], strStartID); EndNoderesult = RoutePlanner.GetResult(resultplancourse[m], strEndID); if (minStartNodeResult.WeightValues > startNoderesult.WeightValues) { minStartNodeResult = startNoderesult; } if (minEndNodeResult.WeightValues > EndNoderesult.WeightValues) { minEndNodeResult = EndNoderesult; } } desttime[0] = time * (pFrompointToOutpointLength / (pFrompointToOutpointLength + pOutpointToEndpointLength)); desttime[1] = time - desttime[0]; //判断污染物到达该应急处置空间位置的时间是否大于应急资源调度时间与工程措施建设时间之和 if (minStartNodeResult.WeightValues + desttime[0] > minEndNodeResult.WeightValues + desttime[1]) { if ((minEndNodeResult.WeightValues + desttime[1] + Convert.ToDouble(textBox1.Text)) < pixelvalue) { List <IPoint> pointlist = new List <IPoint>(); pointlist.Add(point); SaveVector.pointtoFeatureLayer(comboBox4.Text, pointlist, pFeatureLayerDepot); sign = 1; break; } } else { if ((minStartNodeResult.WeightValues + desttime[0] + Convert.ToDouble(textBox1.Text)) < pixelvalue) { List <IPoint> pointlist = new List <IPoint>(); pointlist.Add(point); SaveVector.pointtoFeatureLayer(comboBox4.Text, pointlist, pFeatureLayerDepot); sign = 1; break; } } } } if (sign == 1) { break; } } MessageBox.Show("处理完毕!"); } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常"); } }
private void button6_Click(object sender, EventArgs e) { try { //保存应急处置空间位置应急资源调度后 IFeatureClass pFeatureClassDeptResult = pFeatureLayerDept.FeatureClass; IQueryFilter pQueryFilterDeptResult = new QueryFilterClass(); pQueryFilterDeptResult.WhereClause = "FID=" + Convert.ToString(Convert.ToInt32(comboBox4.Text) - 1); IFeatureCursor pFeatureCursorDeptResult = pFeatureClassDeptResult.Update(pQueryFilterDeptResult, false); IFeature pFeatureDeptResult = pFeatureCursorDeptResult.NextFeature(); //保存应急处置空间位置的图层 List <IPoint> DeptpointList = new List <IPoint>(); DeptpointList.Add(pFeatureDeptResult.Shape as IPoint); SaveVector.pointtoFeatureLayer(comboBox6.Text, DeptpointList, pFeatureLayerDept); //保存应急处置空间位置应急资源调度后 while (pFeatureDeptResult != null) { for (int i = 0; i < pEmergencyDeptResource.Count; i++) { pFeatureDeptResult.set_Value(pFeatureDeptResult.Fields.FindField(pEmergencyDeptResource[i].EmergencyDemandResourceName), pEmergencyDeptResource[i].EmergencyDemandResourceNumber); } pFeatureCursorDeptResult.UpdateFeature(pFeatureDeptResult); pFeatureDeptResult = pFeatureCursorDeptResult.NextFeature(); } //保存应急资源仓库应急资源数量 IFeatureClass pFeatureClassDepotResult = pFeatureLayerDepot.FeatureClass; //定义应急资源仓库点的List List <IPoint> DepotpointList = new List <IPoint>(); for (int j = 0; j < pEmergencyDepotResource.Count; j++) { if (pEmergencyDepotResource[j].EmergencyDepotBool == true) { IQueryFilter pQueryFilterDepotResult = new QueryFilterClass(); pQueryFilterDepotResult.WhereClause = "Name=" + "'" + Convert.ToString(pEmergencyDepotResource[j].DepotName) + "'"; IFeatureCursor pFeatureCursorDepotResult = pFeatureClassDepotResult.Update(pQueryFilterDepotResult, false); IFeature pFeauteDepotResult = pFeatureCursorDepotResult.NextFeature(); //将调度出的应急资源仓库点加载到List中 DepotpointList.Add(pFeauteDepotResult.Shape as IPoint); while (pFeauteDepotResult != null) { for (int k = 0; k < pEmergencyDepotResource[j].EmergencyVarietyName.Length; k++) { pFeauteDepotResult.set_Value(pFeauteDepotResult.Fields.FindField(pEmergencyDepotResource[j].EmergencyVarietyName[k]), pEmergencyDepotResource[j].EmergencyVarietyNameNumber[k]); } pFeatureCursorDepotResult.UpdateFeature(pFeauteDepotResult); pFeauteDepotResult = pFeatureCursorDepotResult.NextFeature(); } } } //保存应急资源仓库数据 SaveVector.pointtoFeatureLayer(comboBox5.Text, DepotpointList, pFeatureLayerDepot); MessageBox.Show("运行结束!"); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常"); } }