using SuperMap.Analyst.NetworkAnalyst; using SuperMap.Data; using SuperMap.Mapping; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Windows.Forms; using WWPipeLine.MapBasic; using WWPipeLine.MapBasic.Conditions; namespace WWPipeLine.MapTools.Conditions.AnalystToolBar { public class LianTong : BasicToolBar { private int startEdgeID = 0; private int endEdgeID = 0; DatasetVector dv = null; public LianTong() : base() { this.ConditionPanelName = "连通分析"; var analystToolStripButton = new ToolStripButton() { DisplayStyle = ToolStripItemDisplayStyle.ImageAndText, Text = "开始分析", Name = "Analyst", AutoToolTip = false }; var reSelect = new ToolStripButton() { DisplayStyle = ToolStripItemDisplayStyle.ImageAndText, Text = "重新选择", Name = "reSelect", AutoToolTip = false }; base.ToolStrip.Items.Add(reSelect); base.ToolStrip.Items.Add(analystToolStripButton); analystToolStripButton.Click += AnalystToolStripButton_Click; reSelect.Click += ReSelect_Click; } protected override void OnLoad(EventArgs e) { ComsStatic.SetLayersIsSelectableFalse(ComsStatic.gsGuanXian.Name, true); MapControl.GeometrySelectChanged += MapControl_GeometrySelectChanged; string dviName = ComsStatic.DatasourceMemory.Datasets.GetAvailableDatasetName("LianTongNetwork"); dv = NetworkBuilder.BuildNetwork(ComsStatic.gsGuanXian, ComsStatic.gsGuanDian, "objectid", "qsdh", "zddh", "bsm", ComsStatic.DatasourceMemory, dviName); } private void AnalystToolStripButton_Click(object sender, EventArgs e) { if (startEdgeID == 0 || endEdgeID == 0) { Sunny.UI.UIMessageTip.ShowError("请选择两根需要分析的管线", 2000, false); return; } FacilityAnalystSetting analystSetting = new FacilityAnalystSetting(); analystSetting.NetworkDataset = dv; analystSetting.NodeIDField = "SmNodeID"; analystSetting.EdgeIDField = "objectid";//objectid SmEdgeID analystSetting.FNodeIDField = "SmFNode"; analystSetting.TNodeIDField = "SmTNode"; analystSetting.DirectionField = "lx"; analystSetting.Tolerance = 0.001; WeightFieldInfo info = new WeightFieldInfo(); info.Name = "length"; info.FTWeightField = "SmLength"; info.TFWeightField = "SmLength"; WeightFieldInfos infos = new WeightFieldInfos(); infos.Add(info); analystSetting.WeightFieldInfos = infos; FacilityAnalyst m_facilityAnalyst = new FacilityAnalyst(); m_facilityAnalyst.AnalystSetting = analystSetting; m_facilityAnalyst.Load(); FacilityAnalystResult resultEdges = m_facilityAnalyst.FindPathFromEdges(startEdgeID, endEdgeID, "length", true); if (resultEdges is null) { Sunny.UI.UIMessageTip.ShowWarning("选择的管线不连通"); return; } DataSet ds = new DataSet(); Recordset rdJSLK = ComsStatic.gsGuanXian.Query(string.Format(" enabled=1 and objectid in ({0})", string.Join(",", resultEdges.Edges)), CursorType.Static); DataTable dtJSLK = ComsStatic.RecordsetToDataTable(rdJSLK, true, string.Format("经过{0}根管线", rdJSLK.RecordCount)); ds.Tables.Add(dtJSLK); Recordset rdJSJDPT = dv.ChildDataset.Query(resultEdges.Nodes, "SmNodeID", CursorType.Static); DataTable dtJSJDPT = ComsStatic.RecordsetToDataTable(rdJSJDPT,true, string.Format("经过{0}个节点", rdJSJDPT.RecordCount)); ds.Tables.Add(dtJSJDPT); AnalystResultTabControl from = new AnalystResultTabControl(ds, "连通性分析结果"); from.ShowDialog(); m_facilityAnalyst.Dispose(); this.CloseToolBar(); } private void ReSelect_Click(object sender, EventArgs e) { startEdgeID = 0; endEdgeID = 0; MapControl.Map.TrackingLayer.Clear(); MapControl.Map.RefreshTrackingLayer(); } private void MapControl_GeometrySelectChanged(object sender, SuperMap.UI.GeometrySelectChangedEventArgs e) { Selection[] _selection = MapControl.Map.FindSelection(true); if (_selection.Length != 1 || _selection[0].Count != 1) { Sunny.UI.UIMessageTip.ShowError("请选择一根需要分析的管线"); return; } if (startEdgeID == 0) startEdgeID = ComsStatic.StringToInt(_selection[0].ToRecordset().GetFieldValue("objectid")); else endEdgeID = ComsStatic.StringToInt(_selection[0].ToRecordset().GetFieldValue("objectid")); MapControl.Map.TrackingLayer.Clear(); Recordset rd = ComsStatic.gsGuanXian.Query(string.Format("objectid in ({0},{1})", startEdgeID, endEdgeID), CursorType.Static); GeoStyle style = new GeoStyle { LineWidth = 1.2, LineColor = Color.Red }; Geometry geo; rd.MoveFirst(); while (!rd.IsEOF) { geo = rd.GetGeometry(); geo.Style = style; MapControl.Map.TrackingLayer.Add(geo, "GeoRectangle"); rd.MoveNext(); } MapControl.Map.RefreshTrackingLayer(); } public override void AfterClose() { MapControl.GeometrySelectChanged -= MapControl_GeometrySelectChanged; base.AfterClose(); } private void InitializeComponent() { this.SuspendLayout(); // // ToolsConditions // this.Name = "ToolsConditions"; this.ResumeLayout(false); } } }