diff --git a/FrmAccessoriesgather.cs b/FrmAccessoriesgather.cs index 5187a3a..36c014e 100644 --- a/FrmAccessoriesgather.cs +++ b/FrmAccessoriesgather.cs @@ -17,7 +17,8 @@ { GSOGlobeControl globeControl1; List instrumenLayerNames; - string[] accessStrs = null; + //string[] accessStrs = null; + Dictionary dic = new Dictionary(); static FrmAccessoriesgather frm; public static void ShowForm(GSOGlobeControl globeControl, List pipeLayers, int visibleId) @@ -46,9 +47,7 @@ buttonX9.Visible = false; buttonX8.Visible = true; buttonX8.Location = buttonX9.Location; - } - if (visibleId == 1) - { + }else{ buttonX8.Visible = false; buttonX9.Visible = true; } @@ -67,22 +66,7 @@ clbPipeLine2.Items.Add(instrumenLayerNames[i]); } } - //if (Utility.listPipelineType != null) - //{ - // List list = Utility.listPipelineType; - // string temptype = ""; - - // for (int i = 0; i < list.Count; i++) - // { - // PipelineType pipelineType = Utility.listPipelineType[i]; - // if (temptype != pipelineType.type) - // { - // //clbPipeLine.Items.Add(pipelineType.type); - // clbPipeLine2.Items.Add(pipelineType.type); - // temptype = pipelineType.type; - // } - // } - //} + } @@ -167,14 +151,8 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); + } } /// @@ -189,118 +167,74 @@ clbPipeLine.SetItemChecked(i, false); } } - Dictionary dic = new Dictionary(); - private void pipeDiameterStatis(GSOGeoPolygon3D polygon) - { - try - { - dic = new Dictionary(); - dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) - { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - int ncount = 0; - ncount = feats.Length; - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["数量"].Value = ncount; - dic.Add(layer.Caption, ncount); - } - } - else - { - MessageBox.Show("请选择图层!"); - } + + //private void pipeDiameterStatis(GSOGeoPolygon3D polygon) + //{ + // try + // { + // dic = new Dictionary(); + // dataGridViewX1.Rows.Clear(); + // if (clbPipeLine.CheckedItems.Count > 0) + // { + // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) + // { + // GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + // GSOFeatureLayer flayer = layer as GSOFeatureLayer; + // GSOFeatures feats = new GSOFeatures(); + // if (polygon == null) + // feats = flayer.GetAllFeatures(); + // else + // feats = flayer.FindFeaturesInPolygon(polygon, false); + // int ncount = 0; + // ncount = feats.Length; + // DataGridViewRow row = new DataGridViewRow(); + // int index = dataGridViewX1.Rows.Add(row); + // row = dataGridViewX1.Rows[index]; + // row.Cells["图层名称"].Value = layer.Caption; + // row.Cells["数量"].Value = ncount; + // dic.Add(layer.Caption, ncount); + // } + // } + // else + // { + // MessageBox.Show("请选择图层!"); + // } - showPipeWidget(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - LogError.PublishError(ex); - } - } + // showPipeWidget(); + // } + // catch (Exception ex) + // { + // MessageBox.Show(ex.Message); + // LogError.PublishError(ex); + // } + //} private void pipeDiameterStatisNew(GSOGeoPolygon3D polygon, string layertype) { try { - //根据管线类型找到其附属物 - accessStrs = Utility.getAccStrsByLayer(layertype); - if (accessStrs != null) - { + FeatureStatisticsService featureService = new FeatureStatisticsService(); + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(layertype); + List accessoriesResult = featureService.groupAccessories(polygon, layer); - dic = new Dictionary(); - dataGridViewX1.Rows.Clear(); - - int ncount = 0; - string accessValue = ""; - - //if (clbPipeLine.CheckedItems.Count > 0) - //{ - // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - // { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine2.Text); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - for (int j = 0; j < accessStrs.Length; j++) - { - if (polygon == null) - { - feats = flayer.GetFeatureByFieldValue("附属物名称", accessStrs[j], true); - ncount = feats.Length; - } - else - { - feats = flayer.FindFeaturesInPolygon(polygon, false); - - GSOFeatures newfeats = flayer.FindFeaturesInPolygon(polygon, false); - newfeats.RemoveAll(); - //过滤 - for (int n= 0; n < feats.Length; n++) - { - GSOFeature feat = feats[n]; - - if (feat.GetFieldAsString("附属物名称").Contains(accessStrs[j])) - { - newfeats.Add(feat); - } - } - ncount = newfeats.Length; - } - - //accessValue = clbPipeLine.CheckedItems[i].ToString() + accessStrs[j]; - accessValue = accessStrs[j]; - - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = accessValue;// layer.Caption; - row.Cells["数量"].Value = ncount; - dic.Add(accessValue, ncount); - } - // } - //} - //else - //{ - // MessageBox.Show("请选择图层!"); - //} - - showPipeWidget(); - } - else + if (accessoriesResult == null || accessoriesResult.Count == 0) { MessageBox.Show("该图层没有附属物"); } + dataGridViewX1.Rows.Clear(); + dic.Clear(); + foreach (FeaturesClassfyResult accessoryResult in accessoriesResult) + { + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + string layerName = accessoryResult.layerName; + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layerName;// layer.Caption; + row.Cells["数量"].Value = accessoryResult.ncount; + dic.Add(layerName, accessoryResult.ncount); + + } + showPipeWidget(); + } catch (Exception ex) { diff --git a/FrmAccessoriesgather.cs b/FrmAccessoriesgather.cs index 5187a3a..36c014e 100644 --- a/FrmAccessoriesgather.cs +++ b/FrmAccessoriesgather.cs @@ -17,7 +17,8 @@ { GSOGlobeControl globeControl1; List instrumenLayerNames; - string[] accessStrs = null; + //string[] accessStrs = null; + Dictionary dic = new Dictionary(); static FrmAccessoriesgather frm; public static void ShowForm(GSOGlobeControl globeControl, List pipeLayers, int visibleId) @@ -46,9 +47,7 @@ buttonX9.Visible = false; buttonX8.Visible = true; buttonX8.Location = buttonX9.Location; - } - if (visibleId == 1) - { + }else{ buttonX8.Visible = false; buttonX9.Visible = true; } @@ -67,22 +66,7 @@ clbPipeLine2.Items.Add(instrumenLayerNames[i]); } } - //if (Utility.listPipelineType != null) - //{ - // List list = Utility.listPipelineType; - // string temptype = ""; - - // for (int i = 0; i < list.Count; i++) - // { - // PipelineType pipelineType = Utility.listPipelineType[i]; - // if (temptype != pipelineType.type) - // { - // //clbPipeLine.Items.Add(pipelineType.type); - // clbPipeLine2.Items.Add(pipelineType.type); - // temptype = pipelineType.type; - // } - // } - //} + } @@ -167,14 +151,8 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); + } } /// @@ -189,118 +167,74 @@ clbPipeLine.SetItemChecked(i, false); } } - Dictionary dic = new Dictionary(); - private void pipeDiameterStatis(GSOGeoPolygon3D polygon) - { - try - { - dic = new Dictionary(); - dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) - { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - int ncount = 0; - ncount = feats.Length; - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["数量"].Value = ncount; - dic.Add(layer.Caption, ncount); - } - } - else - { - MessageBox.Show("请选择图层!"); - } + + //private void pipeDiameterStatis(GSOGeoPolygon3D polygon) + //{ + // try + // { + // dic = new Dictionary(); + // dataGridViewX1.Rows.Clear(); + // if (clbPipeLine.CheckedItems.Count > 0) + // { + // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) + // { + // GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + // GSOFeatureLayer flayer = layer as GSOFeatureLayer; + // GSOFeatures feats = new GSOFeatures(); + // if (polygon == null) + // feats = flayer.GetAllFeatures(); + // else + // feats = flayer.FindFeaturesInPolygon(polygon, false); + // int ncount = 0; + // ncount = feats.Length; + // DataGridViewRow row = new DataGridViewRow(); + // int index = dataGridViewX1.Rows.Add(row); + // row = dataGridViewX1.Rows[index]; + // row.Cells["图层名称"].Value = layer.Caption; + // row.Cells["数量"].Value = ncount; + // dic.Add(layer.Caption, ncount); + // } + // } + // else + // { + // MessageBox.Show("请选择图层!"); + // } - showPipeWidget(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - LogError.PublishError(ex); - } - } + // showPipeWidget(); + // } + // catch (Exception ex) + // { + // MessageBox.Show(ex.Message); + // LogError.PublishError(ex); + // } + //} private void pipeDiameterStatisNew(GSOGeoPolygon3D polygon, string layertype) { try { - //根据管线类型找到其附属物 - accessStrs = Utility.getAccStrsByLayer(layertype); - if (accessStrs != null) - { + FeatureStatisticsService featureService = new FeatureStatisticsService(); + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(layertype); + List accessoriesResult = featureService.groupAccessories(polygon, layer); - dic = new Dictionary(); - dataGridViewX1.Rows.Clear(); - - int ncount = 0; - string accessValue = ""; - - //if (clbPipeLine.CheckedItems.Count > 0) - //{ - // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - // { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine2.Text); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - for (int j = 0; j < accessStrs.Length; j++) - { - if (polygon == null) - { - feats = flayer.GetFeatureByFieldValue("附属物名称", accessStrs[j], true); - ncount = feats.Length; - } - else - { - feats = flayer.FindFeaturesInPolygon(polygon, false); - - GSOFeatures newfeats = flayer.FindFeaturesInPolygon(polygon, false); - newfeats.RemoveAll(); - //过滤 - for (int n= 0; n < feats.Length; n++) - { - GSOFeature feat = feats[n]; - - if (feat.GetFieldAsString("附属物名称").Contains(accessStrs[j])) - { - newfeats.Add(feat); - } - } - ncount = newfeats.Length; - } - - //accessValue = clbPipeLine.CheckedItems[i].ToString() + accessStrs[j]; - accessValue = accessStrs[j]; - - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = accessValue;// layer.Caption; - row.Cells["数量"].Value = ncount; - dic.Add(accessValue, ncount); - } - // } - //} - //else - //{ - // MessageBox.Show("请选择图层!"); - //} - - showPipeWidget(); - } - else + if (accessoriesResult == null || accessoriesResult.Count == 0) { MessageBox.Show("该图层没有附属物"); } + dataGridViewX1.Rows.Clear(); + dic.Clear(); + foreach (FeaturesClassfyResult accessoryResult in accessoriesResult) + { + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + string layerName = accessoryResult.layerName; + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layerName;// layer.Caption; + row.Cells["数量"].Value = accessoryResult.ncount; + dic.Add(layerName, accessoryResult.ncount); + + } + showPipeWidget(); + } catch (Exception ex) { diff --git a/FrmpipeDeepstatis.cs b/FrmpipeDeepstatis.cs index 607ea65..879801a 100644 --- a/FrmpipeDeepstatis.cs +++ b/FrmpipeDeepstatis.cs @@ -19,19 +19,17 @@ List pipeLayerNames; static FrmpipeDeepstatis frm; + Dictionary dic = new Dictionary(); + public static void ShowForm(GSOGlobeControl globeControl, List pipeLayers, int visibleId) { if (frm == null) { frm = new FrmpipeDeepstatis(globeControl, pipeLayers, visibleId); frm.Show(globeControl.Parent); - } - else + }else if (frm.WindowState == FormWindowState.Minimized) { - if (frm.WindowState == FormWindowState.Minimized) - { - frm.WindowState = FormWindowState.Normal; - } + frm.WindowState = FormWindowState.Normal; } } @@ -45,8 +43,7 @@ buttonX9.Visible = false; buttonX8.Visible = true; buttonX8.Location = buttonX9.Location; - } - if (visibleId == 1) + }else if (visibleId == 1) { buttonX8.Visible = false; buttonX9.Visible = true; @@ -59,50 +56,47 @@ /// private void buttonX5_Click(object sender, EventArgs e) { - if (dataGridViewX2.SelectedCells.Count > 0) + if (dataGridViewX2.SelectedCells.Count == 0 || lstpipeRadius.SelectedItem == null) return; + + DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; + + if (row.Cells["上限"].Value == null) { - DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; - if (lstpipeRadius.SelectedItem != null) + row.Cells["下限"].Value = lstpipeRadius.SelectedItem.ToString(); + } + else + { + double downRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); + double upRadius = Convert.ToDouble(row.Cells["上限"].Value); + if (upRadius >= downRadius) { - if (row.Cells["上限"].Value == null) - { - row.Cells["下限"].Value = lstpipeRadius.SelectedItem.ToString(); - } - else - { - double downRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); - double upRadius = Convert.ToDouble(row.Cells["上限"].Value); - if (upRadius >= downRadius) - { - row.Cells["下限"].Value = downRadius.ToString(); - } - } + row.Cells["下限"].Value = downRadius.ToString(); } } - } + + } + //上限值设置 private void buttonX4_Click(object sender, EventArgs e) { - if (dataGridViewX2.SelectedCells.Count > 0) + if (dataGridViewX2.SelectedCells.Count == 0 || lstpipeRadius.SelectedItem == null) return; + + DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; + + if (row.Cells["下限"].Value != null && row.Cells["下限"].Value.ToString() != "") { - DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; - if (lstpipeRadius.SelectedItem != null) + double downRadius = Convert.ToDouble(row.Cells["下限"].Value); + double upRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); + if (upRadius >= downRadius) { - if (row.Cells["下限"].Value != null && row.Cells["下限"].Value.ToString() != "") - { - double downRadius = Convert.ToDouble(row.Cells["下限"].Value); - double upRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); - if (upRadius >= downRadius) - { - row.Cells["上限"].Value = upRadius.ToString(); - } - } - else - { - row.Cells["上限"].Value = lstpipeRadius.SelectedItem.ToString(); - } + row.Cells["上限"].Value = upRadius.ToString(); } } + else + { + row.Cells["上限"].Value = lstpipeRadius.SelectedItem.ToString(); + } + } /// /// 添加行按钮事件处理 @@ -128,7 +122,7 @@ dataGridViewX2.Rows.Remove(row); } } - Dictionary dic = new Dictionary(); + /// /// 给表格绑定数据 /// @@ -137,90 +131,121 @@ { try { - dic = new Dictionary(); + dic.Clear() ; dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) + FeatureStatisticsService service = new FeatureStatisticsService(); + for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) { - if (dataGridViewX2.Rows.Count > 0) - { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - for (int j = 0; j < dataGridViewX2.Rows.Count; j++) - { - double totalLength = 0.00; - int ncount = 0; - for (int m = 0; m < feats.Length; m++) - { - GSOFeature feat = feats[m]; - float radius = feat.GetFieldAsFloat("起始埋深"); - bool upCompare = true; - bool downCompare = true; - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["下限"].Value.ToString() != "") - { - if (radius >= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["下限"].Value)) - { - downCompare = true; - } - else - downCompare = false; - } - } - if (dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["上限"].Value.ToString() != "") - { - if (radius <= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["上限"].Value)) - { - upCompare = true; - } - else - upCompare = false; - } - } - if (upCompare && downCompare) - { - GSOGeoPolyline3D line = feat.Geometry as GSOGeoPolyline3D; - double length = line.GetSpaceLength(true, 6378137); - totalLength += length; - ncount += 1; - } - } - } - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["埋深范围"].Value = dataGridViewX2.Rows[j].Cells["下限"].Value + "-" + dataGridViewX2.Rows[j].Cells["上限"].Value; - row.Cells["条数"].Value = ncount; - row.Cells["总长度"].Value =Math.Round(totalLength,2); - dic.Add(layer.Caption + "," + row.Cells["埋深范围"].Value.ToString()+","+row.Cells["总长度"].Value.ToString(), ncount); - } - } - } - } - else + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + for (int j = 0; j < dataGridViewX2.Rows.Count; j++) { - MessageBox.Show("请添加分段!"); + object tempUp = dataGridViewX2.Rows[j].Cells["上限"].Value; + double? upLimit = null; + if (tempUp != null) upLimit = Convert.ToDouble(tempUp); + + object tempDown = dataGridViewX2.Rows[j].Cells["下限"].Value; + double? downLimit = null; + if (tempDown != null) downLimit = Convert.ToDouble(tempDown); + //Double downLimit = Convert.ToDouble(dataGridViewX2.Rows[j].Cells["下限"].Value); + if (upLimit == null && downLimit == null) continue;//空行过滤 + //获取符合条件的管线 + FeaturesClassfyResult result = service.getPipesInfoByValueSection(polygon, layer, downLimit, upLimit, "起始埋深"); + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layer.Caption; + row.Cells["埋深范围"].Value = result.groupFieldValue; + row.Cells["条数"].Value = result.ncount; + row.Cells["总长度"].Value = Math.Round(result.sum, 2); + dic.Add(layer.Caption + "," + row.Cells["埋深范围"].Value.ToString() + "," + row.Cells["总长度"].Value.ToString(), result.ncount); + + } } - else - { - MessageBox.Show("请选择图层!"); - } + + //if (clbPipeLine.CheckedItems.Count > 0) + //{ + // if (dataGridViewX2.Rows.Count > 0) + // { + // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) + // { + // GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + // GSOFeatureLayer flayer = layer as GSOFeatureLayer; + // GSOFeatures feats = new GSOFeatures(); + // if (polygon == null) + // feats = flayer.GetAllFeatures(); + // else + // feats = flayer.FindFeaturesInPolygon(polygon, false); + // for (int j = 0; j < dataGridViewX2.Rows.Count; j++) + // { + // double totalLength = 0.00; + // int ncount = 0; + // for (int m = 0; m < feats.Length; m++) + // { + // GSOFeature feat = feats[m]; + // float radius = feat.GetFieldAsFloat("起始埋深"); + // bool upCompare = true; + // bool downCompare = true; + // if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) + // { + // if (dataGridViewX2.Rows[j].Cells["下限"].Value != null) + // { + // if (dataGridViewX2.Rows[j].Cells["下限"].Value.ToString() != "") + // { + // if (radius >= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["下限"].Value)) + // { + // downCompare = true; + // } + // else + // downCompare = false; + // } + // } + // if (dataGridViewX2.Rows[j].Cells["上限"].Value != null) + // { + // if (dataGridViewX2.Rows[j].Cells["上限"].Value.ToString() != "") + // { + // if (radius <= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["上限"].Value)) + // { + // upCompare = true; + // } + // else + // upCompare = false; + // } + // } + // if (upCompare && downCompare) + // { + // GSOGeoPolyline3D line = feat.Geometry as GSOGeoPolyline3D; + // double length = line.GetSpaceLength(true, 6378137); + // totalLength += length; + // ncount += 1; + // } + // } + // } + // if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) + // { + // DataGridViewRow row = new DataGridViewRow(); + // int index = dataGridViewX1.Rows.Add(row); + // row = dataGridViewX1.Rows[index]; + // row.Cells["图层名称"].Value = layer.Caption; + // row.Cells["埋深范围"].Value = dataGridViewX2.Rows[j].Cells["下限"].Value + "-" + dataGridViewX2.Rows[j].Cells["上限"].Value; + // row.Cells["条数"].Value = ncount; + // row.Cells["总长度"].Value =Math.Round(totalLength,2); + + // dic.Add(layer.Caption + "," + row.Cells["埋深范围"].Value.ToString()+","+row.Cells["总长度"].Value.ToString(), ncount); + // } + // } + // } + // } + // else + // { + // MessageBox.Show("请添加分段!"); + // } + //} + //else + //{ + // MessageBox.Show("请选择图层!"); + //} showPipeWidget(); } catch (Exception ex) @@ -234,92 +259,7 @@ /// private void showPipeWidget() { - /* - if (chart1.Series.Count > 0) - { - chart1.Series.Clear(); - } - if (chart1.Legends.Count > 0) - { - chart1.Legends.Clear(); - } - - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - chart1.Series.Add(clbPipeLine.CheckedItems[i].ToString()); - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - if (layer != null && layer is GSOFeatureLayer) - { - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures features = flayer.GetAllFeatures(); - if (features.Length > 0) - { - if (features[0] != null && features[0].Geometry != null && features[0].Geometry.Type == EnumGeometryType.GeoPolyline3D) - { - GSOGeoPolyline3D p3d = features[0].Geometry as GSOGeoPolyline3D; - if (p3d.Style != null && p3d.Style is GSOPipeLineStyle3D) - { - GSOPipeLineStyle3D ps3d = p3d.Style as GSOPipeLineStyle3D; - chart1.Series[i].Color = ps3d.LineColor; - } - } - } - } - chart1.Legends.Add(clbPipeLine.CheckedItems[i].ToString()); - chart1.Legends[i].Docking = Docking.Top; - - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].IsTextAutoFit = true; - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].LegendStyle = LegendStyle.Table; - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].DockedToChartArea = "ChartArea1"; - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].BackColor = Color.Transparent; - chart1.ChartAreas["ChartArea1"].AxisY.IsLabelAutoFit = false; - - } - - // Set axis title - chart1.ChartAreas["ChartArea1"].AxisX.Title = "埋深范围(米)"; - chart1.ChartAreas["ChartArea1"].AxisY.Title = "管线数量"; - chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; - LabelStyle labeStyleAxisX = new LabelStyle(); - labeStyleAxisX.Angle = -45; - labeStyleAxisX.Enabled = true; - chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle = labeStyleAxisX; - - Dictionary dic1 = new Dictionary(); - List dicLength = new List(); - for (int j = 0; j < chart1.Series.Count; j++) - { - dic1 = new Dictionary(); - dicLength = new List(); - foreach (string key in dic.Keys) - { - if (key.Contains(chart1.Series[j].Name)) - { - dic1.Add(key.Split(',')[1].ToString(), dic[key]); - dicLength.Add(key.Split(',')[2].ToString()); - } - } - chart1.Series[j].ChartType = SeriesChartType.Column; - - chart1.Series[j]["DrawingStyle"] = "Cylinder"; - - //chart1.Series[j].IsValueShownAsLabel = true; - - chart1.Series[j].Points.DataBindXY(dic1.Keys, dic1.Values); - for (int m = 0; m < dic1.Values.Count; m++) - { - if (chart1.Series[j].Points[m].YValues[0].ToString() != "0") - { - chart1.Series[j].Points[m].Label = chart1.Series[j].Points[m].YValues[0].ToString(); - - } - if (dicLength[m] != "0") - { - chart1.Series[j].Points[m].ToolTip ="长度:"+dicLength[m]; - } - } - } - * */ + chart1.Series.Clear(); chart1.Series.Add("管线"); @@ -367,19 +307,29 @@ /// void globeControl1_TrackPolygonEndEvent(object sender, TrackPolygonEndEventArgs e) { - if (e.Polygon != null) + if (clbPipeLine.CheckedItems.Count == 0) { - GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; - polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; - GSOFeature feature = new GSOFeature(); - feature.Geometry = polygon; - feature.Name = "trackPolygon"; - globeControl1.Globe.MemoryLayer.AddFeature(feature); - globeControl1.Globe.ClearLastTrackPolygon(); - globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(e.Polygon); + MessageBox.Show("请选择图层"); + return; } + if (dataGridViewX2.Rows.Count == 0) + { + MessageBox.Show("请添加分段"); + return; + } + if (e.Polygon == null) return; + + GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; + polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; + GSOFeature feature = new GSOFeature(); + feature.Geometry = polygon; + feature.Name = "trackPolygon"; + globeControl1.Globe.MemoryLayer.AddFeature(feature); + globeControl1.Globe.ClearLastTrackPolygon(); + globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(e.Polygon); + } /// /// 全选 @@ -402,14 +352,8 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); + } } /// @@ -431,21 +375,16 @@ /// private void buttonX8_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - if (dataGridViewX2.Rows.Count > 0) - { - pipeDiameterStatis(null); - } - else - { - MessageBox.Show("请添加分段"); - } - } - else - { + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层"); - } + return; + } + if (dataGridViewX2.Rows.Count == 0) + { + MessageBox.Show("请添加分段"); + return; + } + pipeDiameterStatis(null); } /// /// 绘制区域分段统计 @@ -454,24 +393,21 @@ /// private void buttonX9_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - if (dataGridViewX2.Rows.Count > 0) - { - Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); - globeControl1.Globe.Action = EnumAction3D.TrackPolygon; - globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; - globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - } - else - { - MessageBox.Show("请添加分段"); - } - } - else + + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层"); + return; } + if (dataGridViewX2.Rows.Count == 0) + { + MessageBox.Show("请添加分段"); + return; + } + Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); + globeControl1.Globe.Action = EnumAction3D.TrackPolygon; + globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; + globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); } diff --git a/FrmAccessoriesgather.cs b/FrmAccessoriesgather.cs index 5187a3a..36c014e 100644 --- a/FrmAccessoriesgather.cs +++ b/FrmAccessoriesgather.cs @@ -17,7 +17,8 @@ { GSOGlobeControl globeControl1; List instrumenLayerNames; - string[] accessStrs = null; + //string[] accessStrs = null; + Dictionary dic = new Dictionary(); static FrmAccessoriesgather frm; public static void ShowForm(GSOGlobeControl globeControl, List pipeLayers, int visibleId) @@ -46,9 +47,7 @@ buttonX9.Visible = false; buttonX8.Visible = true; buttonX8.Location = buttonX9.Location; - } - if (visibleId == 1) - { + }else{ buttonX8.Visible = false; buttonX9.Visible = true; } @@ -67,22 +66,7 @@ clbPipeLine2.Items.Add(instrumenLayerNames[i]); } } - //if (Utility.listPipelineType != null) - //{ - // List list = Utility.listPipelineType; - // string temptype = ""; - - // for (int i = 0; i < list.Count; i++) - // { - // PipelineType pipelineType = Utility.listPipelineType[i]; - // if (temptype != pipelineType.type) - // { - // //clbPipeLine.Items.Add(pipelineType.type); - // clbPipeLine2.Items.Add(pipelineType.type); - // temptype = pipelineType.type; - // } - // } - //} + } @@ -167,14 +151,8 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); + } } /// @@ -189,118 +167,74 @@ clbPipeLine.SetItemChecked(i, false); } } - Dictionary dic = new Dictionary(); - private void pipeDiameterStatis(GSOGeoPolygon3D polygon) - { - try - { - dic = new Dictionary(); - dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) - { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - int ncount = 0; - ncount = feats.Length; - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["数量"].Value = ncount; - dic.Add(layer.Caption, ncount); - } - } - else - { - MessageBox.Show("请选择图层!"); - } + + //private void pipeDiameterStatis(GSOGeoPolygon3D polygon) + //{ + // try + // { + // dic = new Dictionary(); + // dataGridViewX1.Rows.Clear(); + // if (clbPipeLine.CheckedItems.Count > 0) + // { + // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) + // { + // GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + // GSOFeatureLayer flayer = layer as GSOFeatureLayer; + // GSOFeatures feats = new GSOFeatures(); + // if (polygon == null) + // feats = flayer.GetAllFeatures(); + // else + // feats = flayer.FindFeaturesInPolygon(polygon, false); + // int ncount = 0; + // ncount = feats.Length; + // DataGridViewRow row = new DataGridViewRow(); + // int index = dataGridViewX1.Rows.Add(row); + // row = dataGridViewX1.Rows[index]; + // row.Cells["图层名称"].Value = layer.Caption; + // row.Cells["数量"].Value = ncount; + // dic.Add(layer.Caption, ncount); + // } + // } + // else + // { + // MessageBox.Show("请选择图层!"); + // } - showPipeWidget(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - LogError.PublishError(ex); - } - } + // showPipeWidget(); + // } + // catch (Exception ex) + // { + // MessageBox.Show(ex.Message); + // LogError.PublishError(ex); + // } + //} private void pipeDiameterStatisNew(GSOGeoPolygon3D polygon, string layertype) { try { - //根据管线类型找到其附属物 - accessStrs = Utility.getAccStrsByLayer(layertype); - if (accessStrs != null) - { + FeatureStatisticsService featureService = new FeatureStatisticsService(); + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(layertype); + List accessoriesResult = featureService.groupAccessories(polygon, layer); - dic = new Dictionary(); - dataGridViewX1.Rows.Clear(); - - int ncount = 0; - string accessValue = ""; - - //if (clbPipeLine.CheckedItems.Count > 0) - //{ - // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - // { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine2.Text); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - for (int j = 0; j < accessStrs.Length; j++) - { - if (polygon == null) - { - feats = flayer.GetFeatureByFieldValue("附属物名称", accessStrs[j], true); - ncount = feats.Length; - } - else - { - feats = flayer.FindFeaturesInPolygon(polygon, false); - - GSOFeatures newfeats = flayer.FindFeaturesInPolygon(polygon, false); - newfeats.RemoveAll(); - //过滤 - for (int n= 0; n < feats.Length; n++) - { - GSOFeature feat = feats[n]; - - if (feat.GetFieldAsString("附属物名称").Contains(accessStrs[j])) - { - newfeats.Add(feat); - } - } - ncount = newfeats.Length; - } - - //accessValue = clbPipeLine.CheckedItems[i].ToString() + accessStrs[j]; - accessValue = accessStrs[j]; - - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = accessValue;// layer.Caption; - row.Cells["数量"].Value = ncount; - dic.Add(accessValue, ncount); - } - // } - //} - //else - //{ - // MessageBox.Show("请选择图层!"); - //} - - showPipeWidget(); - } - else + if (accessoriesResult == null || accessoriesResult.Count == 0) { MessageBox.Show("该图层没有附属物"); } + dataGridViewX1.Rows.Clear(); + dic.Clear(); + foreach (FeaturesClassfyResult accessoryResult in accessoriesResult) + { + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + string layerName = accessoryResult.layerName; + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layerName;// layer.Caption; + row.Cells["数量"].Value = accessoryResult.ncount; + dic.Add(layerName, accessoryResult.ncount); + + } + showPipeWidget(); + } catch (Exception ex) { diff --git a/FrmpipeDeepstatis.cs b/FrmpipeDeepstatis.cs index 607ea65..879801a 100644 --- a/FrmpipeDeepstatis.cs +++ b/FrmpipeDeepstatis.cs @@ -19,19 +19,17 @@ List pipeLayerNames; static FrmpipeDeepstatis frm; + Dictionary dic = new Dictionary(); + public static void ShowForm(GSOGlobeControl globeControl, List pipeLayers, int visibleId) { if (frm == null) { frm = new FrmpipeDeepstatis(globeControl, pipeLayers, visibleId); frm.Show(globeControl.Parent); - } - else + }else if (frm.WindowState == FormWindowState.Minimized) { - if (frm.WindowState == FormWindowState.Minimized) - { - frm.WindowState = FormWindowState.Normal; - } + frm.WindowState = FormWindowState.Normal; } } @@ -45,8 +43,7 @@ buttonX9.Visible = false; buttonX8.Visible = true; buttonX8.Location = buttonX9.Location; - } - if (visibleId == 1) + }else if (visibleId == 1) { buttonX8.Visible = false; buttonX9.Visible = true; @@ -59,50 +56,47 @@ /// private void buttonX5_Click(object sender, EventArgs e) { - if (dataGridViewX2.SelectedCells.Count > 0) + if (dataGridViewX2.SelectedCells.Count == 0 || lstpipeRadius.SelectedItem == null) return; + + DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; + + if (row.Cells["上限"].Value == null) { - DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; - if (lstpipeRadius.SelectedItem != null) + row.Cells["下限"].Value = lstpipeRadius.SelectedItem.ToString(); + } + else + { + double downRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); + double upRadius = Convert.ToDouble(row.Cells["上限"].Value); + if (upRadius >= downRadius) { - if (row.Cells["上限"].Value == null) - { - row.Cells["下限"].Value = lstpipeRadius.SelectedItem.ToString(); - } - else - { - double downRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); - double upRadius = Convert.ToDouble(row.Cells["上限"].Value); - if (upRadius >= downRadius) - { - row.Cells["下限"].Value = downRadius.ToString(); - } - } + row.Cells["下限"].Value = downRadius.ToString(); } } - } + + } + //上限值设置 private void buttonX4_Click(object sender, EventArgs e) { - if (dataGridViewX2.SelectedCells.Count > 0) + if (dataGridViewX2.SelectedCells.Count == 0 || lstpipeRadius.SelectedItem == null) return; + + DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; + + if (row.Cells["下限"].Value != null && row.Cells["下限"].Value.ToString() != "") { - DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; - if (lstpipeRadius.SelectedItem != null) + double downRadius = Convert.ToDouble(row.Cells["下限"].Value); + double upRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); + if (upRadius >= downRadius) { - if (row.Cells["下限"].Value != null && row.Cells["下限"].Value.ToString() != "") - { - double downRadius = Convert.ToDouble(row.Cells["下限"].Value); - double upRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); - if (upRadius >= downRadius) - { - row.Cells["上限"].Value = upRadius.ToString(); - } - } - else - { - row.Cells["上限"].Value = lstpipeRadius.SelectedItem.ToString(); - } + row.Cells["上限"].Value = upRadius.ToString(); } } + else + { + row.Cells["上限"].Value = lstpipeRadius.SelectedItem.ToString(); + } + } /// /// 添加行按钮事件处理 @@ -128,7 +122,7 @@ dataGridViewX2.Rows.Remove(row); } } - Dictionary dic = new Dictionary(); + /// /// 给表格绑定数据 /// @@ -137,90 +131,121 @@ { try { - dic = new Dictionary(); + dic.Clear() ; dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) + FeatureStatisticsService service = new FeatureStatisticsService(); + for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) { - if (dataGridViewX2.Rows.Count > 0) - { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - for (int j = 0; j < dataGridViewX2.Rows.Count; j++) - { - double totalLength = 0.00; - int ncount = 0; - for (int m = 0; m < feats.Length; m++) - { - GSOFeature feat = feats[m]; - float radius = feat.GetFieldAsFloat("起始埋深"); - bool upCompare = true; - bool downCompare = true; - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["下限"].Value.ToString() != "") - { - if (radius >= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["下限"].Value)) - { - downCompare = true; - } - else - downCompare = false; - } - } - if (dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["上限"].Value.ToString() != "") - { - if (radius <= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["上限"].Value)) - { - upCompare = true; - } - else - upCompare = false; - } - } - if (upCompare && downCompare) - { - GSOGeoPolyline3D line = feat.Geometry as GSOGeoPolyline3D; - double length = line.GetSpaceLength(true, 6378137); - totalLength += length; - ncount += 1; - } - } - } - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["埋深范围"].Value = dataGridViewX2.Rows[j].Cells["下限"].Value + "-" + dataGridViewX2.Rows[j].Cells["上限"].Value; - row.Cells["条数"].Value = ncount; - row.Cells["总长度"].Value =Math.Round(totalLength,2); - dic.Add(layer.Caption + "," + row.Cells["埋深范围"].Value.ToString()+","+row.Cells["总长度"].Value.ToString(), ncount); - } - } - } - } - else + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + for (int j = 0; j < dataGridViewX2.Rows.Count; j++) { - MessageBox.Show("请添加分段!"); + object tempUp = dataGridViewX2.Rows[j].Cells["上限"].Value; + double? upLimit = null; + if (tempUp != null) upLimit = Convert.ToDouble(tempUp); + + object tempDown = dataGridViewX2.Rows[j].Cells["下限"].Value; + double? downLimit = null; + if (tempDown != null) downLimit = Convert.ToDouble(tempDown); + //Double downLimit = Convert.ToDouble(dataGridViewX2.Rows[j].Cells["下限"].Value); + if (upLimit == null && downLimit == null) continue;//空行过滤 + //获取符合条件的管线 + FeaturesClassfyResult result = service.getPipesInfoByValueSection(polygon, layer, downLimit, upLimit, "起始埋深"); + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layer.Caption; + row.Cells["埋深范围"].Value = result.groupFieldValue; + row.Cells["条数"].Value = result.ncount; + row.Cells["总长度"].Value = Math.Round(result.sum, 2); + dic.Add(layer.Caption + "," + row.Cells["埋深范围"].Value.ToString() + "," + row.Cells["总长度"].Value.ToString(), result.ncount); + + } } - else - { - MessageBox.Show("请选择图层!"); - } + + //if (clbPipeLine.CheckedItems.Count > 0) + //{ + // if (dataGridViewX2.Rows.Count > 0) + // { + // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) + // { + // GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + // GSOFeatureLayer flayer = layer as GSOFeatureLayer; + // GSOFeatures feats = new GSOFeatures(); + // if (polygon == null) + // feats = flayer.GetAllFeatures(); + // else + // feats = flayer.FindFeaturesInPolygon(polygon, false); + // for (int j = 0; j < dataGridViewX2.Rows.Count; j++) + // { + // double totalLength = 0.00; + // int ncount = 0; + // for (int m = 0; m < feats.Length; m++) + // { + // GSOFeature feat = feats[m]; + // float radius = feat.GetFieldAsFloat("起始埋深"); + // bool upCompare = true; + // bool downCompare = true; + // if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) + // { + // if (dataGridViewX2.Rows[j].Cells["下限"].Value != null) + // { + // if (dataGridViewX2.Rows[j].Cells["下限"].Value.ToString() != "") + // { + // if (radius >= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["下限"].Value)) + // { + // downCompare = true; + // } + // else + // downCompare = false; + // } + // } + // if (dataGridViewX2.Rows[j].Cells["上限"].Value != null) + // { + // if (dataGridViewX2.Rows[j].Cells["上限"].Value.ToString() != "") + // { + // if (radius <= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["上限"].Value)) + // { + // upCompare = true; + // } + // else + // upCompare = false; + // } + // } + // if (upCompare && downCompare) + // { + // GSOGeoPolyline3D line = feat.Geometry as GSOGeoPolyline3D; + // double length = line.GetSpaceLength(true, 6378137); + // totalLength += length; + // ncount += 1; + // } + // } + // } + // if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) + // { + // DataGridViewRow row = new DataGridViewRow(); + // int index = dataGridViewX1.Rows.Add(row); + // row = dataGridViewX1.Rows[index]; + // row.Cells["图层名称"].Value = layer.Caption; + // row.Cells["埋深范围"].Value = dataGridViewX2.Rows[j].Cells["下限"].Value + "-" + dataGridViewX2.Rows[j].Cells["上限"].Value; + // row.Cells["条数"].Value = ncount; + // row.Cells["总长度"].Value =Math.Round(totalLength,2); + + // dic.Add(layer.Caption + "," + row.Cells["埋深范围"].Value.ToString()+","+row.Cells["总长度"].Value.ToString(), ncount); + // } + // } + // } + // } + // else + // { + // MessageBox.Show("请添加分段!"); + // } + //} + //else + //{ + // MessageBox.Show("请选择图层!"); + //} showPipeWidget(); } catch (Exception ex) @@ -234,92 +259,7 @@ /// private void showPipeWidget() { - /* - if (chart1.Series.Count > 0) - { - chart1.Series.Clear(); - } - if (chart1.Legends.Count > 0) - { - chart1.Legends.Clear(); - } - - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - chart1.Series.Add(clbPipeLine.CheckedItems[i].ToString()); - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - if (layer != null && layer is GSOFeatureLayer) - { - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures features = flayer.GetAllFeatures(); - if (features.Length > 0) - { - if (features[0] != null && features[0].Geometry != null && features[0].Geometry.Type == EnumGeometryType.GeoPolyline3D) - { - GSOGeoPolyline3D p3d = features[0].Geometry as GSOGeoPolyline3D; - if (p3d.Style != null && p3d.Style is GSOPipeLineStyle3D) - { - GSOPipeLineStyle3D ps3d = p3d.Style as GSOPipeLineStyle3D; - chart1.Series[i].Color = ps3d.LineColor; - } - } - } - } - chart1.Legends.Add(clbPipeLine.CheckedItems[i].ToString()); - chart1.Legends[i].Docking = Docking.Top; - - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].IsTextAutoFit = true; - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].LegendStyle = LegendStyle.Table; - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].DockedToChartArea = "ChartArea1"; - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].BackColor = Color.Transparent; - chart1.ChartAreas["ChartArea1"].AxisY.IsLabelAutoFit = false; - - } - - // Set axis title - chart1.ChartAreas["ChartArea1"].AxisX.Title = "埋深范围(米)"; - chart1.ChartAreas["ChartArea1"].AxisY.Title = "管线数量"; - chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; - LabelStyle labeStyleAxisX = new LabelStyle(); - labeStyleAxisX.Angle = -45; - labeStyleAxisX.Enabled = true; - chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle = labeStyleAxisX; - - Dictionary dic1 = new Dictionary(); - List dicLength = new List(); - for (int j = 0; j < chart1.Series.Count; j++) - { - dic1 = new Dictionary(); - dicLength = new List(); - foreach (string key in dic.Keys) - { - if (key.Contains(chart1.Series[j].Name)) - { - dic1.Add(key.Split(',')[1].ToString(), dic[key]); - dicLength.Add(key.Split(',')[2].ToString()); - } - } - chart1.Series[j].ChartType = SeriesChartType.Column; - - chart1.Series[j]["DrawingStyle"] = "Cylinder"; - - //chart1.Series[j].IsValueShownAsLabel = true; - - chart1.Series[j].Points.DataBindXY(dic1.Keys, dic1.Values); - for (int m = 0; m < dic1.Values.Count; m++) - { - if (chart1.Series[j].Points[m].YValues[0].ToString() != "0") - { - chart1.Series[j].Points[m].Label = chart1.Series[j].Points[m].YValues[0].ToString(); - - } - if (dicLength[m] != "0") - { - chart1.Series[j].Points[m].ToolTip ="长度:"+dicLength[m]; - } - } - } - * */ + chart1.Series.Clear(); chart1.Series.Add("管线"); @@ -367,19 +307,29 @@ /// void globeControl1_TrackPolygonEndEvent(object sender, TrackPolygonEndEventArgs e) { - if (e.Polygon != null) + if (clbPipeLine.CheckedItems.Count == 0) { - GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; - polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; - GSOFeature feature = new GSOFeature(); - feature.Geometry = polygon; - feature.Name = "trackPolygon"; - globeControl1.Globe.MemoryLayer.AddFeature(feature); - globeControl1.Globe.ClearLastTrackPolygon(); - globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(e.Polygon); + MessageBox.Show("请选择图层"); + return; } + if (dataGridViewX2.Rows.Count == 0) + { + MessageBox.Show("请添加分段"); + return; + } + if (e.Polygon == null) return; + + GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; + polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; + GSOFeature feature = new GSOFeature(); + feature.Geometry = polygon; + feature.Name = "trackPolygon"; + globeControl1.Globe.MemoryLayer.AddFeature(feature); + globeControl1.Globe.ClearLastTrackPolygon(); + globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(e.Polygon); + } /// /// 全选 @@ -402,14 +352,8 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); + } } /// @@ -431,21 +375,16 @@ /// private void buttonX8_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - if (dataGridViewX2.Rows.Count > 0) - { - pipeDiameterStatis(null); - } - else - { - MessageBox.Show("请添加分段"); - } - } - else - { + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层"); - } + return; + } + if (dataGridViewX2.Rows.Count == 0) + { + MessageBox.Show("请添加分段"); + return; + } + pipeDiameterStatis(null); } /// /// 绘制区域分段统计 @@ -454,24 +393,21 @@ /// private void buttonX9_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - if (dataGridViewX2.Rows.Count > 0) - { - Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); - globeControl1.Globe.Action = EnumAction3D.TrackPolygon; - globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; - globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - } - else - { - MessageBox.Show("请添加分段"); - } - } - else + + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层"); + return; } + if (dataGridViewX2.Rows.Count == 0) + { + MessageBox.Show("请添加分段"); + return; + } + Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); + globeControl1.Globe.Action = EnumAction3D.TrackPolygon; + globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; + globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); } diff --git a/FrmpipeDiametergather.cs b/FrmpipeDiametergather.cs index 8c3b147..36467df 100644 --- a/FrmpipeDiametergather.cs +++ b/FrmpipeDiametergather.cs @@ -19,6 +19,8 @@ List pipeLayerNames; static FrmpipeDiametergather frm; + Dictionary dic = new Dictionary(); + public static void ShowForm(GSOGlobeControl globeControl, List pipeLayers, int visibleId) { if (frm == null) @@ -26,12 +28,9 @@ frm = new FrmpipeDiametergather(globeControl, pipeLayers, visibleId); frm.Show(globeControl.Parent); } - else + else if (frm.WindowState == FormWindowState.Minimized) { - if (frm.WindowState == FormWindowState.Minimized) - { - frm.WindowState = FormWindowState.Normal; - } + frm.WindowState = FormWindowState.Normal; } } @@ -45,8 +44,7 @@ buttonX9.Visible = false; buttonX8.Visible = true; buttonX8.Location = buttonX9.Location; - } - if (visibleId == 1) + }else if (visibleId == 1) { buttonX8.Visible = false; buttonX9.Visible = true; @@ -74,19 +72,23 @@ /// void globeControl1_TrackPolygonEndEvent(object sender, TrackPolygonEndEventArgs e) { - if (e.Polygon != null) + if (e.Polygon == null) return; + if (clbPipeLine.CheckedItems.Count == 0) { - GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; - polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; - GSOFeature feature = new GSOFeature(); - feature.Geometry = polygon; - feature.Name = "trackPolygon"; - globeControl1.Globe.MemoryLayer.AddFeature(feature); - globeControl1.Globe.ClearLastTrackPolygon(); - globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(e.Polygon); + MessageBox.Show("请选择图层!"); + return; } + GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; + polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; + GSOFeature feature = new GSOFeature(); + feature.Geometry = polygon; + feature.Name = "trackPolygon"; + globeControl1.Globe.MemoryLayer.AddFeature(feature); + globeControl1.Globe.ClearLastTrackPolygon(); + globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(e.Polygon); + } /// /// 全选 @@ -109,14 +111,8 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); + } } /// @@ -138,15 +134,13 @@ /// private void buttonX8_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(null); - } - else - { + + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层!"); - } + return; + } + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(null); } /// /// 绘制区域分类汇总 @@ -155,21 +149,20 @@ /// private void buttonX9_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); - globeControl1.Globe.Action = EnumAction3D.TrackPolygon; - globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; - globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - } - else + + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层!"); + return; } + Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); + globeControl1.Globe.Action = EnumAction3D.TrackPolygon; + globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; + globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); } - Dictionary dic = new Dictionary(); + /// /// 给表格绑定数据 /// @@ -178,62 +171,27 @@ { try { - dic = new Dictionary(); + dic.Clear() ; dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) + FeatureStatisticsService service = new FeatureStatisticsService(); + for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - List lstDiameter = new List(); - - for (int j = 0; j < feats.Length; j++) - { - if (!lstDiameter.Contains(feats[j].GetFieldAsFloat("管径_毫米"))) - { - lstDiameter.Add(feats[j].GetFieldAsFloat("管径_毫米")); - } - } - lstDiameter.Sort(); - if (lstDiameter.Count > 0) - { - for (int m = 0; m < lstDiameter.Count; m++) - { - double totalLength = 0.00; - int ncount = 0; - for (int j = 0; j < feats.Length; j++) - { - if (feats[j].GetFieldAsFloat("管径_毫米") == lstDiameter[m]) - { - GSOGeoPolyline3D line = feats[j].Geometry as GSOGeoPolyline3D; - double length = line.GetSpaceLength(true, 6378137); - totalLength += length; - ncount += 1; - } - } - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["管径"].Value = lstDiameter[m]; - row.Cells["条数"].Value = ncount; - row.Cells["总长度"].Value =Math.Round(totalLength,2); - - dic.Add(layer.Caption + "," + row.Cells["管径"].Value.ToString(), ncount); - } - } + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + List results = service.groupPipeByDiameter(polygon,layer); + + foreach(FeaturesClassfyResult result in results){ + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layer.Caption; + row.Cells["管径"].Value = result.groupFieldValue; + row.Cells["条数"].Value = result.ncount; + row.Cells["总长度"].Value = Math.Round(result.sum, 2); + dic.Add(layer.Caption + "," + row.Cells["管径"].Value.ToString(), result.ncount); } + } - else - { - MessageBox.Show("请选择图层!"); - } + showPipeWidget(); } catch (Exception ex) @@ -442,19 +400,19 @@ globeControl1.Globe.MemoryLayer.RemoveAllFeature(); } - + //限制只能选择一个 private void clbPipeLine_ItemCheck(object sender, ItemCheckEventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) + if (clbPipeLine.CheckedItems.Count == 0) return; + + for (int i = 0; i < clbPipeLine.Items.Count; i++) { - for (int i = 0; i < clbPipeLine.Items.Count; i++) + if (i != e.Index) { - if (i != e.Index) - { - this.clbPipeLine.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked); - } + this.clbPipeLine.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked); } } + } diff --git a/FrmAccessoriesgather.cs b/FrmAccessoriesgather.cs index 5187a3a..36c014e 100644 --- a/FrmAccessoriesgather.cs +++ b/FrmAccessoriesgather.cs @@ -17,7 +17,8 @@ { GSOGlobeControl globeControl1; List instrumenLayerNames; - string[] accessStrs = null; + //string[] accessStrs = null; + Dictionary dic = new Dictionary(); static FrmAccessoriesgather frm; public static void ShowForm(GSOGlobeControl globeControl, List pipeLayers, int visibleId) @@ -46,9 +47,7 @@ buttonX9.Visible = false; buttonX8.Visible = true; buttonX8.Location = buttonX9.Location; - } - if (visibleId == 1) - { + }else{ buttonX8.Visible = false; buttonX9.Visible = true; } @@ -67,22 +66,7 @@ clbPipeLine2.Items.Add(instrumenLayerNames[i]); } } - //if (Utility.listPipelineType != null) - //{ - // List list = Utility.listPipelineType; - // string temptype = ""; - - // for (int i = 0; i < list.Count; i++) - // { - // PipelineType pipelineType = Utility.listPipelineType[i]; - // if (temptype != pipelineType.type) - // { - // //clbPipeLine.Items.Add(pipelineType.type); - // clbPipeLine2.Items.Add(pipelineType.type); - // temptype = pipelineType.type; - // } - // } - //} + } @@ -167,14 +151,8 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); + } } /// @@ -189,118 +167,74 @@ clbPipeLine.SetItemChecked(i, false); } } - Dictionary dic = new Dictionary(); - private void pipeDiameterStatis(GSOGeoPolygon3D polygon) - { - try - { - dic = new Dictionary(); - dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) - { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - int ncount = 0; - ncount = feats.Length; - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["数量"].Value = ncount; - dic.Add(layer.Caption, ncount); - } - } - else - { - MessageBox.Show("请选择图层!"); - } + + //private void pipeDiameterStatis(GSOGeoPolygon3D polygon) + //{ + // try + // { + // dic = new Dictionary(); + // dataGridViewX1.Rows.Clear(); + // if (clbPipeLine.CheckedItems.Count > 0) + // { + // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) + // { + // GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + // GSOFeatureLayer flayer = layer as GSOFeatureLayer; + // GSOFeatures feats = new GSOFeatures(); + // if (polygon == null) + // feats = flayer.GetAllFeatures(); + // else + // feats = flayer.FindFeaturesInPolygon(polygon, false); + // int ncount = 0; + // ncount = feats.Length; + // DataGridViewRow row = new DataGridViewRow(); + // int index = dataGridViewX1.Rows.Add(row); + // row = dataGridViewX1.Rows[index]; + // row.Cells["图层名称"].Value = layer.Caption; + // row.Cells["数量"].Value = ncount; + // dic.Add(layer.Caption, ncount); + // } + // } + // else + // { + // MessageBox.Show("请选择图层!"); + // } - showPipeWidget(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - LogError.PublishError(ex); - } - } + // showPipeWidget(); + // } + // catch (Exception ex) + // { + // MessageBox.Show(ex.Message); + // LogError.PublishError(ex); + // } + //} private void pipeDiameterStatisNew(GSOGeoPolygon3D polygon, string layertype) { try { - //根据管线类型找到其附属物 - accessStrs = Utility.getAccStrsByLayer(layertype); - if (accessStrs != null) - { + FeatureStatisticsService featureService = new FeatureStatisticsService(); + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(layertype); + List accessoriesResult = featureService.groupAccessories(polygon, layer); - dic = new Dictionary(); - dataGridViewX1.Rows.Clear(); - - int ncount = 0; - string accessValue = ""; - - //if (clbPipeLine.CheckedItems.Count > 0) - //{ - // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - // { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine2.Text); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - for (int j = 0; j < accessStrs.Length; j++) - { - if (polygon == null) - { - feats = flayer.GetFeatureByFieldValue("附属物名称", accessStrs[j], true); - ncount = feats.Length; - } - else - { - feats = flayer.FindFeaturesInPolygon(polygon, false); - - GSOFeatures newfeats = flayer.FindFeaturesInPolygon(polygon, false); - newfeats.RemoveAll(); - //过滤 - for (int n= 0; n < feats.Length; n++) - { - GSOFeature feat = feats[n]; - - if (feat.GetFieldAsString("附属物名称").Contains(accessStrs[j])) - { - newfeats.Add(feat); - } - } - ncount = newfeats.Length; - } - - //accessValue = clbPipeLine.CheckedItems[i].ToString() + accessStrs[j]; - accessValue = accessStrs[j]; - - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = accessValue;// layer.Caption; - row.Cells["数量"].Value = ncount; - dic.Add(accessValue, ncount); - } - // } - //} - //else - //{ - // MessageBox.Show("请选择图层!"); - //} - - showPipeWidget(); - } - else + if (accessoriesResult == null || accessoriesResult.Count == 0) { MessageBox.Show("该图层没有附属物"); } + dataGridViewX1.Rows.Clear(); + dic.Clear(); + foreach (FeaturesClassfyResult accessoryResult in accessoriesResult) + { + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + string layerName = accessoryResult.layerName; + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layerName;// layer.Caption; + row.Cells["数量"].Value = accessoryResult.ncount; + dic.Add(layerName, accessoryResult.ncount); + + } + showPipeWidget(); + } catch (Exception ex) { diff --git a/FrmpipeDeepstatis.cs b/FrmpipeDeepstatis.cs index 607ea65..879801a 100644 --- a/FrmpipeDeepstatis.cs +++ b/FrmpipeDeepstatis.cs @@ -19,19 +19,17 @@ List pipeLayerNames; static FrmpipeDeepstatis frm; + Dictionary dic = new Dictionary(); + public static void ShowForm(GSOGlobeControl globeControl, List pipeLayers, int visibleId) { if (frm == null) { frm = new FrmpipeDeepstatis(globeControl, pipeLayers, visibleId); frm.Show(globeControl.Parent); - } - else + }else if (frm.WindowState == FormWindowState.Minimized) { - if (frm.WindowState == FormWindowState.Minimized) - { - frm.WindowState = FormWindowState.Normal; - } + frm.WindowState = FormWindowState.Normal; } } @@ -45,8 +43,7 @@ buttonX9.Visible = false; buttonX8.Visible = true; buttonX8.Location = buttonX9.Location; - } - if (visibleId == 1) + }else if (visibleId == 1) { buttonX8.Visible = false; buttonX9.Visible = true; @@ -59,50 +56,47 @@ /// private void buttonX5_Click(object sender, EventArgs e) { - if (dataGridViewX2.SelectedCells.Count > 0) + if (dataGridViewX2.SelectedCells.Count == 0 || lstpipeRadius.SelectedItem == null) return; + + DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; + + if (row.Cells["上限"].Value == null) { - DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; - if (lstpipeRadius.SelectedItem != null) + row.Cells["下限"].Value = lstpipeRadius.SelectedItem.ToString(); + } + else + { + double downRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); + double upRadius = Convert.ToDouble(row.Cells["上限"].Value); + if (upRadius >= downRadius) { - if (row.Cells["上限"].Value == null) - { - row.Cells["下限"].Value = lstpipeRadius.SelectedItem.ToString(); - } - else - { - double downRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); - double upRadius = Convert.ToDouble(row.Cells["上限"].Value); - if (upRadius >= downRadius) - { - row.Cells["下限"].Value = downRadius.ToString(); - } - } + row.Cells["下限"].Value = downRadius.ToString(); } } - } + + } + //上限值设置 private void buttonX4_Click(object sender, EventArgs e) { - if (dataGridViewX2.SelectedCells.Count > 0) + if (dataGridViewX2.SelectedCells.Count == 0 || lstpipeRadius.SelectedItem == null) return; + + DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; + + if (row.Cells["下限"].Value != null && row.Cells["下限"].Value.ToString() != "") { - DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; - if (lstpipeRadius.SelectedItem != null) + double downRadius = Convert.ToDouble(row.Cells["下限"].Value); + double upRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); + if (upRadius >= downRadius) { - if (row.Cells["下限"].Value != null && row.Cells["下限"].Value.ToString() != "") - { - double downRadius = Convert.ToDouble(row.Cells["下限"].Value); - double upRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); - if (upRadius >= downRadius) - { - row.Cells["上限"].Value = upRadius.ToString(); - } - } - else - { - row.Cells["上限"].Value = lstpipeRadius.SelectedItem.ToString(); - } + row.Cells["上限"].Value = upRadius.ToString(); } } + else + { + row.Cells["上限"].Value = lstpipeRadius.SelectedItem.ToString(); + } + } /// /// 添加行按钮事件处理 @@ -128,7 +122,7 @@ dataGridViewX2.Rows.Remove(row); } } - Dictionary dic = new Dictionary(); + /// /// 给表格绑定数据 /// @@ -137,90 +131,121 @@ { try { - dic = new Dictionary(); + dic.Clear() ; dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) + FeatureStatisticsService service = new FeatureStatisticsService(); + for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) { - if (dataGridViewX2.Rows.Count > 0) - { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - for (int j = 0; j < dataGridViewX2.Rows.Count; j++) - { - double totalLength = 0.00; - int ncount = 0; - for (int m = 0; m < feats.Length; m++) - { - GSOFeature feat = feats[m]; - float radius = feat.GetFieldAsFloat("起始埋深"); - bool upCompare = true; - bool downCompare = true; - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["下限"].Value.ToString() != "") - { - if (radius >= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["下限"].Value)) - { - downCompare = true; - } - else - downCompare = false; - } - } - if (dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["上限"].Value.ToString() != "") - { - if (radius <= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["上限"].Value)) - { - upCompare = true; - } - else - upCompare = false; - } - } - if (upCompare && downCompare) - { - GSOGeoPolyline3D line = feat.Geometry as GSOGeoPolyline3D; - double length = line.GetSpaceLength(true, 6378137); - totalLength += length; - ncount += 1; - } - } - } - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["埋深范围"].Value = dataGridViewX2.Rows[j].Cells["下限"].Value + "-" + dataGridViewX2.Rows[j].Cells["上限"].Value; - row.Cells["条数"].Value = ncount; - row.Cells["总长度"].Value =Math.Round(totalLength,2); - dic.Add(layer.Caption + "," + row.Cells["埋深范围"].Value.ToString()+","+row.Cells["总长度"].Value.ToString(), ncount); - } - } - } - } - else + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + for (int j = 0; j < dataGridViewX2.Rows.Count; j++) { - MessageBox.Show("请添加分段!"); + object tempUp = dataGridViewX2.Rows[j].Cells["上限"].Value; + double? upLimit = null; + if (tempUp != null) upLimit = Convert.ToDouble(tempUp); + + object tempDown = dataGridViewX2.Rows[j].Cells["下限"].Value; + double? downLimit = null; + if (tempDown != null) downLimit = Convert.ToDouble(tempDown); + //Double downLimit = Convert.ToDouble(dataGridViewX2.Rows[j].Cells["下限"].Value); + if (upLimit == null && downLimit == null) continue;//空行过滤 + //获取符合条件的管线 + FeaturesClassfyResult result = service.getPipesInfoByValueSection(polygon, layer, downLimit, upLimit, "起始埋深"); + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layer.Caption; + row.Cells["埋深范围"].Value = result.groupFieldValue; + row.Cells["条数"].Value = result.ncount; + row.Cells["总长度"].Value = Math.Round(result.sum, 2); + dic.Add(layer.Caption + "," + row.Cells["埋深范围"].Value.ToString() + "," + row.Cells["总长度"].Value.ToString(), result.ncount); + + } } - else - { - MessageBox.Show("请选择图层!"); - } + + //if (clbPipeLine.CheckedItems.Count > 0) + //{ + // if (dataGridViewX2.Rows.Count > 0) + // { + // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) + // { + // GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + // GSOFeatureLayer flayer = layer as GSOFeatureLayer; + // GSOFeatures feats = new GSOFeatures(); + // if (polygon == null) + // feats = flayer.GetAllFeatures(); + // else + // feats = flayer.FindFeaturesInPolygon(polygon, false); + // for (int j = 0; j < dataGridViewX2.Rows.Count; j++) + // { + // double totalLength = 0.00; + // int ncount = 0; + // for (int m = 0; m < feats.Length; m++) + // { + // GSOFeature feat = feats[m]; + // float radius = feat.GetFieldAsFloat("起始埋深"); + // bool upCompare = true; + // bool downCompare = true; + // if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) + // { + // if (dataGridViewX2.Rows[j].Cells["下限"].Value != null) + // { + // if (dataGridViewX2.Rows[j].Cells["下限"].Value.ToString() != "") + // { + // if (radius >= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["下限"].Value)) + // { + // downCompare = true; + // } + // else + // downCompare = false; + // } + // } + // if (dataGridViewX2.Rows[j].Cells["上限"].Value != null) + // { + // if (dataGridViewX2.Rows[j].Cells["上限"].Value.ToString() != "") + // { + // if (radius <= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["上限"].Value)) + // { + // upCompare = true; + // } + // else + // upCompare = false; + // } + // } + // if (upCompare && downCompare) + // { + // GSOGeoPolyline3D line = feat.Geometry as GSOGeoPolyline3D; + // double length = line.GetSpaceLength(true, 6378137); + // totalLength += length; + // ncount += 1; + // } + // } + // } + // if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) + // { + // DataGridViewRow row = new DataGridViewRow(); + // int index = dataGridViewX1.Rows.Add(row); + // row = dataGridViewX1.Rows[index]; + // row.Cells["图层名称"].Value = layer.Caption; + // row.Cells["埋深范围"].Value = dataGridViewX2.Rows[j].Cells["下限"].Value + "-" + dataGridViewX2.Rows[j].Cells["上限"].Value; + // row.Cells["条数"].Value = ncount; + // row.Cells["总长度"].Value =Math.Round(totalLength,2); + + // dic.Add(layer.Caption + "," + row.Cells["埋深范围"].Value.ToString()+","+row.Cells["总长度"].Value.ToString(), ncount); + // } + // } + // } + // } + // else + // { + // MessageBox.Show("请添加分段!"); + // } + //} + //else + //{ + // MessageBox.Show("请选择图层!"); + //} showPipeWidget(); } catch (Exception ex) @@ -234,92 +259,7 @@ /// private void showPipeWidget() { - /* - if (chart1.Series.Count > 0) - { - chart1.Series.Clear(); - } - if (chart1.Legends.Count > 0) - { - chart1.Legends.Clear(); - } - - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - chart1.Series.Add(clbPipeLine.CheckedItems[i].ToString()); - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - if (layer != null && layer is GSOFeatureLayer) - { - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures features = flayer.GetAllFeatures(); - if (features.Length > 0) - { - if (features[0] != null && features[0].Geometry != null && features[0].Geometry.Type == EnumGeometryType.GeoPolyline3D) - { - GSOGeoPolyline3D p3d = features[0].Geometry as GSOGeoPolyline3D; - if (p3d.Style != null && p3d.Style is GSOPipeLineStyle3D) - { - GSOPipeLineStyle3D ps3d = p3d.Style as GSOPipeLineStyle3D; - chart1.Series[i].Color = ps3d.LineColor; - } - } - } - } - chart1.Legends.Add(clbPipeLine.CheckedItems[i].ToString()); - chart1.Legends[i].Docking = Docking.Top; - - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].IsTextAutoFit = true; - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].LegendStyle = LegendStyle.Table; - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].DockedToChartArea = "ChartArea1"; - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].BackColor = Color.Transparent; - chart1.ChartAreas["ChartArea1"].AxisY.IsLabelAutoFit = false; - - } - - // Set axis title - chart1.ChartAreas["ChartArea1"].AxisX.Title = "埋深范围(米)"; - chart1.ChartAreas["ChartArea1"].AxisY.Title = "管线数量"; - chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; - LabelStyle labeStyleAxisX = new LabelStyle(); - labeStyleAxisX.Angle = -45; - labeStyleAxisX.Enabled = true; - chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle = labeStyleAxisX; - - Dictionary dic1 = new Dictionary(); - List dicLength = new List(); - for (int j = 0; j < chart1.Series.Count; j++) - { - dic1 = new Dictionary(); - dicLength = new List(); - foreach (string key in dic.Keys) - { - if (key.Contains(chart1.Series[j].Name)) - { - dic1.Add(key.Split(',')[1].ToString(), dic[key]); - dicLength.Add(key.Split(',')[2].ToString()); - } - } - chart1.Series[j].ChartType = SeriesChartType.Column; - - chart1.Series[j]["DrawingStyle"] = "Cylinder"; - - //chart1.Series[j].IsValueShownAsLabel = true; - - chart1.Series[j].Points.DataBindXY(dic1.Keys, dic1.Values); - for (int m = 0; m < dic1.Values.Count; m++) - { - if (chart1.Series[j].Points[m].YValues[0].ToString() != "0") - { - chart1.Series[j].Points[m].Label = chart1.Series[j].Points[m].YValues[0].ToString(); - - } - if (dicLength[m] != "0") - { - chart1.Series[j].Points[m].ToolTip ="长度:"+dicLength[m]; - } - } - } - * */ + chart1.Series.Clear(); chart1.Series.Add("管线"); @@ -367,19 +307,29 @@ /// void globeControl1_TrackPolygonEndEvent(object sender, TrackPolygonEndEventArgs e) { - if (e.Polygon != null) + if (clbPipeLine.CheckedItems.Count == 0) { - GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; - polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; - GSOFeature feature = new GSOFeature(); - feature.Geometry = polygon; - feature.Name = "trackPolygon"; - globeControl1.Globe.MemoryLayer.AddFeature(feature); - globeControl1.Globe.ClearLastTrackPolygon(); - globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(e.Polygon); + MessageBox.Show("请选择图层"); + return; } + if (dataGridViewX2.Rows.Count == 0) + { + MessageBox.Show("请添加分段"); + return; + } + if (e.Polygon == null) return; + + GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; + polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; + GSOFeature feature = new GSOFeature(); + feature.Geometry = polygon; + feature.Name = "trackPolygon"; + globeControl1.Globe.MemoryLayer.AddFeature(feature); + globeControl1.Globe.ClearLastTrackPolygon(); + globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(e.Polygon); + } /// /// 全选 @@ -402,14 +352,8 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); + } } /// @@ -431,21 +375,16 @@ /// private void buttonX8_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - if (dataGridViewX2.Rows.Count > 0) - { - pipeDiameterStatis(null); - } - else - { - MessageBox.Show("请添加分段"); - } - } - else - { + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层"); - } + return; + } + if (dataGridViewX2.Rows.Count == 0) + { + MessageBox.Show("请添加分段"); + return; + } + pipeDiameterStatis(null); } /// /// 绘制区域分段统计 @@ -454,24 +393,21 @@ /// private void buttonX9_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - if (dataGridViewX2.Rows.Count > 0) - { - Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); - globeControl1.Globe.Action = EnumAction3D.TrackPolygon; - globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; - globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - } - else - { - MessageBox.Show("请添加分段"); - } - } - else + + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层"); + return; } + if (dataGridViewX2.Rows.Count == 0) + { + MessageBox.Show("请添加分段"); + return; + } + Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); + globeControl1.Globe.Action = EnumAction3D.TrackPolygon; + globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; + globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); } diff --git a/FrmpipeDiametergather.cs b/FrmpipeDiametergather.cs index 8c3b147..36467df 100644 --- a/FrmpipeDiametergather.cs +++ b/FrmpipeDiametergather.cs @@ -19,6 +19,8 @@ List pipeLayerNames; static FrmpipeDiametergather frm; + Dictionary dic = new Dictionary(); + public static void ShowForm(GSOGlobeControl globeControl, List pipeLayers, int visibleId) { if (frm == null) @@ -26,12 +28,9 @@ frm = new FrmpipeDiametergather(globeControl, pipeLayers, visibleId); frm.Show(globeControl.Parent); } - else + else if (frm.WindowState == FormWindowState.Minimized) { - if (frm.WindowState == FormWindowState.Minimized) - { - frm.WindowState = FormWindowState.Normal; - } + frm.WindowState = FormWindowState.Normal; } } @@ -45,8 +44,7 @@ buttonX9.Visible = false; buttonX8.Visible = true; buttonX8.Location = buttonX9.Location; - } - if (visibleId == 1) + }else if (visibleId == 1) { buttonX8.Visible = false; buttonX9.Visible = true; @@ -74,19 +72,23 @@ /// void globeControl1_TrackPolygonEndEvent(object sender, TrackPolygonEndEventArgs e) { - if (e.Polygon != null) + if (e.Polygon == null) return; + if (clbPipeLine.CheckedItems.Count == 0) { - GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; - polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; - GSOFeature feature = new GSOFeature(); - feature.Geometry = polygon; - feature.Name = "trackPolygon"; - globeControl1.Globe.MemoryLayer.AddFeature(feature); - globeControl1.Globe.ClearLastTrackPolygon(); - globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(e.Polygon); + MessageBox.Show("请选择图层!"); + return; } + GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; + polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; + GSOFeature feature = new GSOFeature(); + feature.Geometry = polygon; + feature.Name = "trackPolygon"; + globeControl1.Globe.MemoryLayer.AddFeature(feature); + globeControl1.Globe.ClearLastTrackPolygon(); + globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(e.Polygon); + } /// /// 全选 @@ -109,14 +111,8 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); + } } /// @@ -138,15 +134,13 @@ /// private void buttonX8_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(null); - } - else - { + + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层!"); - } + return; + } + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(null); } /// /// 绘制区域分类汇总 @@ -155,21 +149,20 @@ /// private void buttonX9_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); - globeControl1.Globe.Action = EnumAction3D.TrackPolygon; - globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; - globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - } - else + + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层!"); + return; } + Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); + globeControl1.Globe.Action = EnumAction3D.TrackPolygon; + globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; + globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); } - Dictionary dic = new Dictionary(); + /// /// 给表格绑定数据 /// @@ -178,62 +171,27 @@ { try { - dic = new Dictionary(); + dic.Clear() ; dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) + FeatureStatisticsService service = new FeatureStatisticsService(); + for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - List lstDiameter = new List(); - - for (int j = 0; j < feats.Length; j++) - { - if (!lstDiameter.Contains(feats[j].GetFieldAsFloat("管径_毫米"))) - { - lstDiameter.Add(feats[j].GetFieldAsFloat("管径_毫米")); - } - } - lstDiameter.Sort(); - if (lstDiameter.Count > 0) - { - for (int m = 0; m < lstDiameter.Count; m++) - { - double totalLength = 0.00; - int ncount = 0; - for (int j = 0; j < feats.Length; j++) - { - if (feats[j].GetFieldAsFloat("管径_毫米") == lstDiameter[m]) - { - GSOGeoPolyline3D line = feats[j].Geometry as GSOGeoPolyline3D; - double length = line.GetSpaceLength(true, 6378137); - totalLength += length; - ncount += 1; - } - } - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["管径"].Value = lstDiameter[m]; - row.Cells["条数"].Value = ncount; - row.Cells["总长度"].Value =Math.Round(totalLength,2); - - dic.Add(layer.Caption + "," + row.Cells["管径"].Value.ToString(), ncount); - } - } + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + List results = service.groupPipeByDiameter(polygon,layer); + + foreach(FeaturesClassfyResult result in results){ + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layer.Caption; + row.Cells["管径"].Value = result.groupFieldValue; + row.Cells["条数"].Value = result.ncount; + row.Cells["总长度"].Value = Math.Round(result.sum, 2); + dic.Add(layer.Caption + "," + row.Cells["管径"].Value.ToString(), result.ncount); } + } - else - { - MessageBox.Show("请选择图层!"); - } + showPipeWidget(); } catch (Exception ex) @@ -442,19 +400,19 @@ globeControl1.Globe.MemoryLayer.RemoveAllFeature(); } - + //限制只能选择一个 private void clbPipeLine_ItemCheck(object sender, ItemCheckEventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) + if (clbPipeLine.CheckedItems.Count == 0) return; + + for (int i = 0; i < clbPipeLine.Items.Count; i++) { - for (int i = 0; i < clbPipeLine.Items.Count; i++) + if (i != e.Index) { - if (i != e.Index) - { - this.clbPipeLine.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked); - } + this.clbPipeLine.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked); } } + } diff --git a/FrmpipeMaterialGather.cs b/FrmpipeMaterialGather.cs index 5b2e1c7..b7ab1d2 100644 --- a/FrmpipeMaterialGather.cs +++ b/FrmpipeMaterialGather.cs @@ -26,12 +26,9 @@ frm = new FrmpipeMaterialGather(globeControl, pipeLayers, visibleId); frm.Show(globeControl.Parent); } - else + else if(frm.WindowState == FormWindowState.Minimized) { - if (frm.WindowState == FormWindowState.Minimized) - { - frm.WindowState = FormWindowState.Normal; - } + frm.WindowState = FormWindowState.Normal; } } @@ -45,8 +42,7 @@ buttonX9.Visible = false; buttonX8.Visible = true; buttonX8.Location = buttonX9.Location; - } - if (visibleId == 1) + }else if (visibleId == 1) { buttonX8.Visible = false; buttonX9.Visible = true; @@ -59,47 +55,31 @@ /// private void FrmpipeMaterialGather_Load(object sender, EventArgs e) { - //for (int i = globeControl1.Globe.Layers.Count - 1; i >= 0; i--) - //{ + for (int i = 0; i < pipeLayerNames.Count; i++) { - //GSOLayer layer = globeControl1.Globe.Layers[i]; clbPipeLine.Items.Add(pipeLayerNames[i]); - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(pipeLayerNames[i]); - if (layer.Dataset != null && layer.Dataset.IsFeatureDataset) - { - string name = layer.Name; + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(pipeLayerNames[i]); + if (layer.Dataset == null || !layer.Dataset.IsFeatureDataset || layer.Type != EnumLayerType.FeatureLayer) continue; - if (layer.Type == EnumLayerType.FeatureLayer)//if (layer.Type == EnumLayerType.FeatureLayer && !name.Contains("\\") && layer.Caption.Contains("管线") && !layer.Caption.Contains("弯头")) + string name = layer.Name; + GSOFeatureLayer flayer = layer as GSOFeatureLayer; + GSOFeatures feats = flayer.GetAllFeatures(); + + for (int j = 0; j < feats.Length; j++) + { + if (clbmaterials.Items.Contains(feats[j].GetFieldAsString("材质"))) continue; + + if (feats[j].GetFieldAsString("材质") == "" && !clbmaterials.Items.Contains("无")) { - /* - if (!clbPipeLine.Items.Contains(layer.Caption)) - { - clbPipeLine.Items.Add(layer.Caption); - } - */ - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - feats = flayer.GetAllFeatures(); - for (int j = 0; j < feats.Length; j++) - { - if (!clbmaterials.Items.Contains(feats[j].GetFieldAsString("材质"))) - { - if (feats[j].GetFieldAsString("材质") == "") - { - if (!clbmaterials.Items.Contains("无")) - { - clbmaterials.Items.Add("无"); - } - } - else - { - clbmaterials.Items.Add(feats[j].GetFieldAsString("材质")); - } - } - } + clbmaterials.Items.Add("无"); + } + else + { + clbmaterials.Items.Add(feats[j].GetFieldAsString("材质")); } } + } } @@ -110,19 +90,23 @@ /// void globeControl1_TrackPolygonEndEvent(object sender, TrackPolygonEndEventArgs e) { - if (e.Polygon != null) + if (e.Polygon == null) return; + if (clbPipeLine.CheckedItems.Count == 0) { - GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; - polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; - GSOFeature feature = new GSOFeature(); - feature.Geometry = polygon; - feature.Name = "trackPolygon"; - globeControl1.Globe.MemoryLayer.AddFeature(feature); - globeControl1.Globe.ClearLastTrackPolygon(); - globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(e.Polygon); + MessageBox.Show("请选择图层!"); + return; } + GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; + polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; + GSOFeature feature = new GSOFeature(); + feature.Geometry = polygon; + feature.Name = "trackPolygon"; + globeControl1.Globe.MemoryLayer.AddFeature(feature); + globeControl1.Globe.ClearLastTrackPolygon(); + globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(e.Polygon); + } /// /// 全选按钮事件处理 @@ -145,14 +129,7 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); } } /// @@ -174,83 +151,108 @@ /// private void pipeDiameterStatis(GSOGeoPolygon3D polygon) { + try { - dic = new Dictionary(); + dic.Clear(); dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) + + FeatureStatisticsService featureService = new FeatureStatisticsService(); + + for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + + for (int j = 0; j < clbmaterials.CheckedItems.Count; j++) { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - List lstDiameter = new List(); + FeaturesClassfyResult featureResult = featureService.groupPipeByMaterial(polygon, layer, clbmaterials.CheckedItems[j].ToString()); + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layer.Caption; + row.Cells["材质"].Value = featureResult.groupFieldValue; + row.Cells["条数"].Value = featureResult.ncount; + row.Cells["总长度"].Value = Math.Round(featureResult.sum); - for (int j = 0; j < clbmaterials.CheckedItems.Count; j++) - { - if (!lstDiameter.Contains(clbmaterials.CheckedItems[j].ToString())) - { - lstDiameter.Add(clbmaterials.CheckedItems[j].ToString()); - } - } - //lstDiameter.Sort(); - if (lstDiameter.Count > 0) - { - for (int m = 0; m < lstDiameter.Count; m++) - { - double totalLength = 0.00; - int ncount = 0; - for (int j = 0; j < feats.Length; j++) - { - if (lstDiameter[m] != "无") - { - if (feats[j].GetFieldAsString("材质") == lstDiameter[m]) - { - GSOGeoPolyline3D line = feats[j].Geometry as GSOGeoPolyline3D; - if (line != null) - { - double length = line.GetSpaceLength(true, 6378137); - totalLength += length; - ncount += 1; - } - } - } - else - { - if (feats[j].GetFieldAsString("材质") == "") - { - GSOGeoPolyline3D line = feats[j].Geometry as GSOGeoPolyline3D; - if (line != null) - { - double length = line.GetSpaceLength(true, 6378137); - totalLength += length; - ncount += 1; - } - } - } - } - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["材质"].Value = lstDiameter[m]; - row.Cells["条数"].Value = ncount; - row.Cells["总长度"].Value = Math.Round(totalLength); - - dic.Add(layer.Caption + "," + row.Cells["材质"].Value.ToString(), ncount); - } - } + dic.Add(layer.Caption + "," + row.Cells["材质"].Value.ToString(), featureResult.ncount); } - } - else - { - MessageBox.Show("请选择图层!"); + + } + + //if (clbPipeLine.CheckedItems.Count > 0) + //{ + // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) + // { + // GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + // GSOFeatureLayer flayer = layer as GSOFeatureLayer; + // GSOFeatures feats = new GSOFeatures(); + // if (polygon == null) + // feats = flayer.GetAllFeatures(); + // else + // feats = flayer.FindFeaturesInPolygon(polygon, false); + // List lstDiameter = new List(); + + // for (int j = 0; j < clbmaterials.CheckedItems.Count; j++) + // { + // if (!lstDiameter.Contains(clbmaterials.CheckedItems[j].ToString())) + // { + // lstDiameter.Add(clbmaterials.CheckedItems[j].ToString()); + // } + // } + // //lstDiameter.Sort(); + // if (lstDiameter.Count > 0) + // { + // for (int m = 0; m < lstDiameter.Count; m++) + // { + // double totalLength = 0.00; + // int ncount = 0; + // for (int j = 0; j < feats.Length; j++) + // { + // if (lstDiameter[m] != "无") + // { + // if (feats[j].GetFieldAsString("材质") == lstDiameter[m]) + // { + // GSOGeoPolyline3D line = feats[j].Geometry as GSOGeoPolyline3D; + // if (line != null) + // { + // double length = line.GetSpaceLength(true, 6378137); + // totalLength += length; + // ncount += 1; + // } + // } + // } + // else + // { + // if (feats[j].GetFieldAsString("材质") == "") + // { + // GSOGeoPolyline3D line = feats[j].Geometry as GSOGeoPolyline3D; + // if (line != null) + // { + // double length = line.GetSpaceLength(true, 6378137); + // totalLength += length; + // ncount += 1; + // } + // } + // } + // } + // DataGridViewRow row = new DataGridViewRow(); + // int index = dataGridViewX1.Rows.Add(row); + // row = dataGridViewX1.Rows[index]; + // row.Cells["图层名称"].Value = layer.Caption; + // row.Cells["材质"].Value = lstDiameter[m]; + // row.Cells["条数"].Value = ncount; + // row.Cells["总长度"].Value = Math.Round(totalLength); + + // dic.Add(layer.Caption + "," + row.Cells["材质"].Value.ToString(), ncount); + // } + // } + // } + //} + //else + //{ + // MessageBox.Show("请选择图层!"); + //} showPipeWidget(); } catch (Exception ex) @@ -339,6 +341,27 @@ } } } + + /// + /// 全区域分类汇总 + /// + /// + /// + private void buttonX8_Click(object sender, EventArgs e) + { + if (clbPipeLine.CheckedItems.Count == 0) + { + MessageBox.Show("请选择图层!"); + return; + } + if (clbmaterials.CheckedItems.Count == 0) + { + MessageBox.Show("请选择材质类型!"); + return; + } + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(null); + } /// /// 绘制区域分类汇总 /// @@ -346,24 +369,19 @@ /// private void buttonX9_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - if (clbmaterials.CheckedItems.Count > 0) - { - Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); - globeControl1.Globe.Action = EnumAction3D.TrackPolygon; - globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; - globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - } - else - { - MessageBox.Show("请选择材质类型!"); - } - } - else - { + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层!"); + return; } + if (clbmaterials.CheckedItems.Count == 0) + { + MessageBox.Show("请选择材质类型!"); + return; + } + Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); + globeControl1.Globe.Action = EnumAction3D.TrackPolygon; + globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; + globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); } /// @@ -458,30 +476,7 @@ MessageBox.Show("统计结果为空,请重新统计之后再导出Excel!", "提示"); } } - /// - /// 全区域分类汇总 - /// - /// - /// - private void buttonX8_Click(object sender, EventArgs e) - { - if (clbPipeLine.CheckedItems.Count > 0) - { - if (clbmaterials.CheckedItems.Count > 0) - { - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(null); - } - else - { - MessageBox.Show("请选择材质类型!"); - } - } - else - { - MessageBox.Show("请选择图层!"); - } - } + /// /// 全选 /// @@ -503,14 +498,8 @@ { for (int i = 0; i < this.clbmaterials.Items.Count; i++) { - if (clbmaterials.GetItemChecked(i) == true) - { - this.clbmaterials.SetItemChecked(i, false); - } - else - { - this.clbmaterials.SetItemChecked(i, true); - } + this.clbmaterials.SetItemChecked(i, !clbmaterials.GetItemChecked(i)); + } } /// @@ -525,19 +514,20 @@ clbmaterials.SetItemChecked(i, false); } } - + + //限制只能选择一个图层 private void clbPipeLine_ItemCheck(object sender, ItemCheckEventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) + if (clbPipeLine.CheckedItems.Count == 0) return; + + for (int i = 0; i < clbPipeLine.Items.Count; i++) { - for (int i = 0; i < clbPipeLine.Items.Count; i++) + if (i != e.Index) { - if (i != e.Index) - { - this.clbPipeLine.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked); - } + this.clbPipeLine.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked); } } + } } diff --git a/FrmAccessoriesgather.cs b/FrmAccessoriesgather.cs index 5187a3a..36c014e 100644 --- a/FrmAccessoriesgather.cs +++ b/FrmAccessoriesgather.cs @@ -17,7 +17,8 @@ { GSOGlobeControl globeControl1; List instrumenLayerNames; - string[] accessStrs = null; + //string[] accessStrs = null; + Dictionary dic = new Dictionary(); static FrmAccessoriesgather frm; public static void ShowForm(GSOGlobeControl globeControl, List pipeLayers, int visibleId) @@ -46,9 +47,7 @@ buttonX9.Visible = false; buttonX8.Visible = true; buttonX8.Location = buttonX9.Location; - } - if (visibleId == 1) - { + }else{ buttonX8.Visible = false; buttonX9.Visible = true; } @@ -67,22 +66,7 @@ clbPipeLine2.Items.Add(instrumenLayerNames[i]); } } - //if (Utility.listPipelineType != null) - //{ - // List list = Utility.listPipelineType; - // string temptype = ""; - - // for (int i = 0; i < list.Count; i++) - // { - // PipelineType pipelineType = Utility.listPipelineType[i]; - // if (temptype != pipelineType.type) - // { - // //clbPipeLine.Items.Add(pipelineType.type); - // clbPipeLine2.Items.Add(pipelineType.type); - // temptype = pipelineType.type; - // } - // } - //} + } @@ -167,14 +151,8 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); + } } /// @@ -189,118 +167,74 @@ clbPipeLine.SetItemChecked(i, false); } } - Dictionary dic = new Dictionary(); - private void pipeDiameterStatis(GSOGeoPolygon3D polygon) - { - try - { - dic = new Dictionary(); - dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) - { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - int ncount = 0; - ncount = feats.Length; - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["数量"].Value = ncount; - dic.Add(layer.Caption, ncount); - } - } - else - { - MessageBox.Show("请选择图层!"); - } + + //private void pipeDiameterStatis(GSOGeoPolygon3D polygon) + //{ + // try + // { + // dic = new Dictionary(); + // dataGridViewX1.Rows.Clear(); + // if (clbPipeLine.CheckedItems.Count > 0) + // { + // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) + // { + // GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + // GSOFeatureLayer flayer = layer as GSOFeatureLayer; + // GSOFeatures feats = new GSOFeatures(); + // if (polygon == null) + // feats = flayer.GetAllFeatures(); + // else + // feats = flayer.FindFeaturesInPolygon(polygon, false); + // int ncount = 0; + // ncount = feats.Length; + // DataGridViewRow row = new DataGridViewRow(); + // int index = dataGridViewX1.Rows.Add(row); + // row = dataGridViewX1.Rows[index]; + // row.Cells["图层名称"].Value = layer.Caption; + // row.Cells["数量"].Value = ncount; + // dic.Add(layer.Caption, ncount); + // } + // } + // else + // { + // MessageBox.Show("请选择图层!"); + // } - showPipeWidget(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - LogError.PublishError(ex); - } - } + // showPipeWidget(); + // } + // catch (Exception ex) + // { + // MessageBox.Show(ex.Message); + // LogError.PublishError(ex); + // } + //} private void pipeDiameterStatisNew(GSOGeoPolygon3D polygon, string layertype) { try { - //根据管线类型找到其附属物 - accessStrs = Utility.getAccStrsByLayer(layertype); - if (accessStrs != null) - { + FeatureStatisticsService featureService = new FeatureStatisticsService(); + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(layertype); + List accessoriesResult = featureService.groupAccessories(polygon, layer); - dic = new Dictionary(); - dataGridViewX1.Rows.Clear(); - - int ncount = 0; - string accessValue = ""; - - //if (clbPipeLine.CheckedItems.Count > 0) - //{ - // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - // { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine2.Text); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - for (int j = 0; j < accessStrs.Length; j++) - { - if (polygon == null) - { - feats = flayer.GetFeatureByFieldValue("附属物名称", accessStrs[j], true); - ncount = feats.Length; - } - else - { - feats = flayer.FindFeaturesInPolygon(polygon, false); - - GSOFeatures newfeats = flayer.FindFeaturesInPolygon(polygon, false); - newfeats.RemoveAll(); - //过滤 - for (int n= 0; n < feats.Length; n++) - { - GSOFeature feat = feats[n]; - - if (feat.GetFieldAsString("附属物名称").Contains(accessStrs[j])) - { - newfeats.Add(feat); - } - } - ncount = newfeats.Length; - } - - //accessValue = clbPipeLine.CheckedItems[i].ToString() + accessStrs[j]; - accessValue = accessStrs[j]; - - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = accessValue;// layer.Caption; - row.Cells["数量"].Value = ncount; - dic.Add(accessValue, ncount); - } - // } - //} - //else - //{ - // MessageBox.Show("请选择图层!"); - //} - - showPipeWidget(); - } - else + if (accessoriesResult == null || accessoriesResult.Count == 0) { MessageBox.Show("该图层没有附属物"); } + dataGridViewX1.Rows.Clear(); + dic.Clear(); + foreach (FeaturesClassfyResult accessoryResult in accessoriesResult) + { + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + string layerName = accessoryResult.layerName; + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layerName;// layer.Caption; + row.Cells["数量"].Value = accessoryResult.ncount; + dic.Add(layerName, accessoryResult.ncount); + + } + showPipeWidget(); + } catch (Exception ex) { diff --git a/FrmpipeDeepstatis.cs b/FrmpipeDeepstatis.cs index 607ea65..879801a 100644 --- a/FrmpipeDeepstatis.cs +++ b/FrmpipeDeepstatis.cs @@ -19,19 +19,17 @@ List pipeLayerNames; static FrmpipeDeepstatis frm; + Dictionary dic = new Dictionary(); + public static void ShowForm(GSOGlobeControl globeControl, List pipeLayers, int visibleId) { if (frm == null) { frm = new FrmpipeDeepstatis(globeControl, pipeLayers, visibleId); frm.Show(globeControl.Parent); - } - else + }else if (frm.WindowState == FormWindowState.Minimized) { - if (frm.WindowState == FormWindowState.Minimized) - { - frm.WindowState = FormWindowState.Normal; - } + frm.WindowState = FormWindowState.Normal; } } @@ -45,8 +43,7 @@ buttonX9.Visible = false; buttonX8.Visible = true; buttonX8.Location = buttonX9.Location; - } - if (visibleId == 1) + }else if (visibleId == 1) { buttonX8.Visible = false; buttonX9.Visible = true; @@ -59,50 +56,47 @@ /// private void buttonX5_Click(object sender, EventArgs e) { - if (dataGridViewX2.SelectedCells.Count > 0) + if (dataGridViewX2.SelectedCells.Count == 0 || lstpipeRadius.SelectedItem == null) return; + + DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; + + if (row.Cells["上限"].Value == null) { - DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; - if (lstpipeRadius.SelectedItem != null) + row.Cells["下限"].Value = lstpipeRadius.SelectedItem.ToString(); + } + else + { + double downRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); + double upRadius = Convert.ToDouble(row.Cells["上限"].Value); + if (upRadius >= downRadius) { - if (row.Cells["上限"].Value == null) - { - row.Cells["下限"].Value = lstpipeRadius.SelectedItem.ToString(); - } - else - { - double downRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); - double upRadius = Convert.ToDouble(row.Cells["上限"].Value); - if (upRadius >= downRadius) - { - row.Cells["下限"].Value = downRadius.ToString(); - } - } + row.Cells["下限"].Value = downRadius.ToString(); } } - } + + } + //上限值设置 private void buttonX4_Click(object sender, EventArgs e) { - if (dataGridViewX2.SelectedCells.Count > 0) + if (dataGridViewX2.SelectedCells.Count == 0 || lstpipeRadius.SelectedItem == null) return; + + DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; + + if (row.Cells["下限"].Value != null && row.Cells["下限"].Value.ToString() != "") { - DataGridViewRow row = dataGridViewX2.Rows[dataGridViewX2.SelectedCells[0].RowIndex]; - if (lstpipeRadius.SelectedItem != null) + double downRadius = Convert.ToDouble(row.Cells["下限"].Value); + double upRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); + if (upRadius >= downRadius) { - if (row.Cells["下限"].Value != null && row.Cells["下限"].Value.ToString() != "") - { - double downRadius = Convert.ToDouble(row.Cells["下限"].Value); - double upRadius = Convert.ToDouble(lstpipeRadius.SelectedItem.ToString()); - if (upRadius >= downRadius) - { - row.Cells["上限"].Value = upRadius.ToString(); - } - } - else - { - row.Cells["上限"].Value = lstpipeRadius.SelectedItem.ToString(); - } + row.Cells["上限"].Value = upRadius.ToString(); } } + else + { + row.Cells["上限"].Value = lstpipeRadius.SelectedItem.ToString(); + } + } /// /// 添加行按钮事件处理 @@ -128,7 +122,7 @@ dataGridViewX2.Rows.Remove(row); } } - Dictionary dic = new Dictionary(); + /// /// 给表格绑定数据 /// @@ -137,90 +131,121 @@ { try { - dic = new Dictionary(); + dic.Clear() ; dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) + FeatureStatisticsService service = new FeatureStatisticsService(); + for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) { - if (dataGridViewX2.Rows.Count > 0) - { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - for (int j = 0; j < dataGridViewX2.Rows.Count; j++) - { - double totalLength = 0.00; - int ncount = 0; - for (int m = 0; m < feats.Length; m++) - { - GSOFeature feat = feats[m]; - float radius = feat.GetFieldAsFloat("起始埋深"); - bool upCompare = true; - bool downCompare = true; - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["下限"].Value.ToString() != "") - { - if (radius >= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["下限"].Value)) - { - downCompare = true; - } - else - downCompare = false; - } - } - if (dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["上限"].Value.ToString() != "") - { - if (radius <= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["上限"].Value)) - { - upCompare = true; - } - else - upCompare = false; - } - } - if (upCompare && downCompare) - { - GSOGeoPolyline3D line = feat.Geometry as GSOGeoPolyline3D; - double length = line.GetSpaceLength(true, 6378137); - totalLength += length; - ncount += 1; - } - } - } - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["埋深范围"].Value = dataGridViewX2.Rows[j].Cells["下限"].Value + "-" + dataGridViewX2.Rows[j].Cells["上限"].Value; - row.Cells["条数"].Value = ncount; - row.Cells["总长度"].Value =Math.Round(totalLength,2); - dic.Add(layer.Caption + "," + row.Cells["埋深范围"].Value.ToString()+","+row.Cells["总长度"].Value.ToString(), ncount); - } - } - } - } - else + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + for (int j = 0; j < dataGridViewX2.Rows.Count; j++) { - MessageBox.Show("请添加分段!"); + object tempUp = dataGridViewX2.Rows[j].Cells["上限"].Value; + double? upLimit = null; + if (tempUp != null) upLimit = Convert.ToDouble(tempUp); + + object tempDown = dataGridViewX2.Rows[j].Cells["下限"].Value; + double? downLimit = null; + if (tempDown != null) downLimit = Convert.ToDouble(tempDown); + //Double downLimit = Convert.ToDouble(dataGridViewX2.Rows[j].Cells["下限"].Value); + if (upLimit == null && downLimit == null) continue;//空行过滤 + //获取符合条件的管线 + FeaturesClassfyResult result = service.getPipesInfoByValueSection(polygon, layer, downLimit, upLimit, "起始埋深"); + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layer.Caption; + row.Cells["埋深范围"].Value = result.groupFieldValue; + row.Cells["条数"].Value = result.ncount; + row.Cells["总长度"].Value = Math.Round(result.sum, 2); + dic.Add(layer.Caption + "," + row.Cells["埋深范围"].Value.ToString() + "," + row.Cells["总长度"].Value.ToString(), result.ncount); + + } } - else - { - MessageBox.Show("请选择图层!"); - } + + //if (clbPipeLine.CheckedItems.Count > 0) + //{ + // if (dataGridViewX2.Rows.Count > 0) + // { + // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) + // { + // GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + // GSOFeatureLayer flayer = layer as GSOFeatureLayer; + // GSOFeatures feats = new GSOFeatures(); + // if (polygon == null) + // feats = flayer.GetAllFeatures(); + // else + // feats = flayer.FindFeaturesInPolygon(polygon, false); + // for (int j = 0; j < dataGridViewX2.Rows.Count; j++) + // { + // double totalLength = 0.00; + // int ncount = 0; + // for (int m = 0; m < feats.Length; m++) + // { + // GSOFeature feat = feats[m]; + // float radius = feat.GetFieldAsFloat("起始埋深"); + // bool upCompare = true; + // bool downCompare = true; + // if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) + // { + // if (dataGridViewX2.Rows[j].Cells["下限"].Value != null) + // { + // if (dataGridViewX2.Rows[j].Cells["下限"].Value.ToString() != "") + // { + // if (radius >= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["下限"].Value)) + // { + // downCompare = true; + // } + // else + // downCompare = false; + // } + // } + // if (dataGridViewX2.Rows[j].Cells["上限"].Value != null) + // { + // if (dataGridViewX2.Rows[j].Cells["上限"].Value.ToString() != "") + // { + // if (radius <= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["上限"].Value)) + // { + // upCompare = true; + // } + // else + // upCompare = false; + // } + // } + // if (upCompare && downCompare) + // { + // GSOGeoPolyline3D line = feat.Geometry as GSOGeoPolyline3D; + // double length = line.GetSpaceLength(true, 6378137); + // totalLength += length; + // ncount += 1; + // } + // } + // } + // if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) + // { + // DataGridViewRow row = new DataGridViewRow(); + // int index = dataGridViewX1.Rows.Add(row); + // row = dataGridViewX1.Rows[index]; + // row.Cells["图层名称"].Value = layer.Caption; + // row.Cells["埋深范围"].Value = dataGridViewX2.Rows[j].Cells["下限"].Value + "-" + dataGridViewX2.Rows[j].Cells["上限"].Value; + // row.Cells["条数"].Value = ncount; + // row.Cells["总长度"].Value =Math.Round(totalLength,2); + + // dic.Add(layer.Caption + "," + row.Cells["埋深范围"].Value.ToString()+","+row.Cells["总长度"].Value.ToString(), ncount); + // } + // } + // } + // } + // else + // { + // MessageBox.Show("请添加分段!"); + // } + //} + //else + //{ + // MessageBox.Show("请选择图层!"); + //} showPipeWidget(); } catch (Exception ex) @@ -234,92 +259,7 @@ /// private void showPipeWidget() { - /* - if (chart1.Series.Count > 0) - { - chart1.Series.Clear(); - } - if (chart1.Legends.Count > 0) - { - chart1.Legends.Clear(); - } - - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - chart1.Series.Add(clbPipeLine.CheckedItems[i].ToString()); - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - if (layer != null && layer is GSOFeatureLayer) - { - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures features = flayer.GetAllFeatures(); - if (features.Length > 0) - { - if (features[0] != null && features[0].Geometry != null && features[0].Geometry.Type == EnumGeometryType.GeoPolyline3D) - { - GSOGeoPolyline3D p3d = features[0].Geometry as GSOGeoPolyline3D; - if (p3d.Style != null && p3d.Style is GSOPipeLineStyle3D) - { - GSOPipeLineStyle3D ps3d = p3d.Style as GSOPipeLineStyle3D; - chart1.Series[i].Color = ps3d.LineColor; - } - } - } - } - chart1.Legends.Add(clbPipeLine.CheckedItems[i].ToString()); - chart1.Legends[i].Docking = Docking.Top; - - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].IsTextAutoFit = true; - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].LegendStyle = LegendStyle.Table; - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].DockedToChartArea = "ChartArea1"; - chart1.Legends[clbPipeLine.CheckedItems[i].ToString()].BackColor = Color.Transparent; - chart1.ChartAreas["ChartArea1"].AxisY.IsLabelAutoFit = false; - - } - - // Set axis title - chart1.ChartAreas["ChartArea1"].AxisX.Title = "埋深范围(米)"; - chart1.ChartAreas["ChartArea1"].AxisY.Title = "管线数量"; - chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; - LabelStyle labeStyleAxisX = new LabelStyle(); - labeStyleAxisX.Angle = -45; - labeStyleAxisX.Enabled = true; - chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle = labeStyleAxisX; - - Dictionary dic1 = new Dictionary(); - List dicLength = new List(); - for (int j = 0; j < chart1.Series.Count; j++) - { - dic1 = new Dictionary(); - dicLength = new List(); - foreach (string key in dic.Keys) - { - if (key.Contains(chart1.Series[j].Name)) - { - dic1.Add(key.Split(',')[1].ToString(), dic[key]); - dicLength.Add(key.Split(',')[2].ToString()); - } - } - chart1.Series[j].ChartType = SeriesChartType.Column; - - chart1.Series[j]["DrawingStyle"] = "Cylinder"; - - //chart1.Series[j].IsValueShownAsLabel = true; - - chart1.Series[j].Points.DataBindXY(dic1.Keys, dic1.Values); - for (int m = 0; m < dic1.Values.Count; m++) - { - if (chart1.Series[j].Points[m].YValues[0].ToString() != "0") - { - chart1.Series[j].Points[m].Label = chart1.Series[j].Points[m].YValues[0].ToString(); - - } - if (dicLength[m] != "0") - { - chart1.Series[j].Points[m].ToolTip ="长度:"+dicLength[m]; - } - } - } - * */ + chart1.Series.Clear(); chart1.Series.Add("管线"); @@ -367,19 +307,29 @@ /// void globeControl1_TrackPolygonEndEvent(object sender, TrackPolygonEndEventArgs e) { - if (e.Polygon != null) + if (clbPipeLine.CheckedItems.Count == 0) { - GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; - polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; - GSOFeature feature = new GSOFeature(); - feature.Geometry = polygon; - feature.Name = "trackPolygon"; - globeControl1.Globe.MemoryLayer.AddFeature(feature); - globeControl1.Globe.ClearLastTrackPolygon(); - globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(e.Polygon); + MessageBox.Show("请选择图层"); + return; } + if (dataGridViewX2.Rows.Count == 0) + { + MessageBox.Show("请添加分段"); + return; + } + if (e.Polygon == null) return; + + GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; + polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; + GSOFeature feature = new GSOFeature(); + feature.Geometry = polygon; + feature.Name = "trackPolygon"; + globeControl1.Globe.MemoryLayer.AddFeature(feature); + globeControl1.Globe.ClearLastTrackPolygon(); + globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(e.Polygon); + } /// /// 全选 @@ -402,14 +352,8 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); + } } /// @@ -431,21 +375,16 @@ /// private void buttonX8_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - if (dataGridViewX2.Rows.Count > 0) - { - pipeDiameterStatis(null); - } - else - { - MessageBox.Show("请添加分段"); - } - } - else - { + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层"); - } + return; + } + if (dataGridViewX2.Rows.Count == 0) + { + MessageBox.Show("请添加分段"); + return; + } + pipeDiameterStatis(null); } /// /// 绘制区域分段统计 @@ -454,24 +393,21 @@ /// private void buttonX9_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - if (dataGridViewX2.Rows.Count > 0) - { - Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); - globeControl1.Globe.Action = EnumAction3D.TrackPolygon; - globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; - globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - } - else - { - MessageBox.Show("请添加分段"); - } - } - else + + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层"); + return; } + if (dataGridViewX2.Rows.Count == 0) + { + MessageBox.Show("请添加分段"); + return; + } + Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); + globeControl1.Globe.Action = EnumAction3D.TrackPolygon; + globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; + globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); } diff --git a/FrmpipeDiametergather.cs b/FrmpipeDiametergather.cs index 8c3b147..36467df 100644 --- a/FrmpipeDiametergather.cs +++ b/FrmpipeDiametergather.cs @@ -19,6 +19,8 @@ List pipeLayerNames; static FrmpipeDiametergather frm; + Dictionary dic = new Dictionary(); + public static void ShowForm(GSOGlobeControl globeControl, List pipeLayers, int visibleId) { if (frm == null) @@ -26,12 +28,9 @@ frm = new FrmpipeDiametergather(globeControl, pipeLayers, visibleId); frm.Show(globeControl.Parent); } - else + else if (frm.WindowState == FormWindowState.Minimized) { - if (frm.WindowState == FormWindowState.Minimized) - { - frm.WindowState = FormWindowState.Normal; - } + frm.WindowState = FormWindowState.Normal; } } @@ -45,8 +44,7 @@ buttonX9.Visible = false; buttonX8.Visible = true; buttonX8.Location = buttonX9.Location; - } - if (visibleId == 1) + }else if (visibleId == 1) { buttonX8.Visible = false; buttonX9.Visible = true; @@ -74,19 +72,23 @@ /// void globeControl1_TrackPolygonEndEvent(object sender, TrackPolygonEndEventArgs e) { - if (e.Polygon != null) + if (e.Polygon == null) return; + if (clbPipeLine.CheckedItems.Count == 0) { - GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; - polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; - GSOFeature feature = new GSOFeature(); - feature.Geometry = polygon; - feature.Name = "trackPolygon"; - globeControl1.Globe.MemoryLayer.AddFeature(feature); - globeControl1.Globe.ClearLastTrackPolygon(); - globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(e.Polygon); + MessageBox.Show("请选择图层!"); + return; } + GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; + polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; + GSOFeature feature = new GSOFeature(); + feature.Geometry = polygon; + feature.Name = "trackPolygon"; + globeControl1.Globe.MemoryLayer.AddFeature(feature); + globeControl1.Globe.ClearLastTrackPolygon(); + globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(e.Polygon); + } /// /// 全选 @@ -109,14 +111,8 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); + } } /// @@ -138,15 +134,13 @@ /// private void buttonX8_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(null); - } - else - { + + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层!"); - } + return; + } + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(null); } /// /// 绘制区域分类汇总 @@ -155,21 +149,20 @@ /// private void buttonX9_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); - globeControl1.Globe.Action = EnumAction3D.TrackPolygon; - globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; - globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - } - else + + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层!"); + return; } + Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); + globeControl1.Globe.Action = EnumAction3D.TrackPolygon; + globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; + globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); } - Dictionary dic = new Dictionary(); + /// /// 给表格绑定数据 /// @@ -178,62 +171,27 @@ { try { - dic = new Dictionary(); + dic.Clear() ; dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) + FeatureStatisticsService service = new FeatureStatisticsService(); + for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - List lstDiameter = new List(); - - for (int j = 0; j < feats.Length; j++) - { - if (!lstDiameter.Contains(feats[j].GetFieldAsFloat("管径_毫米"))) - { - lstDiameter.Add(feats[j].GetFieldAsFloat("管径_毫米")); - } - } - lstDiameter.Sort(); - if (lstDiameter.Count > 0) - { - for (int m = 0; m < lstDiameter.Count; m++) - { - double totalLength = 0.00; - int ncount = 0; - for (int j = 0; j < feats.Length; j++) - { - if (feats[j].GetFieldAsFloat("管径_毫米") == lstDiameter[m]) - { - GSOGeoPolyline3D line = feats[j].Geometry as GSOGeoPolyline3D; - double length = line.GetSpaceLength(true, 6378137); - totalLength += length; - ncount += 1; - } - } - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["管径"].Value = lstDiameter[m]; - row.Cells["条数"].Value = ncount; - row.Cells["总长度"].Value =Math.Round(totalLength,2); - - dic.Add(layer.Caption + "," + row.Cells["管径"].Value.ToString(), ncount); - } - } + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + List results = service.groupPipeByDiameter(polygon,layer); + + foreach(FeaturesClassfyResult result in results){ + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layer.Caption; + row.Cells["管径"].Value = result.groupFieldValue; + row.Cells["条数"].Value = result.ncount; + row.Cells["总长度"].Value = Math.Round(result.sum, 2); + dic.Add(layer.Caption + "," + row.Cells["管径"].Value.ToString(), result.ncount); } + } - else - { - MessageBox.Show("请选择图层!"); - } + showPipeWidget(); } catch (Exception ex) @@ -442,19 +400,19 @@ globeControl1.Globe.MemoryLayer.RemoveAllFeature(); } - + //限制只能选择一个 private void clbPipeLine_ItemCheck(object sender, ItemCheckEventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) + if (clbPipeLine.CheckedItems.Count == 0) return; + + for (int i = 0; i < clbPipeLine.Items.Count; i++) { - for (int i = 0; i < clbPipeLine.Items.Count; i++) + if (i != e.Index) { - if (i != e.Index) - { - this.clbPipeLine.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked); - } + this.clbPipeLine.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked); } } + } diff --git a/FrmpipeMaterialGather.cs b/FrmpipeMaterialGather.cs index 5b2e1c7..b7ab1d2 100644 --- a/FrmpipeMaterialGather.cs +++ b/FrmpipeMaterialGather.cs @@ -26,12 +26,9 @@ frm = new FrmpipeMaterialGather(globeControl, pipeLayers, visibleId); frm.Show(globeControl.Parent); } - else + else if(frm.WindowState == FormWindowState.Minimized) { - if (frm.WindowState == FormWindowState.Minimized) - { - frm.WindowState = FormWindowState.Normal; - } + frm.WindowState = FormWindowState.Normal; } } @@ -45,8 +42,7 @@ buttonX9.Visible = false; buttonX8.Visible = true; buttonX8.Location = buttonX9.Location; - } - if (visibleId == 1) + }else if (visibleId == 1) { buttonX8.Visible = false; buttonX9.Visible = true; @@ -59,47 +55,31 @@ /// private void FrmpipeMaterialGather_Load(object sender, EventArgs e) { - //for (int i = globeControl1.Globe.Layers.Count - 1; i >= 0; i--) - //{ + for (int i = 0; i < pipeLayerNames.Count; i++) { - //GSOLayer layer = globeControl1.Globe.Layers[i]; clbPipeLine.Items.Add(pipeLayerNames[i]); - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(pipeLayerNames[i]); - if (layer.Dataset != null && layer.Dataset.IsFeatureDataset) - { - string name = layer.Name; + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(pipeLayerNames[i]); + if (layer.Dataset == null || !layer.Dataset.IsFeatureDataset || layer.Type != EnumLayerType.FeatureLayer) continue; - if (layer.Type == EnumLayerType.FeatureLayer)//if (layer.Type == EnumLayerType.FeatureLayer && !name.Contains("\\") && layer.Caption.Contains("管线") && !layer.Caption.Contains("弯头")) + string name = layer.Name; + GSOFeatureLayer flayer = layer as GSOFeatureLayer; + GSOFeatures feats = flayer.GetAllFeatures(); + + for (int j = 0; j < feats.Length; j++) + { + if (clbmaterials.Items.Contains(feats[j].GetFieldAsString("材质"))) continue; + + if (feats[j].GetFieldAsString("材质") == "" && !clbmaterials.Items.Contains("无")) { - /* - if (!clbPipeLine.Items.Contains(layer.Caption)) - { - clbPipeLine.Items.Add(layer.Caption); - } - */ - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - feats = flayer.GetAllFeatures(); - for (int j = 0; j < feats.Length; j++) - { - if (!clbmaterials.Items.Contains(feats[j].GetFieldAsString("材质"))) - { - if (feats[j].GetFieldAsString("材质") == "") - { - if (!clbmaterials.Items.Contains("无")) - { - clbmaterials.Items.Add("无"); - } - } - else - { - clbmaterials.Items.Add(feats[j].GetFieldAsString("材质")); - } - } - } + clbmaterials.Items.Add("无"); + } + else + { + clbmaterials.Items.Add(feats[j].GetFieldAsString("材质")); } } + } } @@ -110,19 +90,23 @@ /// void globeControl1_TrackPolygonEndEvent(object sender, TrackPolygonEndEventArgs e) { - if (e.Polygon != null) + if (e.Polygon == null) return; + if (clbPipeLine.CheckedItems.Count == 0) { - GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; - polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; - GSOFeature feature = new GSOFeature(); - feature.Geometry = polygon; - feature.Name = "trackPolygon"; - globeControl1.Globe.MemoryLayer.AddFeature(feature); - globeControl1.Globe.ClearLastTrackPolygon(); - globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(e.Polygon); + MessageBox.Show("请选择图层!"); + return; } + GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; + polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; + GSOFeature feature = new GSOFeature(); + feature.Geometry = polygon; + feature.Name = "trackPolygon"; + globeControl1.Globe.MemoryLayer.AddFeature(feature); + globeControl1.Globe.ClearLastTrackPolygon(); + globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(e.Polygon); + } /// /// 全选按钮事件处理 @@ -145,14 +129,7 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); } } /// @@ -174,83 +151,108 @@ /// private void pipeDiameterStatis(GSOGeoPolygon3D polygon) { + try { - dic = new Dictionary(); + dic.Clear(); dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) + + FeatureStatisticsService featureService = new FeatureStatisticsService(); + + for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + + for (int j = 0; j < clbmaterials.CheckedItems.Count; j++) { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - List lstDiameter = new List(); + FeaturesClassfyResult featureResult = featureService.groupPipeByMaterial(polygon, layer, clbmaterials.CheckedItems[j].ToString()); + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layer.Caption; + row.Cells["材质"].Value = featureResult.groupFieldValue; + row.Cells["条数"].Value = featureResult.ncount; + row.Cells["总长度"].Value = Math.Round(featureResult.sum); - for (int j = 0; j < clbmaterials.CheckedItems.Count; j++) - { - if (!lstDiameter.Contains(clbmaterials.CheckedItems[j].ToString())) - { - lstDiameter.Add(clbmaterials.CheckedItems[j].ToString()); - } - } - //lstDiameter.Sort(); - if (lstDiameter.Count > 0) - { - for (int m = 0; m < lstDiameter.Count; m++) - { - double totalLength = 0.00; - int ncount = 0; - for (int j = 0; j < feats.Length; j++) - { - if (lstDiameter[m] != "无") - { - if (feats[j].GetFieldAsString("材质") == lstDiameter[m]) - { - GSOGeoPolyline3D line = feats[j].Geometry as GSOGeoPolyline3D; - if (line != null) - { - double length = line.GetSpaceLength(true, 6378137); - totalLength += length; - ncount += 1; - } - } - } - else - { - if (feats[j].GetFieldAsString("材质") == "") - { - GSOGeoPolyline3D line = feats[j].Geometry as GSOGeoPolyline3D; - if (line != null) - { - double length = line.GetSpaceLength(true, 6378137); - totalLength += length; - ncount += 1; - } - } - } - } - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["材质"].Value = lstDiameter[m]; - row.Cells["条数"].Value = ncount; - row.Cells["总长度"].Value = Math.Round(totalLength); - - dic.Add(layer.Caption + "," + row.Cells["材质"].Value.ToString(), ncount); - } - } + dic.Add(layer.Caption + "," + row.Cells["材质"].Value.ToString(), featureResult.ncount); } - } - else - { - MessageBox.Show("请选择图层!"); + + } + + //if (clbPipeLine.CheckedItems.Count > 0) + //{ + // for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) + // { + // GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + // GSOFeatureLayer flayer = layer as GSOFeatureLayer; + // GSOFeatures feats = new GSOFeatures(); + // if (polygon == null) + // feats = flayer.GetAllFeatures(); + // else + // feats = flayer.FindFeaturesInPolygon(polygon, false); + // List lstDiameter = new List(); + + // for (int j = 0; j < clbmaterials.CheckedItems.Count; j++) + // { + // if (!lstDiameter.Contains(clbmaterials.CheckedItems[j].ToString())) + // { + // lstDiameter.Add(clbmaterials.CheckedItems[j].ToString()); + // } + // } + // //lstDiameter.Sort(); + // if (lstDiameter.Count > 0) + // { + // for (int m = 0; m < lstDiameter.Count; m++) + // { + // double totalLength = 0.00; + // int ncount = 0; + // for (int j = 0; j < feats.Length; j++) + // { + // if (lstDiameter[m] != "无") + // { + // if (feats[j].GetFieldAsString("材质") == lstDiameter[m]) + // { + // GSOGeoPolyline3D line = feats[j].Geometry as GSOGeoPolyline3D; + // if (line != null) + // { + // double length = line.GetSpaceLength(true, 6378137); + // totalLength += length; + // ncount += 1; + // } + // } + // } + // else + // { + // if (feats[j].GetFieldAsString("材质") == "") + // { + // GSOGeoPolyline3D line = feats[j].Geometry as GSOGeoPolyline3D; + // if (line != null) + // { + // double length = line.GetSpaceLength(true, 6378137); + // totalLength += length; + // ncount += 1; + // } + // } + // } + // } + // DataGridViewRow row = new DataGridViewRow(); + // int index = dataGridViewX1.Rows.Add(row); + // row = dataGridViewX1.Rows[index]; + // row.Cells["图层名称"].Value = layer.Caption; + // row.Cells["材质"].Value = lstDiameter[m]; + // row.Cells["条数"].Value = ncount; + // row.Cells["总长度"].Value = Math.Round(totalLength); + + // dic.Add(layer.Caption + "," + row.Cells["材质"].Value.ToString(), ncount); + // } + // } + // } + //} + //else + //{ + // MessageBox.Show("请选择图层!"); + //} showPipeWidget(); } catch (Exception ex) @@ -339,6 +341,27 @@ } } } + + /// + /// 全区域分类汇总 + /// + /// + /// + private void buttonX8_Click(object sender, EventArgs e) + { + if (clbPipeLine.CheckedItems.Count == 0) + { + MessageBox.Show("请选择图层!"); + return; + } + if (clbmaterials.CheckedItems.Count == 0) + { + MessageBox.Show("请选择材质类型!"); + return; + } + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(null); + } /// /// 绘制区域分类汇总 /// @@ -346,24 +369,19 @@ /// private void buttonX9_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - if (clbmaterials.CheckedItems.Count > 0) - { - Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); - globeControl1.Globe.Action = EnumAction3D.TrackPolygon; - globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; - globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - } - else - { - MessageBox.Show("请选择材质类型!"); - } - } - else - { + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层!"); + return; } + if (clbmaterials.CheckedItems.Count == 0) + { + MessageBox.Show("请选择材质类型!"); + return; + } + Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); + globeControl1.Globe.Action = EnumAction3D.TrackPolygon; + globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; + globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); } /// @@ -458,30 +476,7 @@ MessageBox.Show("统计结果为空,请重新统计之后再导出Excel!", "提示"); } } - /// - /// 全区域分类汇总 - /// - /// - /// - private void buttonX8_Click(object sender, EventArgs e) - { - if (clbPipeLine.CheckedItems.Count > 0) - { - if (clbmaterials.CheckedItems.Count > 0) - { - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(null); - } - else - { - MessageBox.Show("请选择材质类型!"); - } - } - else - { - MessageBox.Show("请选择图层!"); - } - } + /// /// 全选 /// @@ -503,14 +498,8 @@ { for (int i = 0; i < this.clbmaterials.Items.Count; i++) { - if (clbmaterials.GetItemChecked(i) == true) - { - this.clbmaterials.SetItemChecked(i, false); - } - else - { - this.clbmaterials.SetItemChecked(i, true); - } + this.clbmaterials.SetItemChecked(i, !clbmaterials.GetItemChecked(i)); + } } /// @@ -525,19 +514,20 @@ clbmaterials.SetItemChecked(i, false); } } - + + //限制只能选择一个图层 private void clbPipeLine_ItemCheck(object sender, ItemCheckEventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) + if (clbPipeLine.CheckedItems.Count == 0) return; + + for (int i = 0; i < clbPipeLine.Items.Count; i++) { - for (int i = 0; i < clbPipeLine.Items.Count; i++) + if (i != e.Index) { - if (i != e.Index) - { - this.clbPipeLine.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked); - } + this.clbPipeLine.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked); } } + } } diff --git a/Frmpipediameterstatis.cs b/Frmpipediameterstatis.cs index db19689..9953ac0 100644 --- a/Frmpipediameterstatis.cs +++ b/Frmpipediameterstatis.cs @@ -155,6 +155,14 @@ /// private void buttonX8_Click(object sender, EventArgs e) { + if (clbPipeLine.CheckedItems.Count == 0) + { + MessageBox.Show("请选择图层!"); + } + if (dataGridViewX2.Rows.Count == 0) + { + MessageBox.Show("请添加分段!"); + } pipeDiameterStatis(null); } /// @@ -165,96 +173,37 @@ { try { - dic = new Dictionary(); + dic.Clear(); ; dataGridViewX1.Rows.Clear(); - if (clbPipeLine.CheckedItems.Count > 0) - { - if (dataGridViewX2.Rows.Count > 0) - { - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - if (flayer == null) - { - continue; - } - GSOFeatures feats = new GSOFeatures(); - if (polygon == null) - feats = flayer.GetAllFeatures(); - else - feats = flayer.FindFeaturesInPolygon(polygon, false); - for (int j = 0; j < dataGridViewX2.Rows.Count; j++) - { - double totalLength = 0.00; - int ncount = 0; - for (int m = 0; m < feats.Length; m++) - { - GSOFeature feat = feats[m]; - float radius = feat.GetFieldAsFloat("管径_毫米"); - bool upCompare = true; - bool downCompare = true; - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["下限"].Value.ToString() != "") - { - if (radius >= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["下限"].Value)) - { - downCompare = true; - } - else - downCompare = false; - } - } - if (dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - if (dataGridViewX2.Rows[j].Cells["上限"].Value.ToString() != "") - { - if (radius <= Convert.ToDouble(dataGridViewX2.Rows[j].Cells["上限"].Value)) - { - upCompare = true; - } - else - upCompare = false; - } - } - if (upCompare && downCompare) - { - GSOGeoPolyline3D line = feat.Geometry as GSOGeoPolyline3D; - if (line != null) - { - double length = line.GetSpaceLength(true, 6378137); - totalLength += length; - ncount += 1; - } - } - } - } - if (dataGridViewX2.Rows[j].Cells["下限"].Value != null || dataGridViewX2.Rows[j].Cells["上限"].Value != null) - { - DataGridViewRow row = new DataGridViewRow(); - int index = dataGridViewX1.Rows.Add(row); - row = dataGridViewX1.Rows[index]; - row.Cells["图层名称"].Value = layer.Caption; - row.Cells["管径范围"].Value = dataGridViewX2.Rows[j].Cells["下限"].Value + "-" + dataGridViewX2.Rows[j].Cells["上限"].Value; - row.Cells["条数"].Value = ncount; - row.Cells["总长度"].Value = Math.Round(totalLength, 2); - dic.Add(layer.Caption + "," + row.Cells["管径范围"].Value.ToString() + "," + row.Cells["总长度"].Value.ToString(), ncount); - } - } - } - } - else - { - MessageBox.Show("请添加分段!"); + FeatureStatisticsService service = new FeatureStatisticsService(); + for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) { + + GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(clbPipeLine.CheckedItems[i].ToString()); + for (int j = 0; j < dataGridViewX2.Rows.Count; j++) { + + object tempUp = dataGridViewX2.Rows[j].Cells["上限"].Value; + double? upLimit = null; + if (tempUp != null) upLimit = Convert.ToDouble(tempUp); + + object tempDown = dataGridViewX2.Rows[j].Cells["下限"].Value; + double? downLimit = null; + if (tempDown != null) downLimit = Convert.ToDouble(tempDown); + if (upLimit == null && downLimit == null) continue;//空行过滤 + //获取符合条件的管线 + FeaturesClassfyResult result = service.getPipesInfoByValueSection(polygon, layer, downLimit, upLimit, "管径_毫米"); + DataGridViewRow row = new DataGridViewRow(); + int index = dataGridViewX1.Rows.Add(row); + row = dataGridViewX1.Rows[index]; + row.Cells["图层名称"].Value = layer.Caption; + row.Cells["管径范围"].Value = result.groupFieldValue; + row.Cells["条数"].Value = result.ncount; + row.Cells["总长度"].Value = Math.Round(result.sum, 2); + dic.Add(layer.Caption + "," + row.Cells["管径范围"].Value.ToString() + "," + row.Cells["总长度"].Value.ToString(), result.ncount); + } } - else - { - MessageBox.Show("请选择图层!"); - } + + showPipeWidget(); } catch (Exception ex) @@ -268,93 +217,7 @@ /// private void showPipeWidget() { - /* - if (chart1.Series.Count > 0) - { - chart1.Series.Clear(); - } - if (chart1.Legends.Count > 0) - { - chart1.Legends.Clear(); - } - - for (int i = 0; i < clbPipeLine.CheckedItems.Count; i++) - { - string layerCaption = clbPipeLine.CheckedItems[i].ToString(); - GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(layerCaption); - if (layer != null && layer is GSOFeatureLayer) - { - chart1.Series.Add(layerCaption); - - GSOFeatureLayer flayer = layer as GSOFeatureLayer; - GSOFeatures features = flayer.GetAllFeatures(); - if (features.Length > 0) - { - if (features[0] != null && features[0].Geometry != null && features[0].Geometry.Type == EnumGeometryType.GeoPolyline3D) - { - GSOGeoPolyline3D p3d = features[0].Geometry as GSOGeoPolyline3D; - if (p3d.Style != null && p3d.Style is GSOPipeLineStyle3D) - { - GSOPipeLineStyle3D ps3d = p3d.Style as GSOPipeLineStyle3D; - chart1.Series[layerCaption].Color = ps3d.LineColor; - } - } - } - - chart1.Legends.Add(layerCaption); - chart1.Legends[layerCaption].Docking = Docking.Top; - - chart1.Legends[layerCaption].IsTextAutoFit = true; - chart1.Legends[layerCaption].LegendStyle = LegendStyle.Table; - chart1.Legends[layerCaption].DockedToChartArea = "ChartArea1"; - chart1.Legends[layerCaption].BackColor = Color.Transparent; - chart1.ChartAreas["ChartArea1"].AxisY.IsLabelAutoFit = false; - - - } - } - - // Set axis title - chart1.ChartAreas["ChartArea1"].AxisX.Title = "管径范围(毫米)"; - chart1.ChartAreas["ChartArea1"].AxisY.Title = "管线数量"; - chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; - LabelStyle labeStyleAxisX = new LabelStyle(); - labeStyleAxisX.Angle = -45; - labeStyleAxisX.Enabled = true; - chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle = labeStyleAxisX; - - Dictionary dic1 = new Dictionary(); - List dicLength = new List(); - for (int j = 0; j < chart1.Series.Count; j++) - { - dic1.Clear(); - dicLength.Clear(); - foreach (string key in dic.Keys) - { - if (key.Contains(chart1.Series[j].Name)) - { - dic1.Add(key.Split(',')[1].ToString(), dic[key]); - dicLength.Add(key.Split(',')[2].ToString()); - } - } - chart1.Series[j].ChartType = SeriesChartType.Column; - - chart1.Series[j]["DrawingStyle"] = "Cylinder"; - - chart1.Series[j].Points.DataBindXY(dic1.Keys, dic1.Values); - for (int m = 0; m < dic1.Values.Count; m++) - { - if (chart1.Series[j].Points[m].YValues[0].ToString() != "0") - { - chart1.Series[j].Points[m].Label = chart1.Series[j].Points[m].YValues[0].ToString(); - } - if (dicLength[m] != "0") - { - chart1.Series[j].Points[m].ToolTip = "长度:" + dicLength[m]; - } - } - } - * */ + chart1.Series.Clear(); chart1.Series.Add("管线"); @@ -404,14 +267,8 @@ { for (int i = 0; i < this.clbPipeLine.Items.Count; i++) { - if (clbPipeLine.GetItemChecked(i) == true) - { - this.clbPipeLine.SetItemChecked(i, false); - } - else - { - this.clbPipeLine.SetItemChecked(i, true); - } + this.clbPipeLine.SetItemChecked(i, !clbPipeLine.GetItemChecked(i)); + } } /// @@ -511,24 +368,18 @@ /// private void buttonX9_Click(object sender, EventArgs e) { - if (clbPipeLine.CheckedItems.Count > 0) - { - if (dataGridViewX2.Rows.Count > 0) - { - Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); - globeControl1.Globe.Action = EnumAction3D.TrackPolygon; - globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; - globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - } - else - { - MessageBox.Show("请添加分段!"); - } - } - else - { + if (clbPipeLine.CheckedItems.Count == 0) { MessageBox.Show("请选择图层!"); + return; } + if (dataGridViewX2.Rows.Count == 0) { + MessageBox.Show("请添加分段!"); + return; + } + Utility.RemoveFeatureFromName(globeControl1, "trackPolygon"); + globeControl1.Globe.Action = EnumAction3D.TrackPolygon; + globeControl1.Globe.TrackPolygonTool.TrackMode = EnumTrackMode.SpaceTrack; + globeControl1.TrackPolygonEndEvent += new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); } @@ -539,19 +390,29 @@ /// void globeControl1_TrackPolygonEndEvent(object sender, TrackPolygonEndEventArgs e) { - if (e.Polygon != null) + if (clbPipeLine.CheckedItems.Count == 0) { - GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; - polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; - GSOFeature feature = new GSOFeature(); - feature.Geometry = polygon; - feature.Name = "trackPolygon"; - globeControl1.Globe.MemoryLayer.AddFeature(feature); - globeControl1.Globe.ClearLastTrackPolygon(); - globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); - globeControl1.Globe.Action = EnumAction3D.ActionNull; - pipeDiameterStatis(e.Polygon); + MessageBox.Show("请选择图层!"); + return; } + if (dataGridViewX2.Rows.Count == 0) + { + MessageBox.Show("请添加分段!"); + return; + } + if (e.Polygon == null) return; + + GSOGeoPolygon3D polygon = e.Polygon.Clone() as GSOGeoPolygon3D; + polygon.AltitudeMode = EnumAltitudeMode.RelativeToGround; + GSOFeature feature = new GSOFeature(); + feature.Geometry = polygon; + feature.Name = "trackPolygon"; + globeControl1.Globe.MemoryLayer.AddFeature(feature); + globeControl1.Globe.ClearLastTrackPolygon(); + globeControl1.TrackPolygonEndEvent -= new TrackPolygonEndEventHandler(globeControl1_TrackPolygonEndEvent); + globeControl1.Globe.Action = EnumAction3D.ActionNull; + pipeDiameterStatis(e.Polygon); + } ///