public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { DF2DApplication app = DF2DApplication.Application; m_ActiveView = app.Current2DMapControl.ActiveView; IGraphicsContainer pGC = m_ActiveView.GraphicsContainer; if (this.m_ActiveView.FocusMap.FeatureSelection != null) { this.m_ActiveView.FocusMap.ClearSelection(); } bool ready = false; if (app == null || app.Current2DMapControl == null) { return; } IGeometry pGeo = null; int preCount = 0; int nextCount = 0; try { if (button == 1) { PointClass searchPoint = new PointClass(); searchPoint.PutCoords(mapX, mapY); pGeo = PublicFunction.DoBuffer(searchPoint, PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate)); if (pGeo == null) { return; } ready = true; if (ready) { bool haveone = false; foreach (LogicGroup lg in LogicDataStructureManage2D.Instance.RootLogicGroups) { if (haveone) { break; } foreach (MajorClass mc in lg.MajorClasses) { if (haveone) { break; } string[] arrFc2DId = mc.Fc2D.Split(';'); if (arrFc2DId == null) { continue; } IFeatureCursor pFeatureCursor = null; IFeature pFeature = null; //DFDataConfig.Class.FieldInfo fi; //int indexFusu = 0; ////string nodefcId = null; foreach (SubClass sc in mc.SubClasses) { if (haveone) { break; } if (!sc.Visible2D) { continue; } foreach (string fc2DId in arrFc2DId) { DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); if (dffc == null) { continue; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass facc = dffc.GetFacilityClass(); if (facc.Name != "PipeLine") { continue; } ISpatialFilter pSpatialFilter = new SpatialFilter(); pSpatialFilter.Geometry = pGeo; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pFeatureCursor = fc.Search(pSpatialFilter, false); if (pFeatureCursor == null) { continue; } pFeature = pFeatureCursor.NextFeature(); if (pFeature == null) { continue; } IGeometry pGeometry = pFeature.Shape as IGeometry; if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolyline) { IPolyline pLine = pGeometry as IPolyline; this._EdgeFCID = fc.FeatureClassID.ToString(); this._EdgeOID = pFeature.OID; color = GetRGBColor(0, 230, 240); IElement lineElement = LineElementRenderer(pLine, color); pGC.AddElement(lineElement, 0); } haveone = true; break; } foreach (string fc2DId in arrFc2DId) { DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); if (dffc == null) { continue; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass facc = dffc.GetFacilityClass(); IFeatureLayer fl = dffc.GetFeatureLayer(); if (fc == null || pGeo == null || fl == null) { continue; } if (!fl.Visible) { continue; } if (facc.Name != "PipeNode") { continue; } DFDataConfig.Class.FieldInfo fi = facc.GetFieldInfoBySystemName("Additional"); IFields fiCol = fc.Fields; int indexFusu = fiCol.FindField(fi.Name); WaitForm.Start("正在分析...", "请稍后"); TopoClass2D tc = FacilityInfoService2D.GetTopoClassByFeatureClassID(fc2DId); if (tc == null) { WaitForm.Stop(); return; } TopoNetwork net = tc.GetNetwork(); if (net == null) { WaitForm.Stop(); XtraMessageBox.Show("构建拓扑网络失败!", "提示"); return; } else { HashSet <string> valveIds = new HashSet <string>(); if (!string.IsNullOrEmpty(fc2DId) && ValveManager.Instance.Exists(fc2DId)) { valveIds = ValveManager.Instance.GetValveIds(fc2DId); } else { IFeature feature; string fusu; //IQueryFilter filter = new QueryFilter(); //filter.WhereClause = fi.Name + " LIKE '%阀%'"; IFeatureCursor cursor = fc.Search(null, false); int n = fc.FeatureCount(null); if (indexFusu == 0) { return; } while ((feature = cursor.NextFeature()) != null) { //valveIds.Add(fc2DId + "_" + feature.OID.ToString()); fusu = feature.get_Value(indexFusu).ToString(); if (fusu == "阀门" || fusu == "阀门井") { valveIds.Add(fc2DId + "_" + feature.OID.ToString()); } } ValveManager.Instance.Add(fc2DId, valveIds); } //string edgeID = this._EdgeFCID + "_" + this._EdgeOID.ToString(); if (EdgeManager.Instance.Exists(this._EdgeFCID, this._EdgeOID.ToString())) { edge = EdgeManager.Instance.GetEdgeByID(this._EdgeFCID, this._EdgeOID.ToString()); } preNode = edge.PreNode; nextNode = edge.NextNode; HashSet <string> recordPre = new HashSet <string>(); HashSet <string> recordNext = new HashSet <string>(); color = GetRGBColor(255, 0, 0); net.BGFX(preNode.ID, nextNode.ID, valveIds, ref recordPre, ref recordNext); if (recordPre.Count <= 0 && recordNext.Count <= 0) { continue; } preCount = recordPre.Count; nextCount = recordNext.Count; foreach (string s in recordPre) { int id; Node n = NodeManager.Instance.GetNodeByID(s); Int32.TryParse(n.FeatureId, out id); IFeature feature = fc.GetFeature(id); IPoint point = feature.Shape as IPoint; //color = GetRGBColor(255, 0, 0); IElement elementpPoint = PointElementRenderer(point, color); pGC.AddElement(elementpPoint, 0); IElement elementText = AddCallout(app.Current2DMapControl, point, "需关闭阀门", color); pGC.AddElement(elementText, 1); app.Current2DMapControl.CenterAt(point); } foreach (string s in recordNext) { int id; Node n = NodeManager.Instance.GetNodeByID(s); Int32.TryParse(n.FeatureId, out id); IFeature feature = fc.GetFeature(id); IPoint point = feature.Shape as IPoint; color = GetRGBColor(0, 0, 0); IElement elementpPoint = PointElementRenderer(point, color); pGC.AddElement(elementpPoint, 0); IElement elementText = AddCallout(app.Current2DMapControl, point, "需关闭阀门", color); pGC.AddElement(elementText, 1); app.Current2DMapControl.CenterAt(point); } app.Current2DMapControl.MapScale = 500; app.Current2DMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } if (haveone) { break; } } } } } } } } catch (System.Exception ex) { } finally { WaitForm.Stop(); XtraMessageBox.Show("上游需关闭阀门:" + preCount + "\n下游需关闭阀门:" + nextCount, "提示"); SuspendCommand(); } }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { DF2DApplication app = DF2DApplication.Application; m_ActiveView = app.Current2DMapControl.ActiveView; IGraphicsContainer pGC = m_ActiveView.GraphicsContainer; if (this.m_ActiveView.FocusMap.FeatureSelection != null) { this.m_ActiveView.FocusMap.ClearSelection(); } bool ready = false; if (app == null || app.Current2DMapControl == null) { return; } IGeometry pGeo = null; try { if (button == 1) { PointClass searchPoint = new PointClass(); searchPoint.PutCoords(mapX, mapY); pGeo = PublicFunction.DoBuffer(searchPoint, PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate)); if (pGeo == null) { return; } ready = true; if (ready) { bool haveone = false; foreach (LogicGroup lg in LogicDataStructureManage2D.Instance.RootLogicGroups) { foreach (MajorClass mc in lg.MajorClasses) { string[] arrFc2DId = mc.Fc2D.Split(';'); if (arrFc2DId == null) { continue; } IFeatureCursor pFeatureCursor = null; IFeature pFeature = null; foreach (string fc2DId in arrFc2DId) { DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); if (dffc == null) { continue; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass facc = dffc.GetFacilityClass(); if (facc.Name != "PipeNode") { continue; } IFeatureLayer fl = dffc.GetFeatureLayer(); if (fc == null || pGeo == null || fl == null) { continue; } if (!fl.Visible) { continue; } ISpatialFilter pSpatialFilter = new SpatialFilter(); pSpatialFilter.Geometry = pGeo; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pFeatureCursor = fc.Search(pSpatialFilter, false); if (pFeatureCursor == null) { continue; } pFeature = pFeatureCursor.NextFeature(); if (pFeature == null) { continue; } haveone = true; IGeometry pGeometry = pFeature.Shape as IGeometry; if (pGeometry.GeometryType == esriGeometryType.esriGeometryPoint) { IPoint pPoint = pGeometry as IPoint; if (this._bFinished) { this._bFinished = false; this._startFCID = fc.FeatureClassID.ToString(); this._startOid = pFeature.OID; AddCallout(pPoint, "起点"); app.Current2DMapControl.ActiveView.Refresh(); } else { if (this._startFCID == fc.FeatureClassID.ToString() && this._startOid == pFeature.OID) { XtraMessageBox.Show("您选中的是同一个管点设施。", "提示"); return; } this._bFinished = true; AddCallout(pPoint, "终点"); app.Current2DMapControl.ActiveView.Refresh(); if (this._startFCID != fc.FeatureClassID.ToString()) { XtraMessageBox.Show("您选中的不是同一类管点设施。", "提示"); return; } else { WaitForm.Start("正在分析...", "请稍后"); TopoClass2D tc = FacilityInfoService2D.GetTopoClassByFeatureClassID(fc.FeatureClassID.ToString()); if (tc == null) { return; } TopoNetwork net = tc.GetNetwork(); if (net == null) { WaitForm.Stop(); XtraMessageBox.Show("构建拓扑网络失败!", "提示"); return; } else { string startId = this._startFCID + "_" + this._startOid.ToString(); string endId = fc.FeatureClassID.ToString() + "_" + pFeature.OID.ToString(); List <string> path; double shortestLength = net.SPFA(startId, endId, out path); if ((shortestLength > 0.0 && shortestLength != double.MaxValue) || (path != null && path.Count > 0)) { List <IPoint> listPt = new List <IPoint>(); IPointCollection pointCol = new PolylineClass(); foreach (string nodeId in path) { int index = nodeId.LastIndexOf("_"); string fcID = nodeId.Substring(0, index); string oid = nodeId.Substring(index + 1, nodeId.Length - index - 1); DF2DFeatureClass dffcTemp = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fcID); if (dffcTemp == null || dffcTemp.GetFeatureClass() == null) { continue; } if (dffcTemp.GetFacilityClassName() != "PipeNode") { continue; } IQueryFilter filter = new QueryFilter(); filter.WhereClause = "OBJECTID =" + oid; filter.SubFields = "OBJECTID ,SHAPE"; IFeature feature = null; IFeatureCursor cursor = null; try { cursor = dffcTemp.GetFeatureClass().Search(filter, false); while ((feature = cursor.NextFeature()) != null) { if (feature.Shape != null && feature.Shape is IGeometry) { IGeometry geo = feature.Shape as IGeometry; switch (geo.GeometryType) { case esriGeometryType.esriGeometryPoint: IPoint pt = geo as IPoint; //pt.Z = pt.Z + 1; listPt.Add(pt); pointCol.AddPoint(pt); break; } } } } catch (System.Exception ex) { } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (feature != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(feature); feature = null; } } } if (listPt.Count > 0) { IPolyline polyline = pointCol as IPolyline; ISimpleLineSymbol pLineSymbol = new SimpleLineSymbol(); pLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; pLineSymbol.Width = 5; pLineSymbol.Color = GetRGBColor(0, 230, 240); IElement elementL = new LineElement(); elementL.Geometry = polyline; ILineElement pLineElement = elementL as ILineElement; pLineElement.Symbol = pLineSymbol; pGC.AddElement(elementL, 0); ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(); simpleMarkerSymbol.Color = GetRGBColor(255, 0, 0); simpleMarkerSymbol.Outline = false; simpleMarkerSymbol.Size = 5; simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; foreach (IPoint pt in listPt) { try { IMarkerElement pMarkerElement = new MarkerElementClass(); pMarkerElement.Symbol = simpleMarkerSymbol; IElement pElement = pMarkerElement as IElement; pElement.Geometry = pt; pGC.AddElement(pElement, 0); } catch (System.Exception ex) { continue; } } } app.Current2DMapControl.ActiveView.Refresh(); } else { WaitForm.Stop(); XtraMessageBox.Show("两点不连通!", "提示"); pGC.DeleteAllElements(); } } } } } } if (haveone) { break; } } if (haveone) { break; } } } } } catch (System.Exception ex) { XtraMessageBox.Show("分析出错!", "提示"); } finally { WaitForm.Stop(); } }
private void ClickQuery() { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } try { IFeatureLayer fl = this._drawTool.GetSelectFeatureLayerPickResult().FeatureLayer; if (fl == null) { return; } int featureId = this._drawTool.GetSelectFeatureLayerPickResult().FeatureId; FacilityClass facc = Dictionary3DTable.Instance.GetFacilityClassByDFFeatureClassID(fl.FeatureClassId.ToString()); if (facc == null || facc.Name != "PipeNode") { XtraMessageBox.Show("您选中的不是管点设施,请选择管点设施。", "提示"); return; } DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fl.FeatureClassId.ToString()); if (dffc == null || dffc.GetFeatureClass() == null) { return; } IFeatureClass fc = dffc.GetFeatureClass(); if (this._bFinished) { Clear(); this._startFCGuid = fc.Guid.ToString(); this._startOid = featureId; this._bFinished = false; ILabel label = app.Current3DMapControl.ObjectManager.CreateLabel(app.Current3DMapControl.ProjectTree.RootID); label.Text = "起点"; ITextSymbol ts = new TextSymbol(); ts.TextAttribute.TextSize = SystemInfo.Instance.TextSize; ts.TextAttribute.TextColor = Convert.ToUInt32(SystemInfo.Instance.TextColor, 16); label.TextSymbol = ts; label.Position = this._drawTool.GetSelectPoint(); this._listRGuid.Add(label.Guid); } else { if (this._startFCGuid == fc.Guid.ToString() && this._startOid == featureId) { XtraMessageBox.Show("您选中的是同一个管点设施。", "提示"); return; } this._bFinished = true; ILabel label = app.Current3DMapControl.ObjectManager.CreateLabel(app.Current3DMapControl.ProjectTree.RootID); label.Text = "终点"; ITextSymbol ts = new TextSymbol(); ts.TextAttribute.TextSize = SystemInfo.Instance.TextSize; ts.TextAttribute.TextColor = Convert.ToUInt32(SystemInfo.Instance.TextColor, 16); label.TextSymbol = ts; label.Position = this._drawTool.GetSelectPoint(); this._listRGuid.Add(label.Guid); if (this._startFCGuid != fc.Guid.ToString()) { XtraMessageBox.Show("您选中的不是同一类管点设施。", "提示"); return; } else { WaitForm.Start("正在分析...", "请稍后"); FacClassReg reg = FacilityInfoService.GetFacClassRegByFeatureClassID(fc.Guid.ToString()); if (reg == null) { return; } TopoClass tc = FacilityInfoService.GetTopoClassByFacClassCode(reg.FacClassCode); if (tc == null) { return; } TopoNetwork net = tc.GetNetwork(); if (net == null) { XtraMessageBox.Show("构建拓扑网络失败!", "提示"); return; } else { string startId = this._startFCGuid + "_" + this._startOid.ToString(); string endId = fc.Guid.ToString() + "_" + featureId.ToString(); List <string> path; double shortestLength = net.SPFA(startId, endId, out path); if ((shortestLength > 0.0 && shortestLength != double.MaxValue) || (path != null && path.Count > 0)) { List <IPoint> listPt = new List <IPoint>(); foreach (string nodeId in path) { int index = nodeId.LastIndexOf("_"); string fcguid = nodeId.Substring(0, index); string oid = nodeId.Substring(index + 1, nodeId.Length - index - 1); DF3DFeatureClass dffcTemp = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fcguid); if (dffcTemp == null || dffcTemp.GetFeatureClass() == null) { continue; } if (dffcTemp.GetFacilityClassName() != "PipeNode") { continue; } IQueryFilter filter = new QueryFilter(); filter.WhereClause = "oid = " + oid; filter.SubFields = "oid,Shape"; IRowBuffer row = null; IFdeCursor cursor = null; try { cursor = dffcTemp.GetFeatureClass().Search(filter, false); while ((row = cursor.NextRow()) != null) { if (!row.IsNull(1) && (row.GetValue(1) is IGeometry)) { IGeometry geo = row.GetValue(1) as IGeometry; switch (geo.GeometryType) { case gviGeometryType.gviGeometryPoint: IPoint pt = geo as IPoint; pt.Z = pt.Z + 1; listPt.Add(pt); break; } } } } catch (Exception ex) { } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } } IPolyline polyline = (new GeometryFactory()).CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline; foreach (IPoint pt in listPt) { ISimplePointSymbol ps = new SimplePointSymbol(); ps.Size = 5; ps.Style = gviSimplePointStyle.gviSimplePointCircle; ps.FillColor = Convert.ToUInt32(SystemInfo.Instance.FillColor, 16); IRenderPoint rp = app.Current3DMapControl.ObjectManager.CreateRenderPoint(pt, ps, app.Current3DMapControl.ProjectTree.RootID); rp.Glow(5000); polyline.AppendPoint(pt); this._listRGuid.Add(rp.Guid); } ICurveSymbol cs = new CurveSymbol(); cs.Color = Convert.ToUInt32(SystemInfo.Instance.LineColor, 16); cs.Width = -5; IRenderPolyline rpl = app.Current3DMapControl.ObjectManager.CreateRenderPolyline(polyline, cs, app.Current3DMapControl.ProjectTree.RootID); rpl.Glow(5000); this._listRGuid.Add(rpl.Guid); } else { XtraMessageBox.Show("两点不连通!", "提示"); } } } } } catch (Exception ex) { XtraMessageBox.Show("分析出错!", "提示"); } finally { WaitForm.Stop(); } }
public TopoNetwork GetNetwork() { if (TopoNetworkManager.Instance.Exists(this._objectId)) { return(TopoNetworkManager.Instance.GetTopoNetWorkByObjectId(this._objectId)); } if (DF3DPipeCreateApp.App.PipeLib == null) { return(null); } TopoNetwork network = null; IFeatureClass class2 = null; IQueryFilter filter = null; IFdeCursor cursor = null; IRowBuffer buffer = null; try { IFeatureDataSet fds = DF3DPipeCreateApp.App.PipeLib.OpenFeatureDataset("DataSet_BIZ"); if (fds == null) { return(null); } class2 = fds.OpenFeatureClass(this._topotable); filter = new QueryFilterClass { SubFields = "A_FacClass,Edge,P_FacClass,PNode,E_FacClass,ENode,Geometry" }; Dictionary <string, Node> dictNode = new Dictionary <string, Node>(); // 点字典 int totalcount = class2.GetCount(null); int loop = (int)Math.Ceiling((decimal)(totalcount / 1000.0)); for (int i = 1; i <= loop; i++) { if (i == 1) { filter.ResultBeginIndex = 0; } else { filter.ResultBeginIndex = (i - 1) * 1000; } filter.ResultLimit = 1000; cursor = class2.Search(filter, true); while ((buffer = cursor.NextRow()) != null) { string edgeFC, edgeOid, snodeFC, snodeOid, enodeFC, enodeOid; if (!buffer.IsNull(0)) { edgeFC = buffer.GetValue(0).ToString(); } else { edgeFC = "0"; } if (!buffer.IsNull(1)) { edgeOid = buffer.GetValue(1).ToString(); } else { edgeOid = BitConverter.ToString(ObjectIdGenerator.Generate()).Replace("-", string.Empty).ToLowerInvariant(); } if (!buffer.IsNull(2)) { snodeFC = buffer.GetValue(2).ToString(); } else { snodeFC = "0"; } if (!buffer.IsNull(3)) { snodeOid = buffer.GetValue(3).ToString(); } else { snodeOid = BitConverter.ToString(ObjectIdGenerator.Generate()).Replace("-", string.Empty).ToLowerInvariant(); } if (!buffer.IsNull(4)) { enodeFC = buffer.GetValue(4).ToString(); } else { enodeFC = "0"; } if (!buffer.IsNull(5)) { enodeOid = buffer.GetValue(5).ToString(); } else { enodeOid = BitConverter.ToString(ObjectIdGenerator.Generate()).Replace("-", string.Empty).ToLowerInvariant(); } double edgeLength = double.MaxValue; if (!buffer.IsNull(6) && buffer.GetValue(6) is IPolyline) { IPolyline line = buffer.GetValue(6) as IPolyline; edgeLength = line.Length; } Node sn = null; Node en = null; string key = snodeFC + "_" + snodeOid; if (!dictNode.ContainsKey(key)) { if (NodeManager.Instance.GetNodeByID(key) == null) { sn = new Node(snodeFC, snodeOid); NodeManager.Instance.Add(sn); } else { sn = NodeManager.Instance.GetNodeByID(key); } dictNode.Add(key, sn); } else { sn = dictNode[key]; } key = enodeFC + "_" + enodeOid; if (!dictNode.ContainsKey(key)) { if (NodeManager.Instance.GetNodeByID(key) == null) { en = new Node(enodeFC, enodeOid); NodeManager.Instance.Add(en); } else { en = NodeManager.Instance.GetNodeByID(key); } dictNode.Add(key, en); } else { en = dictNode[key]; } if (sn == null || en == null) { continue; } Edge e = new Edge(edgeFC, edgeOid, sn, en, edgeLength); EdgeManager.Instance.Add(e); } } network = new TopoNetwork(this._objectId, dictNode); TopoNetworkManager.Instance.Add(this.ObjectId, network); return(network); } catch (Exception ex) { return(null); } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (buffer != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(buffer); buffer = null; } } }
public TopoNetwork GetNetwork() { if (TopoNetworkManager.Instance.Exists(this._objectId)) { return(TopoNetworkManager.Instance.GetTopoNetWorkByObjectId(this._objectId)); } string path = Config.GetConfigValue("2DMdbTopo"); TopoNetwork network = null; IFeatureClass featureClass = null; IQueryFilter filter = null; IFeatureCursor cursor = null; IFeature feature = null; try { IWorkspaceFactory pWsFt = new AccessWorkspaceFactory(); IFeatureWorkspace pWs = pWsFt.OpenFromFile(path, 0) as IFeatureWorkspace; featureClass = pWs.OpenFeatureClass(_name); filter = new QueryFilter(); filter.SubFields = "A_FC,Edge,P_FC,PNode,E_FC,ENode,Geometry_Length"; int index1 = featureClass.Fields.FindField("A_FC"); int index2 = featureClass.Fields.FindField("Edge"); int index3 = featureClass.Fields.FindField("P_FC"); int index4 = featureClass.Fields.FindField("PNode"); int index5 = featureClass.Fields.FindField("E_FC"); int index6 = featureClass.Fields.FindField("ENode"); int index7 = featureClass.Fields.FindField("Geometry_Length"); Dictionary <string, Edge> dictEdge = new Dictionary <string, Edge>(); // 边字典 Dictionary <string, Node> dictNode = new Dictionary <string, Node>(); // 点字典 cursor = featureClass.Search(filter, false); while ((feature = cursor.NextFeature()) != null) { string edgeFC, edgeOid, snodeFC, snodeOid, enodeFC, enodeOid; if (feature.get_Value(index1) != null) { edgeFC = feature.get_Value(index1).ToString(); } else { edgeFC = "0"; } if (feature.get_Value(index2) != null) { edgeOid = feature.get_Value(index2).ToString(); } else { edgeOid = BitConverter.ToString(ObjectIdGenerator.Generate()).Replace("-", string.Empty).ToLowerInvariant(); } if (feature.get_Value(index3) != null) { snodeFC = feature.get_Value(index3).ToString(); } else { snodeFC = "0"; } if (feature.get_Value(index4) != null) { snodeOid = feature.get_Value(index4).ToString(); } else { snodeOid = BitConverter.ToString(ObjectIdGenerator.Generate()).Replace("-", string.Empty).ToLowerInvariant(); } if (feature.get_Value(index5) != null) { enodeFC = feature.get_Value(index5).ToString(); } else { enodeFC = "0"; } if (feature.get_Value(index6) != null) { enodeOid = feature.get_Value(index6).ToString(); } else { enodeOid = BitConverter.ToString(ObjectIdGenerator.Generate()).Replace("-", string.Empty).ToLowerInvariant(); } double edgeLength = double.MaxValue; if (feature.get_Value(index7) != null) { edgeLength = (double)feature.get_Value(index7); } //if (feature.get_Value(index7) != null && feature.get_Value(index7) is IPolyline) //{ // IPolyline line = feature.get_Value(index7) as IPolyline; // edgeLength = line.Length; //} Node sn = null; Node en = null; string key = snodeFC + "_" + snodeOid; if (!dictNode.ContainsKey(key)) { if (NodeManager.Instance.GetNodeByID(key) == null) { sn = new Node(snodeFC, snodeOid); NodeManager.Instance.Add(sn); } else { sn = NodeManager.Instance.GetNodeByID(key); } dictNode.Add(key, sn); } else { sn = dictNode[key]; } key = enodeFC + "_" + enodeOid; if (!dictNode.ContainsKey(key)) { if (NodeManager.Instance.GetNodeByID(key) == null) { en = new Node(enodeFC, enodeOid); NodeManager.Instance.Add(en); } else { en = NodeManager.Instance.GetNodeByID(key); } dictNode.Add(key, en); } else { en = dictNode[key]; } if (sn == null || en == null) { continue; } key = edgeFC + "_" + edgeOid; if (!dictEdge.ContainsKey(key)) { Edge e = null; if (EdgeManager.Instance.GetEdgeByID(key) == null) { e = new Edge(edgeFC, edgeOid, sn, en, edgeLength); EdgeManager.Instance.Add(e); } else { e = EdgeManager.Instance.GetEdgeByID(key); } dictEdge.Add(key, e); } } network = new TopoNetwork(this._objectId, dictNode); TopoNetworkManager.Instance.Add(this.ObjectId, network); return(network); } catch (System.Exception ex) { return(null); } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (feature != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(feature); feature = null; } } }