private void Dispose(bool disposing) { if (!_disposed) { if (disposing) { //Managed classes } //Unmanaged classes _DisposeTempDatasets(); UrbanDelineationExtension.ReleaseComObject(_geometricNetwork); _geometricNetwork = null; UrbanDelineationExtension.ReleaseComObject(_inletClass); _inletClass = null; UrbanDelineationExtension.ReleaseComObject(_dem); _dem = null; UrbanDelineationExtension.ReleaseComObject(_punchedDEM); _punchedDEM = null; UrbanDelineationExtension.ReleaseComObject(_filledDEM); _filledDEM = null; UrbanDelineationExtension.ReleaseComObject(_flowDir); _flowDir = null; UrbanDelineationExtension.ReleaseComObject(_drainClass); _drainClass = null; UrbanDelineationExtension.ReleaseComObject(_catchmentClass); _catchmentClass = null; _disposed = true; } }
private IFeatureClass GetFeatureClassByClassId(int classId, IGeometricNetwork geomNetwork) { IEnumFeatureClass enumFC; IFeatureClass fc; enumFC = geomNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleEdge); fc = enumFC.Next(); while (fc != null) { if (fc.FeatureClassID == classId) { return(fc); } fc = enumFC.Next(); } enumFC = geomNetwork.get_ClassesByType(esriFeatureType.esriFTComplexEdge); fc = enumFC.Next(); while (fc != null) { if (fc.FeatureClassID == classId) { return(fc); } fc = enumFC.Next(); } return(null); }
private void method_0(IGeometricNetwork igeometricNetwork_1) { try { IFeatureClassContainer featureDataset = (IFeatureClassContainer)igeometricNetwork_1.FeatureDataset; IEnumRule rules = igeometricNetwork_1.Rules; rules.Reset(); for (IRule rule2 = rules.Next(); rule2 != null; rule2 = rules.Next()) { if (rule2 is IConnectivityRule) { IConnectivityRule rule3 = (IConnectivityRule)rule2; if (rule3.Category == -1) { IJunctionConnectivityRule2 rule4 = (IJunctionConnectivityRule2)rule3; featureDataset.get_ClassByID(rule4.EdgeClassID); featureDataset.get_ClassByID(rule4.JunctionClassID); } else if (rule3.Type == esriRuleType.esriRTEdgeConnectivity) { IEdgeConnectivityRule rule5 = (IEdgeConnectivityRule)rule3; featureDataset.get_ClassByID(rule5.FromEdgeClassID); featureDataset.get_ClassByID(rule5.ToEdgeClassID); featureDataset.get_ClassByID(rule5.DefaultJunctionClassID); for (int i = 0; i < rule5.JunctionCount; i++) { } } } } } catch { } }
public override void OnMouseDown(int button, int shift, int x, int y) { if (button == 1) { IActiveView activeView = _context.ActiveView; _context.FocusMap.ClearSelection(); activeView.PartialRefresh((esriViewDrawPhase)4, null, null); IPoint point = _context.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); StartQueryJunction(point); //IEnvelope envelope = new Envelope() as IEnvelope; //double num = activeView.Extent.Width / 200.0; //envelope.XMax=(point.X + num); //envelope.XMin=(point.X - num); //envelope.YMax=(point.Y + num); //envelope.YMin=(point.Y - num); //_context.FocusMap.SelectByShape(envelope, null, true); //activeView.PartialRefresh((esriViewDrawPhase) 4, null, null); //IEnumFeature enumFeature = (MapSelection)_context.FocusMap.FeatureSelection; //if (enumFeature != null) //{ // IFeature feature = enumFeature.Next(); // if (feature != null) // { // this.StartAnalysis(feature); // } //} } else { this._startPoint = null; this._geometricNetwork = null; this._startEid = 0; } }
/// <summary> /// 设置障碍点 /// </summary> /// <param name="pNetSolver"></param> /// <param name="breakPoints"></param> /// <param name="pGeometricNet"></param> /// <param name="pDisc"></param> private void SetBarries(INetSolver pNetSolver, List <IPoint> breakPoints, IGeometricNetwork pGeometricNet, double pDisc) { INetwork pNetwork = pGeometricNet.Network; INetElements pNetElements = pNetwork as INetElements; IPointToEID pPointToEID = new PointToEIDClass(); pPointToEID.GeometricNetwork = pGeometricNet; pPointToEID.SnapTolerance = pDisc; ISelectionSetBarriers barriers = new SelectionSetBarriersClass(); foreach (var point in breakPoints) { //寻找障碍点最近的线要素,从而添加爆管线 int nearEdgeID; IPoint outIpoint; double precent; pPointToEID.GetNearestEdge(point, out nearEdgeID, out outIpoint, out precent); int userClassID; int userID; int userSubID; //查询相关ID pNetElements.QueryIDs(nearEdgeID, esriElementType.esriETJunction, out userClassID, out userID, out userSubID); //添加障碍点 barriers.Add(userClassID, userID); } pNetSolver.SelectionSetBarriers = barriers; }
private void method_6(IGeometricNetwork geometricNetwork) { INetwork network = geometricNetwork.Network; IUtilityNetwork utilityNetwork = (IUtilityNetwork)network; IEnumNetEID enumNetEID = network.CreateNetBrowser((esriElementType)2); IEIDHelper eIDHelperClass = new EIDHelper(); eIDHelperClass.GeometricNetwork = (geometricNetwork); eIDHelperClass.DisplayEnvelope = (null); eIDHelperClass.OutputSpatialReference = (null); eIDHelperClass.ReturnFeatures = (false); eIDHelperClass.ReturnGeometries = (true); eIDHelperClass.PartialComplexEdgeGeometry = (true); IEnumEIDInfo enumEIDInfo = eIDHelperClass.CreateEnumEIDInfo(enumNetEID); enumEIDInfo.Reset(); long num = (long)enumEIDInfo.Count; int num2 = 0; while ((long)num2 < num) { IEIDInfo iEIDInfo = enumEIDInfo.Next(); int eID = iEIDInfo.EID; IGeometry geometry = iEIDInfo.Geometry; esriFlowDirection esriFlowDirection = this.method_7(geometry); utilityNetwork.SetFlowDirection(eID, esriFlowDirection); num2++; } }
private void _AddNetworkForLayer(ILayer layer, List <ComboBoxItem> geometricNetworks) { IFeatureLayer featureLayer = (IFeatureLayer)layer; INetworkClass networkClass = (INetworkClass)featureLayer.FeatureClass; try { IGeometricNetwork network = networkClass.GeometricNetwork; bool alreadyAdded = false; foreach (ComboBoxItem element in geometricNetworks) { if (element.Value == network) { alreadyAdded = true; break; } } if (!alreadyAdded) { geometricNetworks.Add(new ComboBoxItem() { Name = ((IDataset)network).Name, Value = network }); } } finally { UrbanDelineationExtension.ReleaseComObject(networkClass); } }
//关闭工作空间 private void CloseWorkspace() { m_ipGeometricNetwork = null; m_ipPoints = null; m_ipPointToEID = null; m_ipEnumNetEID_Junctions = null; m_ipEnumNetEID_Edges = null; m_ipPolyline = null; }
private void openGeoNetwork() { string fpath=@"C:\ArcGIS91_Demos\Sewer9\data\sewer3.mdb"; IFeatureWorkspace pFWS=Utility.openPDB(fpath); IFeatureDataset pFdataset=pFWS.OpenFeatureDataset("urban"); INetworkCollection pNetworkCollection=pFdataset as INetworkCollection; //�õ�Sewer Network����TRACE pGeometricNetwork=pNetworkCollection.get_GeometricNetworkByName("Sewer_Network"); }
private void openGeoNetwork() { string fpath = @"C:\ArcGIS91_Demos\Sewer9\data\sewer3.mdb"; IFeatureWorkspace pFWS = Utility.openPDB(fpath); IFeatureDataset pFdataset = pFWS.OpenFeatureDataset("urban"); INetworkCollection pNetworkCollection = pFdataset as INetworkCollection; //得到Sewer Network进行TRACE pGeometricNetwork = pNetworkCollection.get_GeometricNetworkByName("Sewer_Network"); }
/// <summary> /// 获取网络数据 /// </summary> /// <param name="netCollection"></param> /// <param name="index"></param> /// <returns></returns> public static IGeometricNetwork GetGeometricNetWork(INetworkCollection netCollection, int index) { if (index < 0 || index >= netCollection.GeometricNetworkCount) { throw new Exception("索引异常"); } IGeometricNetwork pGeoNet = netCollection.get_GeometricNetwork(index); return(pGeoNet); }
// // returns a reference to the current logical network // private INetwork GetCurrentNetwork() { // get the current network from the Utility Network Analysis extension INetworkAnalysisExt nax = m_utilNetExt as INetworkAnalysisExt; IGeometricNetwork geomNet = nax.CurrentNetwork; // get the geometric network's logical network INetwork net = geomNet.Network; return(net); }
//! 通过点击获取需要分析的管线 public bool PickBrokePipe(IPoint _pMousePoint) { this.InitClick(); this.ipoint_0 = _pMousePoint; bool flag = false; double num = 2147483647.0; ArrayList arrayList = new ArrayList(); GetMapVisibleILayers(m_iApp.FocusMap, null, arrayList); for (int i = 0; i < arrayList.Count; i++) { IFeatureLayer featureLayer = arrayList[i] as IFeatureLayer; if (featureLayer != null && featureLayer.FeatureClass != null && featureLayer.Visible && m_Config.IsPipelineLayer(featureLayer.FeatureClass.AliasName, enumPipelineDataType.Line)) { IPipelineLayer pipeLayer = m_Config.GetPipelineLayer(featureLayer.FeatureClass.AliasName, enumPipelineDataType.Line); IFeatureDataset featureDataset = featureLayer.FeatureClass.FeatureDataset; IFeatureClassContainer featureClassContainer = featureDataset as IFeatureClassContainer; List <IBasicLayerInfo> basicInfos = pipeLayer.GetLayers(enumPipelineDataType.Junction); IFeatureClass featureClass = basicInfos.Count > 0 ? basicInfos[0].FeatureClass : null; if (featureClass != null && featureClass is INetworkClass) { IGeometricNetwork geometricNetwork = ((INetworkClass)featureClass).GeometricNetwork; IPointToEID pointToEIDClass = new PointToEID(); pointToEIDClass.SourceMap = (m_iApp.FocusMap); pointToEIDClass.GeometricNetwork = (geometricNetwork); pointToEIDClass.SnapTolerance = (m_iApp.ActiveView.Extent.Width / 200.0); int edgeID = 0; IPoint location = null; double percent = 0; pointToEIDClass.GetNearestEdge(this.ipoint_0, out edgeID, out location, out percent); if (location != null && num > percent) { num = percent; _pipeLayer = pipeLayer; this._nearestEdgeInfo.GeometricNetwork = geometricNetwork; this._nearestEdgeInfo.Percent = percent; this._nearestEdgeInfo.EdgeID = edgeID; this._nearestEdgeInfo.Location = location; flag = true; break; } } } } arrayList.Clear(); if (flag) { this.DrawBrokeEdge(); } return(flag); }
/// <summary> /// 获取网络数据 /// </summary> /// <param name="netCollection"></param> /// <param name="index"></param> /// <returns></returns> public static IGeometricNetwork GetGeometricNetWork(string dbFileName, string datasetName, int index) { INetworkCollection netCollection = OpenNetworkCollection(dbFileName, datasetName); if (index < 0 || index >= netCollection.GeometricNetworkCount) { throw new Exception("索引异常"); } IGeometricNetwork pGeoNet = netCollection.get_GeometricNetwork(index); return(pGeoNet); }
private bool InitializeNetworkAndMap(IFeatureDataset FeatureDataset) { bool flag = false; try { IFeatureLayer layer; int num; this.m_ipGeometricNetwork = ((INetworkCollection)FeatureDataset).get_GeometricNetwork(0); INetwork network = this.m_ipGeometricNetwork.Network; if (this.m_ipMap == null) { this.m_ipMap = new MapClass(); IFeatureClassContainer ipGeometricNetwork = (IFeatureClassContainer)this.m_ipGeometricNetwork; for (num = 0; num < ipGeometricNetwork.ClassCount; num++) { IFeatureClass class2 = ipGeometricNetwork.get_Class(num); layer = new FeatureLayerClass { FeatureClass = class2 }; this.m_ipMap.AddLayer(layer); } } IEnvelope envelope = new EnvelopeClass(); for (num = 0; num < this.m_ipMap.LayerCount; num++) { layer = (IFeatureLayer)this.m_ipMap.get_Layer(num); IGeoDataset dataset = (IGeoDataset)layer; IEnvelope extent = dataset.Extent; envelope.Union(extent); } this.m_ipPointToEID = new PointToEIDClass(); this.m_ipPointToEID.SourceMap = this.m_ipMap; this.m_ipPointToEID.GeometricNetwork = this.m_ipGeometricNetwork; double width = envelope.Width; double height = envelope.Height; if (width > height) { this.m_ipPointToEID.SnapTolerance = width / 100.0; } else { this.m_ipPointToEID.SnapTolerance = height / 100.0; } flag = true; } catch (Exception exception) { MessageBox.Show(exception.ToString()); } return(flag); }
public static void pathToPolyline(IGeometricNetwork pGeometricNetwork, IActiveView pActiveView, IEnumNetEID pEnumNetEID_Edges) { try { IEIDHelper piEIDHelper = new EIDHelperClass(); piEIDHelper.GeometricNetwork = pGeometricNetwork; piEIDHelper.OutputSpatialReference = pActiveView.FocusMap.SpatialReference; piEIDHelper.ReturnFeatures = true; IPolyline mPolyline = new PolylineClass(); mPolyline.SpatialReference = pActiveView.FocusMap.SpatialReference; IEIDInfo ipEIDInfo; IEnumEIDInfo piEnumEIDInfo; IGeometry ipGeometry = null; piEnumEIDInfo = piEIDHelper.CreateEnumEIDInfo(pEnumNetEID_Edges); IGeometryCollection pGeoCollection = mPolyline as IGeometryCollection; piEnumEIDInfo.Reset(); object objMiss = Type.Missing; for (int ii = 0; ii < piEnumEIDInfo.Count; ii++) { ipEIDInfo = piEnumEIDInfo.Next(); ipGeometry = ipEIDInfo.Feature.Shape; if (ipGeometry != null) { Utility.drawPolyline(pActiveView, ipGeometry as IPolyline); } } //return ipGeometry as IPolyline; } catch (Exception e) { MessageBox.Show(e.Message); } finally { } }
private bool loadGeometricNetworkFromServer(IServerObjectHelper serverObjectHelper, ServerLogger logger) { bool result = false; if (null != serverObjectHelper) { try { IMapServer3 mapServer = (IMapServer3)serverObjectHelper.ServerObject; IMapServerDataAccess da = (IMapServerDataAccess)mapServer; IMapLayerInfos layerInfos = mapServer.GetServerInfo(mapServer.DefaultMapName).MapLayerInfos; IFeatureDataset ftrDataset = null; for (int i = 0; i < layerInfos.Count; i++) { IMapLayerInfo lyrInfo = layerInfos.get_Element(i); if (lyrInfo.IsFeatureLayer) { IFeatureClass ftrClass = (IFeatureClass)da.GetDataSource(mapServer.DefaultMapName, lyrInfo.ID); if (null == ftrDataset && ftrClass.FeatureDataset.Name == this.networkName) { ftrDataset = ftrClass.FeatureDataset; } if (esriFeatureType.esriFTSimpleEdge == ftrClass.FeatureType) { this.addEdgeFeatureClass(ftrClass); } else if (esriFeatureType.esriFTSimpleJunction == ftrClass.FeatureType) { this.addJunctionFeatureClass(ftrClass); } } } if (this.edgeCount > 0 && this.junctionCount > 0 && null != ftrDataset) { INetworkCollection networkCollection = ftrDataset as INetworkCollection; if (networkCollection != null && networkCollection.GeometricNetworkCount > 0) { this.geometricNetwork = networkCollection.GeometricNetwork[0]; result = true; } } } catch (Exception e) { if (null != logger) { logger.LogMessage(ServerLogger.msgType.error, typeof(NetworkHelper).Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, GLC.AO.AOUtilities.ErrorCode, e.Message); } } } return(result); }
/// <summary> /// Builds the <see cref="IEnumNetEID" /> from the specified list of elements. /// </summary> /// <param name="source">The source.</param> /// <param name="elementType">Type of the element.</param> /// <param name="eids">The eids.</param> /// <returns> /// A <see cref="IEnumNetEID" /> from the list of elements. /// </returns> /// <exception cref="System.ArgumentNullException">eids</exception> public static IEnumNetEID CreateEnumNetEID(this IGeometricNetwork source, esriElementType elementType, List <int> eids) { if (source == null) { return(null); } if (eids == null) { throw new ArgumentNullException("eids"); } return(source.CreateEnumNetEID(elementType, eids.ToArray())); }
public IFeature GetEIDFeature(IGeometricNetwork geometricNetwork, int eid, esriElementType elementType) { int userClassId, userId, userSubId; bool isValid = ((INetElements)geometricNetwork.Network).IsValidElement(eid, elementType); ((INetElements)geometricNetwork.Network).QueryIDs(eid, elementType, out userClassId, out userId, out userSubId); if (!isValid) { return(null); } return(FindFeature(GetEnumFeatureClasses(geometricNetwork, esriFeatureType.esriFTSimpleEdge), userClassId, userId)); }
/// <summary> /// Gets the network element identifier for the network feature. /// </summary> /// <param name="source">The source.</param> /// <param name="elementType">Type of the element.</param> /// <returns> /// Returns a <see cref="int" /> representing the network element identifier. /// </returns> public static int GetEID(this INetworkFeature source, out esriElementType elementType) { IGeometricNetwork geometricNetwork = source.GeometricNetwork; INetwork network = geometricNetwork.Network; INetElements netElements = (INetElements)network; ISimpleJunctionFeature sjf = source as ISimpleJunctionFeature; elementType = sjf != null ? esriElementType.esriETJunction : esriElementType.esriETEdge; IFeature feature = (IFeature)source; int eid = netElements.GetEID(feature.Class.ObjectClassID, feature.OID, -1, elementType); return(eid); }
/// <summary> /// Checks the if the trace weight is set on the geometric network /// </summary> /// <param name="source">The geometric network.</param> /// <param name="weightName">Name of the trace weight.</param> /// <returns> /// Returns a <see cref="bool" /> representing <c>true</c> if the weight exists; otherwise <c>false</c>. /// </returns> /// <exception cref="System.ArgumentNullException">weightName</exception> public static bool IsAssignedWeightName(this IGeometricNetwork source, string weightName) { if (source == null) { return(false); } if (weightName == null) { throw new ArgumentNullException("weightName"); } string[] names = { weightName, weightName.ToLowerInvariant(), weightName.ToUpperInvariant() }; INetSchema netSchema = (INetSchema)source.Network; return(names.Select(name => netSchema.WeightByName[name]).Any(netWeight => netWeight != null)); }
/// <summary> /// 最短路径分析 /// </summary> /// <param name="pMap"></param> /// <param name="pGeometricNet"></param> /// <param name="pCollection"></param> /// <param name="weightName"></param> /// <param name="pDisc"></param> /// <returns></returns> public static IPolyline DistanceFun(IMap pMap, IGeometricNetwork pGeometricNet, IPointCollection pCollection, string weightName, double pDisc) { //几何网络分析接口 ITraceFlowSolverGEN pTraceFlowGen = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver pNetSolver = pTraceFlowGen as INetSolver; //获取网络 INetwork pNetwork = pGeometricNet.Network; //设置该网络为几何分析处理网络 pNetSolver.SourceNetwork = pNetwork; //网络元素 INetElements pNetElements = pNetwork as INetElements; //根据输入点建立旗帜数组 IJunctionFlag[] pJunctionFlags = GetJunctionFlags(pMap, pGeometricNet, pCollection, pDisc); //将旗帜数组添加到处理类中 pTraceFlowGen.PutJunctionOrigins(ref pJunctionFlags); //设置边线的权重 可以考虑使用点权重 SetWeight(weightName, pTraceFlowGen, pNetwork); //获取边线和交汇点的集合 IEnumNetEID junctionEIDs; IEnumNetEID netEIDS; object[] pRec = new object[pCollection.PointCount - 1]; pTraceFlowGen.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out junctionEIDs, out netEIDS, pCollection.PointCount - 1, ref pRec); //获取最短路径 IPolyline pPolyline = new PolylineClass(); IGeometryCollection pGeometryCollection = pPolyline as IGeometryCollection; ISpatialReference pSpatialReference = pMap.SpatialReference; IEIDHelper pEIDHelper = new EIDHelperClass(); pEIDHelper.GeometricNetwork = pGeometricNet; pEIDHelper.OutputSpatialReference = pSpatialReference; pEIDHelper.ReturnGeometries = true; IEnumEIDInfo pEnumEIDInfo = pEIDHelper.CreateEnumEIDInfo(netEIDS); int Count = pEnumEIDInfo.Count; pEnumEIDInfo.Reset(); for (int i = 0; i < Count; i++) { IEIDInfo pEIDInfo = pEnumEIDInfo.Next(); IGeometry pGeometry = pEIDInfo.Geometry; pGeometryCollection.AddGeometryCollection(pGeometry as IGeometryCollection); } return(pPolyline); }
/// <summary> /// Builds the <see cref="IEnumNetEID" /> from the specified list of elements. /// </summary> /// <param name="source">The source.</param> /// <param name="elementType">Type of the element.</param> /// <param name="eids">The network element IDs.</param> /// <returns> /// A <see cref="IEnumNetEID" /> from the list of elements. /// </returns> /// <exception cref="System.ArgumentNullException">eids</exception> public static IEnumNetEID CreateEnumNetEID(this IGeometricNetwork source, esriElementType elementType, params int[] eids) { if (source == null) { return(null); } if (eids == null) { throw new ArgumentNullException("eids"); } IEnumNetEIDBuilderGEN builder = new EnumNetEIDArrayClass(); builder.ElementType = elementType; builder.Network = source.Network; builder.set_EIDs(ref eids); return((IEnumNetEID)builder); }
/// <summary> /// Returns the <see cref="IEIDInfo" /> for the specified network element. /// </summary> /// <param name="source">The source.</param> /// <param name="eid">The element ID.</param> /// <param name="elementType">Type of the element.</param> /// <param name="returnFeatures">if set to <c>true</c> if the created IEIDInfo should contain features.</param> /// <param name="returnGeometries">if set to <c>true</c> if the created EIDInfo should contain geometries.</param> /// <returns> /// Returns the <see cref="IEIDInfo" /> interface for the network element. /// </returns> public static IEIDInfo GetEIDInfo(this IGeometricNetwork source, int eid, esriElementType elementType, bool returnFeatures, bool returnGeometries) { if (source == null) { return(null); } IEnumNetEID enumNetEID = source.CreateEnumNetEID(elementType, eid); IEIDHelper eidHelper = new EIDHelperClass(); eidHelper.GeometricNetwork = source; eidHelper.ReturnFeatures = returnFeatures; eidHelper.ReturnGeometries = returnGeometries; IEnumEIDInfo enumEIDInfo = eidHelper.CreateEnumEIDInfo(enumNetEID); IEIDInfo eidInfo = enumEIDInfo.Next(); return(eidInfo); }
private void SetBut_Click(object obj, EventArgs eventArgs) { int selectedIndex = this.NetWorkCombo.SelectedIndex; if (selectedIndex >= 0 && this.MapControl != null) { IFeatureLayer ifeatureLayer_ = ((SetFlowToolForm.Class2) this.NetWorkCombo.SelectedItem).ifeatureLayer_0; INetworkClass networkClass = ifeatureLayer_.FeatureClass as INetworkClass; if (networkClass != null) { IGeometricNetwork geometricNetwork = networkClass.GeometricNetwork; INetwork network = geometricNetwork.Network; IDataset dataset = (IDataset)ifeatureLayer_.FeatureClass; IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)dataset.Workspace; if (!workspaceEdit.IsBeingEdited()) { MessageBox.Show("数据不可编辑"); } else { workspaceEdit.StartEditOperation(); geometricNetwork.EstablishFlowDirection(); if (this.WayCombo.SelectedIndex == 0) { this.method_4(network); } else if (this.WayCombo.SelectedIndex == 1) { this.method_6(geometricNetwork); } else if (this.WayCombo.SelectedIndex == 2) { this.method_5(geometricNetwork); } workspaceEdit.StopEditOperation(); MessageBox.Show("操作完成!"); base.Close(); } } } }
private void method_5(IGeometricNetwork geometricNetwork) { INetwork network = geometricNetwork.Network; IUtilityNetwork utilityNetwork = (IUtilityNetwork)network; IEnumNetEID enumNetEID = network.CreateNetBrowser((esriElementType)2); IEIDHelper eIDHelperClass = new EIDHelper(); eIDHelperClass.GeometricNetwork = (geometricNetwork); eIDHelperClass.DisplayEnvelope = (null); eIDHelperClass.OutputSpatialReference = (null); eIDHelperClass.ReturnFeatures = (true); eIDHelperClass.ReturnGeometries = (true); eIDHelperClass.PartialComplexEdgeGeometry = (true); IEnumEIDInfo enumEIDInfo = eIDHelperClass.CreateEnumEIDInfo(enumNetEID); enumEIDInfo.Reset(); long num = (long)enumEIDInfo.Count; int num2 = 0; while ((long)num2 < num) { IEIDInfo iEIDInfo = enumEIDInfo.Next(); int eID = iEIDInfo.EID; IFeature feature = iEIDInfo.Feature; int num3 = feature.Fields.FindField("流向"); if (num3 < 0) { utilityNetwork.SetFlowDirection(eID, (esriFlowDirection)1); } if (Convert.ToBoolean(feature.get_Value(num3))) { utilityNetwork.SetFlowDirection(eID, (esriFlowDirection)2); } else { utilityNetwork.SetFlowDirection(eID, (esriFlowDirection)1); } num2++; } }
private void LoadGeometryNetwork() { if (Mapcontrol == null) { return; } for (int i = 0; i < Mapcontrol.LayerCount; i++) { IFeatureLayer pfteLyr = Mapcontrol.get_Layer(i) as IFeatureLayer; //获取要素数据集 IFeatureDataset fteDataset = pfteLyr.FeatureClass.FeatureDataset; //获取网络数据集合 INetworkCollection2 netcoll = fteDataset as INetworkCollection2; //获取数据集 m_GeometryNetwork = netcoll.get_GeometricNetwork(0); if (m_GeometryNetwork == null) { continue; } else { //获取逻辑网络数据集 netsolver.SourceNetwork = m_GeometryNetwork.Network; //获取几何网络数据名 IDataset dataset = m_GeometryNetwork as IDataset; if (!this.NetlistCmbx.Items.Contains(dataset.Name)) { this.NetlistCmbx.Items.Add(dataset.Name); } break; } } if (this.NetlistCmbx.Items.Count == 0) { return; } this.NetlistCmbx.Text = this.NetlistCmbx.Items[0].ToString(); }
/// <summary> /// 路径分析结果到几何要素的转换 /// </summary> /// <param name="pMap">当前地图 获取空间参考</param> /// <returns></returns> public IPolyline PathToPolyLine(IMap pMap, IGeometricNetwork mGeometricNetwork, IEnumNetEID mEnumNetEID_Edges) { IPolyline pPolyLine = new PolylineClass(); IGeometryCollection pNewGeometryCollection = pPolyLine as IGeometryCollection; if (mEnumNetEID_Edges == null) { return(null); } IEIDHelper pEIDHelper = new EIDHelperClass(); //获取几何网络 pEIDHelper.GeometricNetwork = mGeometricNetwork; //获取地图空间参考 ISpatialReference pSpatialReference = pMap.SpatialReference; pEIDHelper.OutputSpatialReference = pSpatialReference; pEIDHelper.ReturnGeometries = true; //根据边的ID获取边的信息 IEnumEIDInfo pEnumEIDInfo = pEIDHelper.CreateEnumEIDInfo(mEnumNetEID_Edges); int intCount = pEnumEIDInfo.Count; pEnumEIDInfo.Reset(); IEIDInfo pEIDInfo; IGeometry pGeometry; for (int i = 0; i < intCount; i++) { pEIDInfo = pEnumEIDInfo.Next(); //获取边的几何要素 pGeometry = pEIDInfo.Geometry; pNewGeometryCollection.AddGeometryCollection((IGeometryCollection)pGeometry); } return(pPolyLine); }
/// <summary> /// 根据输入点建立旗帜数组 /// </summary> /// <param name="pGeometricNet"></param> /// <param name="pCollection"></param> /// <param name="pDisc"></param> /// <param name="pNetElements"></param> /// <returns></returns> private static IJunctionFlag[] GetJunctionFlags(IMap pMap, IGeometricNetwork pGeometricNet, IPointCollection pCollection, double pDisc) { INetElements pNetElements = pGeometricNet.Network as INetElements; int pCount = pCollection.PointCount; IJunctionFlag[] pJunctionFlags = new JunctionFlagClass[pCount]; IPointToEID pPointToEID = new PointToEIDClass(); pPointToEID.SourceMap = pMap; pPointToEID.GeometricNetwork = pGeometricNet; //从输入点找最近节点的距离阈值 pPointToEID.SnapTolerance = pDisc; for (int i = 0; i < pCount; i++) { INetFlag pNetFlag = new JunctionFlagClass(); IPoint pEdgePoint = pCollection.get_Point(i); #region 查找输入点最近的节点的ID int nearestJunctionID; IPoint locationPoint; int userClassID; int userID; int userSubID; pPointToEID.GetNearestJunction(pEdgePoint, out nearestJunctionID, out locationPoint); pNetElements.QueryIDs(nearestJunctionID, esriElementType.esriETJunction, out userClassID, out userID, out userSubID); #endregion //设置网络旗帜的节点的ID pNetFlag.UserClassID = userClassID; pNetFlag.UserID = userID; pNetFlag.UserSubID = userSubID; //节点旗帜 IJunctionFlag pJuncF = pNetFlag as IJunctionFlag; //添加 pJunctionFlags[i] = pJuncF; } return(pJunctionFlags); }
private IFeatureClass GetFeatureClassByClassId(int classId, IGeometricNetwork geomNetwork) { IEnumFeatureClass enumFC; IFeatureClass fc; enumFC = geomNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleEdge); fc = enumFC.Next(); while (fc != null) { if (fc.FeatureClassID == classId) return fc; fc = enumFC.Next(); } enumFC = geomNetwork.get_ClassesByType(esriFeatureType.esriFTComplexEdge); fc = enumFC.Next(); while (fc != null) { if (fc.FeatureClassID == classId) return fc; fc = enumFC.Next(); } return null; }
//初始化 private bool InitializeNetworkAndMap(IFeatureDataset Featuredataset,System.Collections.ArrayList array1,System.Collections.ArrayList array2,int flag) { IFeatureClassContainer ipFeatureClassContainer; IFeatureClass ipFeatureClass; IGeoDataset ipGeoDataset; ILayer ipLayer; IFeatureLayer ipFeatureLayer; IEnvelope ipEnvelope, ipMaxEnvelope; double dblSearchTol; INetworkCollection ipNetworkCollection = Featuredataset as INetworkCollection; int count = ipNetworkCollection.GeometricNetworkCount; barrierarray1 =(System.Collections.ArrayList)array1.Clone(); barrierarray2 = (System.Collections.ArrayList)array2.Clone(); barrierflag = flag; //获取几何网络工作空间 m_ipGeometricNetwork = ipNetworkCollection.get_GeometricNetwork(0); INetwork ipNetwork = m_ipGeometricNetwork.Network; if (m_ipMap != null) { m_ipMap = new MapClass(); ipFeatureClassContainer = m_ipGeometricNetwork as IFeatureClassContainer; count = ipFeatureClassContainer.ClassCount; for (int i = 0; i < count; i++) { ipFeatureClass = ipFeatureClassContainer.get_Class(i); ipFeatureLayer = new FeatureLayerClass(); ipFeatureLayer.FeatureClass = ipFeatureClass; m_ipMap.AddLayer(ipFeatureLayer); } } count = m_ipMap.LayerCount; ipMaxEnvelope = new EnvelopeClass(); for (int i = 0; i < count; i++) { ipLayer = m_ipMap.get_Layer(i); ipFeatureLayer = ipLayer as IFeatureLayer; ipGeoDataset = ipFeatureLayer as IGeoDataset; ipEnvelope = ipGeoDataset.Extent; ipMaxEnvelope.Union(ipEnvelope); } m_ipPointToEID = new PointToEIDClass(); m_ipPointToEID.SourceMap = m_ipMap; m_ipPointToEID.GeometricNetwork = m_ipGeometricNetwork; double dblWidth = ipMaxEnvelope.Width; double dblHeight = ipMaxEnvelope.Height; if (dblWidth > dblHeight) dblSearchTol = dblWidth / 100; else dblSearchTol = dblHeight / 100; m_ipPointToEID.SnapTolerance = dblSearchTol; return true; }
//�����ٵĽ�� public static void FindStreamTraceResult(AxMapControl ppAxMapControl, INetFlag ipNetFlag, IGeometricNetwork pGeoNetwork) { try { IEnumNetEID m_ipEnumNetEID_Junctions, m_ipEnumNetEID_Edges;//����������������Junctions��Edges IJunctionFlag[] pArrayJFlag = new IJunctionFlag[1]; pArrayJFlag[0] = ipNetFlag as IJunctionFlag; ITraceFlowSolverGEN ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; //get the inetsolver interface INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver; ipNetSolver.SourceNetwork = pGeoNetwork.Network; ipTraceFlowSolver.PutJunctionOrigins(ref pArrayJFlag); ipTraceFlowSolver.TraceIndeterminateFlow = false; object[] totalCost = new object[1]; //ipTraceFlowSolver.FindSource(esriFlowMethod.esriFMUpstream,esriShortestPathObjFn.esriSPObjFnMinSum,out m_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges,1,ref totalCost); ipTraceFlowSolver.FindFlowElements(esriFlowMethod.esriFMUpstream, esriFlowElements.esriFEEdges, out m_ipEnumNetEID_Junctions, out m_ipEnumNetEID_Edges); //ma //SpatialHelperFunction.pathToPolyline(pGeoNetwork, ppAxMapControl.ActiveView, m_ipEnumNetEID_Edges); //UpStreamFindParcels(ppAxMapControl, m_ipEnumNetEID_Edges,pGeoNetwork); } catch (Exception eX) { MessageBox.Show(eX.Message); } }
//��˷�ٲ��ҹ����漰�ĵؿ� public static void UpStreamFindParcels(AxMapControl ppAxMapControl, IEnumNetEID pEnumResultEdges, IGeometricNetwork pGeoNetwork) { try { IFeatureLayer pFeatLayerSewerLines = FindFeatLayer("Sewer Lines", ppAxMapControl); IFeatureLayer pFeatLayerParcels = FindFeatLayer("Parcels", ppAxMapControl); //����ѡ���Sewer�������д������ΰ� IGeometryCollection pGeomBag = new GeometryBagClass(); object missing = Type.Missing; int lEID; int iUserClassID; int iUserID; int iUserSubID; INetElements pNetElements = pGeoNetwork.Network as INetElements; pEnumResultEdges.Reset(); IFeature pFeature; for (int j = 0; j <= pEnumResultEdges.Count - 1; j++) { lEID = pEnumResultEdges.Next(); pNetElements.QueryIDs(lEID, esriElementType.esriETEdge, out iUserClassID, out iUserID, out iUserSubID); pFeature = pFeatLayerSewerLines.FeatureClass.GetFeature(iUserID); pGeomBag.AddGeometry(pFeature.Shape, ref missing, ref missing); // MessageBox.Show(iUserClassID.ToString()+","+iUserID.ToString()+","+iUserSubID.ToString()); } //���пռ����˵��Ӳ��������ڲ��ҵؿ���Ϣ ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.Geometry = pGeomBag as IGeometry; pSpatialFilter.GeometryField = "Shape"; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.SearchOrder = esriSearchOrder.esriSearchOrderSpatial; //��ý��浽�ĵؿ���Ϣ IFeatureCursor pFeatCursor = pFeatLayerParcels.FeatureClass.Search(pSpatialFilter, false); //���ӱ�ѡ��ĵؿ����ݵ���ͼ��ͼ��ͼ�������� ICompositeGraphicsLayer pComGraphicLayer = new CompositeGraphicsLayerClass(); ILayer pLayer = pComGraphicLayer as ILayer; pLayer.Name = "��Ӱ��ĵؿ�"; IGraphicsContainer pGraphicContainer = pComGraphicLayer as IGraphicsContainer; //������ѡ��ĵؿ鵽ͼ�������� ISimpleFillSymbol pSymFill = new SimpleFillSymbolClass(); IFillSymbol pFillSymbol = pSymFill as IFillSymbol; IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 0; pRgbColor.Green = 200; pRgbColor.Blue = 100; pFillSymbol.Color = pRgbColor as IColor; ICartographicLineSymbol pCartoLine = new CartographicLineSymbolClass(); IRgbColor pRgbColor2 = new RgbColorClass(); pRgbColor2.Red = 100; pRgbColor2.Green = 200; pRgbColor2.Blue = 100; pCartoLine.Width = 2; pCartoLine.Color = pRgbColor2 as IColor; pFillSymbol.Outline = pCartoLine; //����������еؿ����������� IArray pFeatArray = new ArrayClass(); pFeature = pFeatCursor.NextFeature(); while (pFeature != null) { IElement pPolyElement = new PolygonElementClass(); IFillShapeElement pFillShapeElement = pPolyElement as IFillShapeElement; pPolyElement.Geometry = pFeature.Shape; pFillShapeElement.Symbol = pFillSymbol; pGraphicContainer.AddElement(pPolyElement, 0); pFeatArray.Add(pFeature); pFeature = pFeatCursor.NextFeature(); } ppAxMapControl.AddLayer(pGraphicContainer as ILayer); ppAxMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //ma //frmUpstreamCreateOwnerList frmUpstreamCreateOwnerList1 = new frmUpstreamCreateOwnerList(ppAxMapControl,pFeatLayerParcels, pFeatArray); //frmUpstreamCreateOwnerList1.Show(); } catch (Exception eX) { MessageBox.Show(eX.Message); } }
//�������ĸ߳����� public static void ProfileGetRelatedSewerElevData(AxMapControl ppAxMapControl, IGeometricNetwork pGeoNetwork, IEnumNetEID pResultEdges, IEnumNetEID pResultJunctions) { try { //��ñ������Զ�Ӧ�������ٽ�� IArray pSewerElevArray = new ArrayClass(); IEIDHelper pEIDHelper = new EIDHelperClass(); pEIDHelper.GeometricNetwork = pGeoNetwork; pEIDHelper.ReturnFeatures = true; pEIDHelper.ReturnGeometries = true; pEIDHelper.PartialComplexEdgeGeometry = true; pEIDHelper.AddField("Component_Key2"); IEnumEIDInfo pEnumEIDInfo = pEIDHelper.CreateEnumEIDInfo(pResultEdges); //������������ص�������¼ pEnumEIDInfo.Reset(); IEIDInfo pEIDInfo = pEnumEIDInfo.Next(); IFeature pFeature = pEIDInfo.Feature; IGeometry pFeatGeo = pEIDInfo.Geometry; //�������л�ù�ϵ IEnumRelationshipClass pEnumRelationshipCls = pFeature.Class.get_RelationshipClasses(esriRelRole.esriRelRoleOrigin); pEnumRelationshipCls.Reset(); IRelationshipClass pRelationshipCls = pEnumRelationshipCls.Next(); //�����ȷ�Ĺ�ϵ�� string s = "SewerToMainline"; while (pRelationshipCls != null) { if (pRelationshipCls.ForwardPathLabel.ToUpper() == s.ToUpper()) break; else pRelationshipCls = pEnumRelationshipCls.Next(); } //��ѯ���ɹ�����ÿ������ص����ݣ������1-1�Ĺ�ϵ����ֻ����һ����¼ // because the arcs are ordered and directional, if the start node is an // fnode then get subsequent tnode's for the rest of the arcs, else if the // start node is a tnode, get subsequent fnode's. Related data has elev // attributes for up and down stream manhole elevs, so related to from and to node of arc. // get the first junction in the network trace results to determine if the //first junction is a from-node or a to-node for graphing sewer line elev if (pRelationshipCls != null) { ISet pMainlineRelatedSet; IRow pMainlineRow; IEIDHelper pEIDHelper2 = new EIDHelperClass(); pEIDHelper2.GeometricNetwork = pGeoNetwork; pEIDHelper2.ReturnFeatures = true; pEIDHelper2.ReturnGeometries = true; pEIDHelper2.PartialComplexEdgeGeometry = true; IEnumEIDInfo pEnumEIDInfo2 = pEIDHelper2.CreateEnumEIDInfo(pResultJunctions); pEnumEIDInfo2.Reset(); //pFeature is the first arc in the network trace results // check the junctions on the first arc to see which is the starting // junction, this determines which sewer elev attribute (ups_elev, dwn_elev) // will be used to calculate the sewer line profile IEdgeFeature pEdgeFeat = pFeature as IEdgeFeature; string strStartAttr; string strMHelevAttr; double lastelev = 0; int lastnodeEID; if (pEnumEIDInfo2.Next().EID == pEdgeFeat.FromJunctionEID) { // trace is in the direction of flow, flow goes down hill strStartAttr = "Ups_elev"; strMHelevAttr = "Dwn_elev"; } else { //trace is in the opposite direction of flow, flow goes up hill strStartAttr = "Dwn_elev"; strMHelevAttr = "Ups_elev"; } lastnodeEID = pEnumEIDInfo2.Next().EID; // create a polyline from the result junctions, make the polyline in the //direction of the trace, not in the direction of the original arcs/edges IPolyline pPolyline = new PolylineClass(); IPointCollection pPointColl = pPolyline as IPointCollection; pEnumEIDInfo2.Reset(); object missing = Type.Missing; for (int i = 0; i <= pEnumEIDInfo2.Count - 1; i++) { pPointColl.AddPoint(pEnumEIDInfo2.Next().Geometry as IPoint, ref missing, ref missing); } ISegmentCollection pSegColl = pPolyline as ISegmentCollection; //����� ITopologicalOperator pTopoOp = pPolyline as ITopologicalOperator; pTopoOp.Simplify(); pPolyline.SimplifyNetwork(); pPolyline.Densify(50, 0.01); pResultEdges.Reset(); pEnumEIDInfo2.Reset(); IPolyline pNewSegPolyline; IPolyline pPolyLineFeat; IRelationalOperator pRelOpFeat; ISegmentCollection pNewSegColl; ISegmentCollection pSegmentColl = pPolyline as ISegmentCollection; for (int i = 0; i <= pResultEdges.Count - 1; i++) { pMainlineRelatedSet = pRelationshipCls.GetObjectsRelatedToObject(pFeature); pMainlineRelatedSet.Reset(); pMainlineRow = pMainlineRelatedSet.Next() as IRow; pPolyLineFeat = pFeature.Shape as IPolyline; pRelOpFeat = pPolyLineFeat as IRelationalOperator; for (int j = 0; j <= pSegmentColl.SegmentCount - 1; j++) { pNewSegPolyline = new PolylineClass(); pNewSegColl = pNewSegPolyline as ISegmentCollection; pNewSegColl.AddSegment(pSegmentColl.get_Segment(j), ref missing, ref missing); if (pRelOpFeat.Contains(pNewSegPolyline as IGeometry)) { if (j == 0) { pSewerElevArray.Add(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strStartAttr))); lastelev = Convert.ToDouble(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strMHelevAttr))); } else { if (lastelev == Convert.ToDouble(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strMHelevAttr)))) { pSewerElevArray.Add(-99); } else { pSewerElevArray.Add(lastelev); lastelev = Convert.ToDouble(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strMHelevAttr))); } } } } // get the next feature and check to see what direction it's going and //adjust the variables accordingly if (i < pResultEdges.Count - 1) { lastnodeEID = pEdgeFeat.ToJunctionEID; pFeature = pEnumEIDInfo.Next().Feature; pEdgeFeat = pFeature as IEdgeFeature; if (pEdgeFeat.FromJunctionEID == lastnodeEID) strMHelevAttr = "Dwn_elev"; else strMHelevAttr = "Ups_elev"; } else { pSewerElevArray.Add(pMainlineRow.get_Value(pMainlineRow.Fields.FindField(strMHelevAttr))); } } ProfileCreateGraph(ppAxMapControl, pPolyline, pSewerElevArray); } } catch (Exception eX) { MessageBox.Show(eX.Message); } }
private IDictionary<int, SelectedObjects> GetClassIDs(IGeometricNetwork pGN) { IDictionary<int, SelectedObjects> dicIDs; IEnumFeatureClass pEFC; IFeatureClass pFC; IDataset pDS; SelectedObjects pSelObjs; try { dicIDs = new Dictionary<int, SelectedObjects>(); pEFC = pGN.get_ClassesByType(ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTComplexEdge); pFC = pEFC.Next(); while (pFC != null) { if (!dicIDs.ContainsKey(pFC.FeatureClassID)) { pDS = (IDataset)pFC; pSelObjs = new SelectedObjects(pFC); dicIDs.Add(pFC.FeatureClassID, pSelObjs); } pFC = pEFC.Next(); } pEFC = pGN.get_ClassesByType(ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimpleEdge); pFC = pEFC.Next(); while (pFC != null) { if (!dicIDs.ContainsKey(pFC.FeatureClassID)) { pDS = (IDataset)pFC; pSelObjs = new SelectedObjects(pFC); dicIDs.Add(pFC.FeatureClassID, pSelObjs); } pFC = pEFC.Next(); } pEFC = pGN.get_ClassesByType(ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimpleJunction); pFC = pEFC.Next(); while (pFC != null) { if (!dicIDs.ContainsKey(pFC.FeatureClassID)) { pDS = (IDataset)pFC; pSelObjs = new SelectedObjects(pFC); dicIDs.Add(pFC.FeatureClassID, pSelObjs); } pFC = pEFC.Next(); } Marshal.ReleaseComObject(pEFC); return dicIDs; } catch (Exception EX) { this.Logger.WriteLine("GetClassIDs Error" + EX.Message + " " + EX.StackTrace); return null; } }
public static string TracePath(double[] Xs, double[] Ys, string GeoNetName, IApplication app, IMap map, bool traceIndeterminate, double snapTol, bool selectEdges, out IEnumNetEID juncEIDs, out IEnumNetEID edgeEIDs, out IGeometricNetwork gn) { gn = null; juncEIDs = null; edgeEIDs = null; List<INetFlag> pNetFlags = null; IFlagDisplay pFlagDisplay = null; IJunctionFlag[] junctionFlags = null; IEdgeFlag[] edgeFlags = null; ITraceFlowSolverGEN traceFlowSolver = null; List<IEdgeFlag> pEdgeFlags = null; List<IJunctionFlag> pJunctionFlags = null; INetElementBarriers pEdgeElementBarriers; INetElementBarriers pJunctionElementBarriers; ISelectionSetBarriers pSelectionSetBarriers; List<IGeometricNetwork> gnList = null; INetworkAnalysisExt pNetAnalysisExt = null; UID pID = null; try { gnList = Globals.GetGeometricNetworks(ref map); if (gnList == null) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_17a")); return ""; } int gnIdx = -1; gnIdx = Globals.GetGeometricNetwork(ref gnList, GeoNetName); if (gnIdx != -1) { gn = (IGeometricNetwork)gnList[gnIdx]; } pNetFlags = new List<INetFlag>(); // INetFlag[] netFlags = new INetFlag[Xs.Length]; for (int i = 0; i < Xs.Length; i++) { IPoint snappedPoint = null; int EID = -1; if (gn == null) { pNetFlags.Add(Globals.GetJunctionFlag(Xs[i], Ys[i], ref map, ref gnList, snapTol, ref gnIdx, out snappedPoint, out EID, out pFlagDisplay, true) as INetFlag); //Set network to trace if (gnIdx > -1) gn = gnList[gnIdx] as IGeometricNetwork; } else { pNetFlags.Add(Globals.GetJunctionFlagWithGN(Xs[i], Ys[i], ref map, ref gn, ref snapTol, out snappedPoint, out EID, out pFlagDisplay, true) as INetFlag); } } if (gn == null || pNetFlags.Count < 1) { return (A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_17b")); } if (app != null) { pID = new UID(); pID.Value = "esriEditorExt.UtilityNetworkAnalysisExt"; pNetAnalysisExt = (INetworkAnalysisExt)app.FindExtensionByCLSID(pID); Globals.SetCurrentNetwork(ref pNetAnalysisExt, ref gn); traceFlowSolver = Globals.CreateTraceFlowSolverFromToolbar(ref pNetAnalysisExt, out pEdgeFlags, out pJunctionFlags, out pEdgeElementBarriers, out pJunctionElementBarriers, out pSelectionSetBarriers) as ITraceFlowSolverGEN; } else { traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver netSolver = traceFlowSolver as INetSolver; netSolver.SourceNetwork = gn.Network; } traceFlowSolver.TraceIndeterminateFlow = traceIndeterminate; if (pEdgeFlags != null) { foreach (IEdgeFlag pEdFl in pEdgeFlags) { pNetFlags.Add((INetFlag)pEdFl); } } if (pJunctionFlags != null) { foreach (IJunctionFlag pJcFl in pJunctionFlags) { pNetFlags.Add((INetFlag)pJcFl); } } //if (startNetFlag != null) //{ // pNetFlags.Add((INetFlag)startNetFlag); //} Globals.AddFlagsToTraceSolver(pNetFlags.ToArray(), ref traceFlowSolver, out junctionFlags, out edgeFlags); int intCount = 1; System.Object[] segCosts = new System.Object[1]; segCosts[0] = new System.Object(); traceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinMax, out juncEIDs, out edgeEIDs, intCount, ref segCosts); //Select junction features map.ClearSelection(); IJunctionFlag[] junctionFlag = null; Globals.SelectJunctions(ref map, ref gn, ref juncEIDs, ref junctionFlag, "", "", "", true); if (selectEdges) Globals.SelectEdges(ref map, ref gn, ref edgeEIDs); edgeEIDs.Reset(); //Draw edge graphics IEnvelope env = Globals.DrawEdges(ref map, ref gn, ref edgeEIDs); return edgeEIDs.Count.ToString(); } catch (Exception Ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_17a") + "\n" + Ex.Message); return ""; } }
public static void initNetwork(IFeatureDataset pFeaDataset,IMap pMap,out IGeometricNetwork m_ipGeometricNetwork) { INetworkCollection pNetworkCollection; //IGeometricNetwork m_ipGeometricNetwork; INetwork pNetwork; IFeatureClassContainer ipFeatureClassContainer; IFeatureClass ipFeatureClass; IFeatureLayer ipFeatureLayer; IDataset pDataset; //get the network collection pNetworkCollection=pFeaDataset as INetworkCollection; if(pNetworkCollection.GeometricNetworkCount==0) { MessageBox.Show("������û������"); m_ipGeometricNetwork=null; return; } m_ipGeometricNetwork=pNetworkCollection.get_GeometricNetworkByName("Water_Network"); //m_ipGeometricNetwork. //Use the INetwork interface when you want to query the network for general information //such as the status of the network or the number of edges in your network. pNetwork=m_ipGeometricNetwork.Network; //Add each of the Feature Classes in this Geometric Network as a map Layer ipFeatureClassContainer=pNetworkCollection as IFeatureClassContainer; if(ipFeatureClassContainer.ClassCount==0) { MessageBox.Show("û������featureClass"); m_ipGeometricNetwork=null; return; } for(int ii=0;ii<ipFeatureClassContainer.ClassCount;ii++) { ipFeatureClass=ipFeatureClassContainer.get_Class(ii); pDataset=ipFeatureClass as IDataset; if(pDataset.Name=="water_arc"||pDataset.Name.Equals("water_point")||pDataset.Name.Equals("Water_Network_Junctions")) { ipFeatureLayer=new FeatureLayerClass(); ipFeatureLayer.FeatureClass=ipFeatureClass; ipFeatureLayer.Name=pDataset.Name; pMap.AddLayer(ipFeatureLayer); } } }
public static void pathToPolyline(IGeometricNetwork pGeometricNetwork,IActiveView pActiveView,IEnumNetEID pEnumNetEID_Edges) { try { IEIDHelper piEIDHelper=new EIDHelperClass(); piEIDHelper.GeometricNetwork=pGeometricNetwork; piEIDHelper.OutputSpatialReference=pActiveView.FocusMap.SpatialReference; piEIDHelper.ReturnFeatures=true; IPolyline mPolyline=new PolylineClass(); mPolyline.SpatialReference=pActiveView.FocusMap.SpatialReference; IEIDInfo ipEIDInfo; IEnumEIDInfo piEnumEIDInfo; IGeometry ipGeometry=null; piEnumEIDInfo=piEIDHelper.CreateEnumEIDInfo(pEnumNetEID_Edges); IGeometryCollection pGeoCollection=mPolyline as IGeometryCollection; piEnumEIDInfo.Reset(); object objMiss=Type.Missing; for(int ii=0;ii<piEnumEIDInfo.Count;ii++) { ipEIDInfo=piEnumEIDInfo.Next(); ipGeometry=ipEIDInfo.Feature.Shape; if(ipGeometry!=null) Utility.drawPolyline(pActiveView,ipGeometry as IPolyline); } //return ipGeometry as IPolyline; } catch(Exception e) { MessageBox.Show(e.Message); } finally { } }
//������ʩ������� private void menuItem68_Click(object sender, EventArgs e) { axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; m_BasicOperationTool = "isProfileAnalysis"; IMap pMap = axMapControl1.ActiveView.FocusMap; pMap.DelayDrawing(true); CleanUpApp(); //�����ʩ���������еIJ��� IEnvelope pEnv = new EnvelopeClass(); pEnv.XMin = 561900; pEnv.YMin = 42450; pEnv.XMax = 563800; pEnv.YMax = 43676; axMapControl1.ActiveView.Extent = pEnv; //�ù����漰����ͼ�� IArray pLayerNameArray = new ArrayClass(); pLayerNameArray.Add("Sewer Fixtures"); pLayerNameArray.Add("Sewer Lines"); pLayerNameArray.Add("Parcels"); pLayerNameArray.Add("Roads"); SetLayersForApp(pLayerNameArray); //ΪWater fixtures��������ͼ�㶨�� IFeatureLayer pFeatLayer = Utility.FindFeatLayer("Sewer Fixtures", this); IFeatureLayerDefinition pFeatLayerDef = pFeatLayer as IFeatureLayerDefinition; pFeatLayerDef.DefinitionExpression = "[NODE_TYPE] = 'MH'"; IFeatureLayer pFeatLayer2 = Utility.FindFeatLayer("Sewer Lines", this); pFeatLayerDef = pFeatLayer2 as IFeatureLayerDefinition; pFeatLayerDef.DefinitionExpression = "[LINE_TYPE] = 'MG'"; //����ѡ��ͼ�� for (int i = 0; i <= pMap.LayerCount - 1; i++) { if (pMap.get_Layer(i) is IFeatureLayer) { pFeatLayer2 = pMap.get_Layer(i) as IFeatureLayer; if (pFeatLayer2.Name == "Sewer Fixtures") pFeatLayer2.Selectable = true; else pFeatLayer2.Selectable = false; } } //���ָ���ļ������� string sUtilityNetPath; sUtilityNetPath = Application.StartupPath + @"\..\..\..\Data\Sewer9\data\sewer3.mdb"; pGeoNetwork = Utility.openGeoNetwork(sUtilityNetPath, "urban", "Sewer_Network"); pMap.DelayDrawing(false); axMapControl1.ActiveView.Refresh(); }
private IEnumNetEID GetEnumNetEID(int eidToStartFrom, Dictionary<int, int> pathDictionary, INetwork network, IGeometricNetwork geomNet, esriElementType elemType) { IEnumNetEIDBuilder enumEIDBuilder = new EnumNetEIDArrayClass(); enumEIDBuilder.Network = network; enumEIDBuilder.ElementType = elemType; if (eidToStartFrom == -1)//Add all elements to the return dictionary { foreach (KeyValuePair<int, int> kvp in pathDictionary) { int eid = kvp.Key; //Only add to the builder if the element type (junction or edge) is of the type we are looking for if (((eid < 0) && elemType == esriElementType.esriETEdge) || ((eid > 0) && elemType == esriElementType.esriETJunction)) { enumEIDBuilder.Add(Math.Abs( eid)); } } } else { int eid = eidToStartFrom; while (eid != -99999999) // -99999999 means that there is no parent { if (((eid < 0) && elemType == esriElementType.esriETEdge) || ((eid > 0) && elemType == esriElementType.esriETJunction)) { enumEIDBuilder.Add(Math.Abs( eid)); } //Get the junction or edge that feeds this junction or edge eid = pathDictionary[eid]; } } return enumEIDBuilder as IEnumNetEID; }
private void PopulateListView(Dictionary<int, int> pathDictionary, INetwork network, IGeometricNetwork geomNet) { IEnumNetEID netJuncEIDS = GetEnumNetEID(-1, pathDictionary, network, geomNet, esriElementType.esriETJunction); IEnumNetEID netEdgeEIDS = GetEnumNetEID(-1, pathDictionary, network, geomNet, esriElementType.esriETEdge); Dictionary<IFeature, int> junctionsInPath = GetFeaturesFromNetEID(_geomNet, (IEnumNetEIDBuilder) netJuncEIDS); Dictionary<IFeature, int> edgesInPath = GetFeaturesFromNetEID(_geomNet, (IEnumNetEIDBuilder)netEdgeEIDS); //GetFeaturesFromNetEID(_geomNet, (IEnumNetEIDBuilder)netJuncEIDS); //GetFeaturesFromNetEID(_geomNet, (IEnumNetEIDBuilder)netEdgeEIDS); AddToListView(junctionsInPath); }
/// <summary> /// 求解最短路径 /// </summary> /// <param name="_pMap"></param> /// <param name="_pGeometricNetwork"></param> /// <param name="_pWeightName"></param> /// <param name="_pPoints"></param> /// <param name="_pDist"></param> /// <param name="_pPolyline"></param> /// <param name="_pPathCost"></param> public void SolvePath(IMap _pMap, IGeometricNetwork _pGeometricNetwork, string _pWeightName, IPointCollection _pPoints, double _pDist, ref IPolyline _pPolyline, ref double _pPathCost) { try { // 这4个参数其实就是一个定位Element的指标 int intEdgeUserClassID; int intEdgeUserID; int intEdgeUserSubID; int intEdgeID; IPoint pFoundEdgePoint; double dblEdgePercent; ITraceFlowSolverGEN pTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; INetSolver pNetSolver = pTraceFlowSolver as INetSolver; //操作是针对逻辑网络的,INetwork是逻辑网络 INetwork pNetwork = _pGeometricNetwork.Network; pNetSolver.SourceNetwork = pNetwork; INetElements pNetElements = pNetwork as INetElements; int pCount = _pPoints.PointCount; //定义一个边线旗数组 IEdgeFlag[] pEdgeFlagList = new EdgeFlagClass[pCount]; IPointToEID pPointToEID = new PointToEIDClass(); pPointToEID.SourceMap = _pMap; pPointToEID.GeometricNetwork = _pGeometricNetwork; pPointToEID.SnapTolerance = _pDist; for (int i = 0; i < pCount; i++) { INetFlag pNetFlag = new EdgeFlagClass() as INetFlag; IPoint pEdgePoint = _pPoints.get_Point(i); //查找输入点的最近的边线 pPointToEID.GetNearestEdge(pEdgePoint, out intEdgeID, out pFoundEdgePoint, out dblEdgePercent); pNetElements.QueryIDs(intEdgeID, esriElementType.esriETEdge, out intEdgeUserClassID, out intEdgeUserID, out intEdgeUserSubID); pNetFlag.UserClassID = intEdgeUserClassID; pNetFlag.UserID = intEdgeUserID; pNetFlag.UserSubID = intEdgeUserSubID; IEdgeFlag pTemp = (IEdgeFlag)(pNetFlag as IEdgeFlag); pEdgeFlagList[i] = pTemp; } pTraceFlowSolver.PutEdgeOrigins(ref pEdgeFlagList); INetSchema pNetSchema = pNetwork as INetSchema; INetWeight pNetWeight = pNetSchema.get_WeightByName(_pWeightName); INetSolverWeightsGEN pNetSolverWeights = pTraceFlowSolver as INetSolverWeightsGEN; pNetSolverWeights.FromToEdgeWeight = pNetWeight;//开始边线的权重 pNetSolverWeights.ToFromEdgeWeight = pNetWeight;//终止边线的权重 object[] pRes = new object[pCount - 1]; //通过FindPath得到边线和交汇点的集合 IEnumNetEID pEnumNetEID_Junctions; IEnumNetEID pEnumNetEID_Edges; pTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out pEnumNetEID_Junctions, out pEnumNetEID_Edges, pCount - 1, ref pRes); //计算元素成本 _pPathCost = 0; for (int i = 0; i < pRes.Length; i++) { double m_Va = (double)pRes[i]; _pPathCost = _pPathCost + m_Va; } IGeometryCollection pNewGeometryColl = _pPolyline as IGeometryCollection;//QI ISpatialReference pSpatialReference = _pMap.SpatialReference; IEIDHelper pEIDHelper = new EIDHelperClass(); pEIDHelper.GeometricNetwork = _pGeometricNetwork; pEIDHelper.OutputSpatialReference = pSpatialReference; pEIDHelper.ReturnGeometries = true; IEnumEIDInfo pEnumEIDInfo = pEIDHelper.CreateEnumEIDInfo(pEnumNetEID_Edges); int Count = pEnumEIDInfo.Count; pEnumEIDInfo.Reset(); for (int i = 0; i < Count; i++) { IEIDInfo pEIDInfo = pEnumEIDInfo.Next(); IGeometry pGeometry = pEIDInfo.Geometry; pNewGeometryColl.AddGeometryCollection(pGeometry as IGeometryCollection); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// /// </summary> /// <param name="circBreaker"></param> private void TraceFeeder(INetworkFeature circBreaker) { #region Initialize some variables listView1.Items.Clear(); Int32 phaseABit = (int) Math.Pow(2, 28); // 268435456 Int32 phaseBBit = (int) Math.Pow(2, 29); // 536870912 Int32 phaseCBit = (int) Math.Pow(2, 30); // 1073741824 #endregion #region Create a queue of junctions to visit and a hash table for path information Queue<int> junctionsToVisit = new Queue<int>(); Dictionary<int, int> pathHash = new Dictionary<int, int>(); int startEID = ((ISimpleJunctionFeature) circBreaker).EID; junctionsToVisit.Enqueue(startEID); pathHash.Add(startEID, -99999999); #endregion #region Get the MMElectricTraceWeight and create a ForwardStar so that we can stop the trace when we reach an open point _network = circBreaker.GeometricNetwork.Network; _geomNet = circBreaker.GeometricNetwork; INetSchema netSchema = (INetSchema) _network; INetWeight mmElectricTraceWeight = netSchema.get_WeightByName("MMElectricTraceWeight"); IForwardStarGEN fStar = (IForwardStarGEN) _network.CreateForwardStar(false, mmElectricTraceWeight, null, null, null); #endregion while (junctionsToVisit.Count > 0) { #region Orient the Forward Star at the current junction EID int eid = junctionsToVisit.Dequeue(); int adjEdgeCount = 0; fStar.FindAdjacent(0, eid, out adjEdgeCount); #endregion #region Declare and initialize arrays to hold edges and junctions, weights, and orientations int[] adjJuncEIDS = new int[adjEdgeCount]; object[] adjJuncWeights = new object[adjEdgeCount]; int[] adjEdgeEIDS = new int[adjEdgeCount]; object[] adjEdgeWeights = new object[adjEdgeCount]; // We don't use this, but we still have to declare the array bool[] adjRevOrientations = new bool[adjEdgeCount]; // We don't use this, but we still have to declare the array #endregion #region Query the adjacent junctions and edges (while we are at it, get the weights too) fStar.QueryAdjacentJunctions(ref adjJuncEIDS, ref adjJuncWeights); fStar.QueryAdjacentEdges(ref adjEdgeEIDS, ref adjRevOrientations, ref adjEdgeWeights); #endregion #region Loop through all of the connected edges for (int i = 0; i < adjEdgeCount; i++) { #region Get the connected edge and junction int connectedEdgeEID = -1*adjEdgeEIDS[i]; int oppositeJuncEID = adjJuncEIDS[i]; #endregion #region Check to see if the adjacent junctions has already been added to the paths hashtable if (pathHash.ContainsKey(oppositeJuncEID) == false) { #region Add the opposite junction and the connected edge to the paths hashtable pathHash.Add(oppositeJuncEID, connectedEdgeEID); pathHash.Add(connectedEdgeEID, eid); #endregion #region If the opposite junction is closed on at least one phase (A or B or C), then enque the opposite junction Int32 juncWeight = System.Convert.ToInt32(adjJuncWeights[i]); if ((juncWeight & phaseABit) == 0 || (juncWeight & phaseBBit) == 0 || (juncWeight & phaseCBit) == 0 || (juncWeight == 0)) { junctionsToVisit.Enqueue(oppositeJuncEID); } #endregion } #endregion } #endregion } _pathHash = pathHash; PopulateListView(pathHash, _network, _geomNet); }
public IEnumFeatureClass GetEnumFeatureClasses(IGeometricNetwork geometricNetwork, esriFeatureType featureType) { return(geometricNetwork.ClassesByType[featureType]); }
/// <summary> /// Returns the <see cref="IEIDInfo" /> for the specified network element. /// </summary> /// <param name="source">The source.</param> /// <param name="eid">The element ID.</param> /// <param name="elementType">Type of the element.</param> /// <returns> /// Returns the <see cref="IEIDInfo" /> interface for the network element. /// </returns> public static IEIDInfo GetEIDInfo(this IGeometricNetwork source, int eid, esriElementType elementType) { return(source.GetEIDInfo(eid, elementType, true, true)); }
private static void ProfileGetRelatedElevData(IApplication app, List<ProfileGraphDetails> ProfileGraph, IGeometricNetwork pGeometricNet, IEnumNetEID pResultEdges, IEnumNetEID pResultJunctions, int CurrentDetail, ref IFeatureLayer pFLManhole, ref IFeatureLayer pFLMain, ref IFeatureLayer pFLTap) { List<mainDetails> SewerColMains = null; List<manholeDetails> SewerColManholes = null; List<tapDetails> SewerColTap = null; IEIDHelper pEIDHelperEdges = null; IEnumEIDInfo pEnumEIDInfoEdges = null; IEIDHelper pEIDHelperJunctions = null; IEnumEIDInfo pEnumEIDInfoJunctions = null; IPolyline pPolyline = null; IPointCollection pPtColl = null; IEIDInfo pEIDInfo = null; IPoint pNewPt = null; ISegmentCollection pSegColl = null; IMSegmentation pMSegmentation = null; IMAware pMAware = null; IPointCollection pPtCollection = null; IEnumVertex pEnumVertex; IHitTest pHtTest = null; IPoint pHitPntOne = null; IPoint pHitPntTwo = null; IFeature pFeature = null; Hashtable pFeatureAdded = null; mainDetails mainDet = null; IEdgeFeature pEdge = null; IPoint pGeoOne = null; IPoint pGeoTwo = null; IField pFld = null; IJunctionFeature pJunc = null; tapDetails tapDet = null; manholeDetails manDet = null; IFeatureLayer pFl = null; ISpatialFilter pSpatFilt = null; IFeatureCursor pFC = null; try { SewerColMains = new List<mainDetails>(); SewerColManholes = new List<manholeDetails>(); SewerColTap = new List<tapDetails>(); pEIDHelperEdges = new EIDHelper(); pEIDHelperEdges.GeometricNetwork = pGeometricNet; pEIDHelperEdges.ReturnFeatures = true; pEIDHelperEdges.ReturnGeometries = true; pEIDHelperEdges.PartialComplexEdgeGeometry = true; pEnumEIDInfoEdges = pEIDHelperEdges.CreateEnumEIDInfo(pResultEdges); pEnumEIDInfoEdges.Reset(); //edges pEIDHelperJunctions = new EIDHelperClass(); pEIDHelperJunctions.GeometricNetwork = pGeometricNet; pEIDHelperJunctions.ReturnFeatures = true; pEIDHelperJunctions.ReturnGeometries = true; pEIDHelperJunctions.PartialComplexEdgeGeometry = true; pEnumEIDInfoJunctions = pEIDHelperJunctions.CreateEnumEIDInfo(pResultJunctions); pEnumEIDInfoJunctions.Reset();// junctions pPolyline = new PolylineClass(); pPolyline.SpatialReference = (pFLMain as IGeoDataset).SpatialReference; pPtColl = (IPointCollection)pPolyline; //QI for (int i = 0; i < pEnumEIDInfoJunctions.Count; i++) { pEIDInfo = pEnumEIDInfoJunctions.Next(); pNewPt = (IPoint)pEIDInfo.Geometry; pPtColl.AddPoint(pNewPt); } pSegColl = (ISegmentCollection)pPolyline; pPolyline.Densify(50, 0.01); pMAware = (IMAware)pPolyline;//'QI pMAware.MAware = true; pMSegmentation = (IMSegmentation)pPolyline; // get the M values, put the distance in m, 0 to Length pMSegmentation.SetMsAsDistance(false); pPtCollection = (IPointCollection)pPolyline; pEnumVertex = pPtCollection.EnumVertices; pEnumVertex.Reset(); pHtTest = pPolyline as IHitTest; pHitPntOne = new PointClass(); pHitPntTwo = new PointClass(); double pHitDistOne = -1; double pHitDistTwo = -1; int pHitPrtOne = -1; int pHitPrtTwo = -1; int pHitSegOne = -1; int pHitSegTwo = -1; bool pHitSideOne = false; bool pHitSideTwo = false; pFeatureAdded = new Hashtable(); pEnumEIDInfoEdges.Reset(); //edges int intUpStreamFld = pFLMain.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Line_UpStreamElevationField); int intDownStreamFld = pFLMain.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Line_DownStreamElevationField); if (intDownStreamFld < 0) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19c") + ProfileGraph[CurrentDetail].Line_DownStreamElevationField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19b")); } if (intUpStreamFld < 0) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19d") + ProfileGraph[CurrentDetail].Line_UpStreamElevationField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19b")); } for (int i = 0; i < pResultEdges.Count; i++) { pEIDInfo = pEnumEIDInfoEdges.Next(); pFeature = pEIDInfo.Feature; if (((IDataset)pFeature.Class).Name != ((IDataset)pFLMain.FeatureClass).Name) continue; if (pFeatureAdded.ContainsValue(pFeature.OID)) continue; mainDet = new mainDetails(); pEdge = (IEdgeFeature)pFeature; pGeoOne = (IPoint)pEdge.FromJunctionFeature.get_OriginalGeometryForJunctionElement(0); pGeoTwo = (IPoint)pEdge.ToJunctionFeature.get_OriginalGeometryForJunctionElement(0); pFeature = ((IFeatureClass)pFeature.Class).GetFeature(pFeature.OID); bool bHitOne = pHtTest.HitTest(pGeoOne, .1, esriGeometryHitPartType.esriGeometryPartVertex, pHitPntOne, ref pHitDistOne, ref pHitPrtOne, ref pHitSegOne, ref pHitSideOne); bool bHitTwo = pHtTest.HitTest(pGeoTwo, .1, esriGeometryHitPartType.esriGeometryPartVertex, pHitPntTwo, ref pHitDistTwo, ref pHitPrtTwo, ref pHitSegTwo, ref pHitSideTwo); if (bHitOne && bHitTwo) { if (pHitPntOne.M < pHitPntTwo.M) { mainDet.UpM = pHitPntOne.M; mainDet.DownM = pHitPntTwo.M; if (intUpStreamFld > 0) { if (pFeature.get_Value(intUpStreamFld).ToString() != "") { mainDet.UpElev = Convert.ToDouble(pFeature.get_Value(intUpStreamFld)); } else mainDet.UpElev = -9999; } else mainDet.UpElev = -9999; if (intDownStreamFld > 0) { if (pFeature.get_Value(intDownStreamFld).ToString() != "") { mainDet.DownElev = Convert.ToDouble(pFeature.get_Value(intDownStreamFld)); } else mainDet.DownElev = -9999; } else mainDet.DownElev = -9999; } else { mainDet.DownM = pHitPntOne.M; mainDet.UpM = pHitPntTwo.M; if (intUpStreamFld > 0) { if (pFeature.get_Value(intUpStreamFld) != null && pFeature.get_Value(intUpStreamFld).ToString() != "") { mainDet.DownElev = Convert.ToDouble(pFeature.get_Value(intUpStreamFld)); } else mainDet.DownElev = -9999; } else mainDet.DownElev = -9999; if (intDownStreamFld > 0) { if (pFeature.get_Value(intDownStreamFld) != null && pFeature.get_Value(intDownStreamFld).ToString() != "") { mainDet.UpElev = Convert.ToDouble(pFeature.get_Value(intDownStreamFld)); } else mainDet.UpElev = -9999; } else mainDet.UpElev = -9999; } string label = ""; for (int l = 0; l < ProfileGraph[CurrentDetail].Line_Labels.Length; l++) { if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_Labels[l]) > 0) { int fldIdx = pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_Labels[l]); pFld = pFeature.Fields.get_Field(fldIdx); if (pFeature.get_Value(fldIdx) != null) { if (label == "") { label = Globals.GetDomainDisplay(pFeature.get_Value(fldIdx), pFeature, pFld); } else { label = label + "\r\n" + Globals.GetDomainDisplay(pFeature.get_Value(fldIdx), pFeature, pFld); } } } } mainDet.Label = label; } if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_IDField) > 0) { if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_IDField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_IDField)).ToString() != "") { mainDet.MainID = Convert.ToString(pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Line_IDField))); } else mainDet.MainID = "Unk"; } else mainDet.MainID = "Unk"; pFeatureAdded.Add(pFeature.OID, pFeature.OID); SewerColMains.Add(mainDet); } pFeatureAdded = new Hashtable(); pEnumEIDInfoJunctions.Reset(); for (int i = 0; i < pEnumEIDInfoJunctions.Count; i++) { pEIDInfo = pEnumEIDInfoJunctions.Next(); pFeature = pEIDInfo.Feature; if (pFLTap != null) { if (((IDataset)pFeature.Class).Name == ((IDataset)pFLTap.FeatureClass).Name) { pJunc = (IJunctionFeature)pFeature; pFeature = ((IFeatureClass)pFeature.Class).GetFeature(pFeature.OID); pHitPntOne = new PointClass(); bool bHit = pHtTest.HitTest(pFeature.Shape as IPoint, .1, esriGeometryHitPartType.esriGeometryPartVertex, pHitPntOne, ref pHitDistOne, ref pHitPrtOne, ref pHitSegOne, ref pHitSideOne); if (bHit) { tapDet = new tapDetails(); tapDet.M = pHitPntOne.M; if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_IDField) > 0) { if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_IDField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_IDField)).ToString() != "") { tapDet.tapID = pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_IDField)).ToString(); } else tapDet.tapID = "Unk"; } else tapDet.tapID = "Unk"; string label = ""; for (int l = 0; l < ProfileGraph[CurrentDetail].PointAlong_Labels.Length; l++) { if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_Labels[l]) > 0) { int fldIdx = pFeature.Fields.FindField(ProfileGraph[CurrentDetail].PointAlong_Labels[l]); pFld = pFeature.Fields.get_Field(fldIdx); if (pFeature.get_Value(fldIdx) != null) { if (label == "") { label = Globals.GetDomainDisplay(pFeature.get_Value(fldIdx), pFeature, pFld); } else { label = label + "\r\n" + Globals.GetDomainDisplay(pFeature.get_Value(fldIdx), pFeature, pFld); } } } } tapDet.tapLabel = label; SewerColTap.Add(tapDet); } } } if (((IDataset)pFeature.Class).Name == ((IDataset)pFLManhole.FeatureClass).Name) { if (pFeatureAdded.ContainsValue(pFeature.OID)) continue; pJunc = (IJunctionFeature)pFeature; pFeature = ((IFeatureClass)pFeature.Class).GetFeature(pFeature.OID); pHitPntOne = new PointClass(); bool bHit = pHtTest.HitTest(pFeature.Shape as IPoint, .1, esriGeometryHitPartType.esriGeometryPartVertex, pHitPntOne, ref pHitDistOne, ref pHitPrtOne, ref pHitSegOne, ref pHitSideOne); if (bHit) { manDet = new manholeDetails(); manDet.M = pHitPntOne.M; if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_TopElevationField) > 0) { if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_TopElevationField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_TopElevationField)).ToString() != "") { manDet.Top = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_TopElevationField)); } else manDet.Top = -9999; } else manDet.Top = -9999; if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationField) > 0) { if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationField)).ToString() != "") { manDet.Bottom = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationField)); if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField) > 0) { if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField)).ToString() != "") { if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField)).ToString().ToUpper() == "INVERT") manDet.Bottom = manDet.Top - (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_BottomElevationTypeField)); } } } else manDet.Bottom = -9999; } else manDet.Bottom = -9999; //if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertElevationField) > 0) //{ // if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertElevationField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertElevationField)).ToString() != "") // { // manDet.InvertElev = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertElevationField)); // } // else // manDet.InvertElev = -9999; //} //else // manDet.InvertElev = -9999; //if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertField) > 0) //{ // if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertField)).ToString() != "") // { // manDet.Invert = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_InvertField)); // } // else // manDet.Invert = -9999; //} //else // manDet.Invert = -9999; //if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_RimElevationField) > 0) //{ // if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_RimElevationField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_RimElevationField)).ToString() != "") // { // manDet.Rim = (double)pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_RimElevationField)); // } // else // manDet.Rim = -9999; //} //else // manDet.Rim = -9999; if (pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_IDField) > 0) { if (pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_IDField)) != null && pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_IDField)).ToString() != "") { manDet.ManholeID = pFeature.get_Value(pFeature.Fields.FindField(ProfileGraph[CurrentDetail].Point_IDField)).ToString(); } else manDet.ManholeID = "UNK"; } else manDet.ManholeID = "UNK"; pFeatureAdded.Add(pFeature.OID, pFeature.OID); SewerColManholes.Add(manDet); } } } if (ProfileGraph[CurrentDetail].Lines_Along != null) { if (ProfileGraph[CurrentDetail].Lines_Along.Length > 0) { pSpatFilt = new SpatialFilterClass(); pSpatFilt.Geometry = pPolyline; pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; for (int i = 0; i < ProfileGraph[CurrentDetail].Lines_Along.Length; i++) { bool FCorLayerTemp = true; pFl = (IFeatureLayer)Globals.FindLayer(app, ProfileGraph[CurrentDetail].Lines_Along[i].Layer_Name, ref FCorLayerTemp); if (pFl != null) { intUpStreamFld = pFl.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Lines_Along[i].Line_UpStreamElevationField); intDownStreamFld = pFl.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Lines_Along[i].Line_DownStreamElevationField); int intIdFld = pFl.FeatureClass.Fields.FindField(ProfileGraph[CurrentDetail].Lines_Along[i].Line_IDField); if (intIdFld < 0) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19f") + ProfileGraph[CurrentDetail].Lines_Along[i].Line_IDField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19e") + ProfileGraph[CurrentDetail].Lines_Along[i].Layer_Name); } if (intDownStreamFld < 0) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19c") + ProfileGraph[CurrentDetail].Lines_Along[i].Line_DownStreamElevationField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19e") + ProfileGraph[CurrentDetail].Lines_Along[i].Layer_Name); } if (intUpStreamFld < 0) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19d") + ProfileGraph[CurrentDetail].Lines_Along[i].Line_UpStreamElevationField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19e") + ProfileGraph[CurrentDetail].Lines_Along[i].Layer_Name); } pSpatFilt.GeometryField = pFl.FeatureClass.ShapeFieldName; pFC = pFl.Search(pSpatFilt, true); } } } } ProfileCreateGraph(app, ProfileGraph, pPolyline, SewerColMains, SewerColManholes, SewerColTap, CurrentDetail); } catch (Exception Ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + "ProfileGetRelatedSewerElevData " + Ex.Message); } finally { SewerColMains = null; SewerColManholes = null; SewerColTap = null; pEIDHelperEdges = null; pEnumEIDInfoEdges = null; pEIDHelperJunctions = null; if (pEnumEIDInfoJunctions != null) Marshal.ReleaseComObject(pEnumEIDInfoJunctions); pEnumEIDInfoJunctions = null; pPolyline = null; pPtColl = null; pEIDInfo = null; pNewPt = null; pSegColl = null; pMSegmentation = null; pMAware = null; pPtCollection = null; pEnumVertex = null; pHtTest = null; pHitPntOne = null; pHitPntTwo = null; pFeature = null; pFeatureAdded = null; mainDet = null; pEdge = null; pGeoOne = null; pGeoTwo = null; pFld = null; pJunc = null; tapDet = null; manDet = null; pFl = null; pSpatFilt = null; if (pFC != null) Marshal.ReleaseComObject(pFC); pFC = null; } }
/// <summary> /// Get the workspace from map which has geometric network /// </summary> /// <param name="map"></param> /// <returns></returns> public static IWorkspace GetGeoNetworkWorkspaceFromMap(IMap map, out IGeometricNetwork firstGeoNetwork) { IWorkspace workspace = null; firstGeoNetwork = null; try { IDictionary<IWorkspace, int> workspaces = DisplayMap.GetWorkspacesFromMap(map); if (workspaces == null) return null; foreach (KeyValuePair<IWorkspace, int> ws in workspaces) { IList<IGeometricNetwork> geoNetworks = DisplayMap.GetGeometricNetworksFromWorkspace(ws.Key); if (geoNetworks != null && geoNetworks.Count > 0) { firstGeoNetwork = geoNetworks[0]; workspace = ws.Key; break; } } } catch (Exception ex) { //_logger.LogException(ex); } return workspace; }
public static void ProfileFindPath(AxMapControl ppAxMapControl, IArray pNetFlagArray, IGeometricNetwork pGeoNetwork) { try { IEnumNetEID m_ipEnumNetEID_Junctions, m_ipEnumNetEID_Edges;//����������������Junctions��Edges IJunctionFlag[] pArrayJFlag = new IJunctionFlag[2]; pArrayJFlag[0] = pNetFlagArray.get_Element(0) as IJunctionFlag; pArrayJFlag[1] = pNetFlagArray.get_Element(1) as IJunctionFlag; ITraceFlowSolverGEN ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN; //get the inetsolver interface INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver; ipNetSolver.SourceNetwork = pGeoNetwork.Network; ipTraceFlowSolver.PutJunctionOrigins(ref pArrayJFlag); ipTraceFlowSolver.TraceIndeterminateFlow = false; object[] totalCost = new object[1]; //ipTraceFlowSolver.FindSource(esriFlowMethod.esriFMUpstream,esriShortestPathObjFn.esriSPObjFnMinSum,out m_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges,1,ref totalCost); ipTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinMax, out m_ipEnumNetEID_Junctions, out m_ipEnumNetEID_Edges, 1, ref totalCost); //��������еĽ����Ԫ�� pNetFlagArray.RemoveAll(); //ma // SpatialHelperFunction.pathToPolyline(pGeoNetwork, ppAxMapControl.ActiveView, m_ipEnumNetEID_Edges); //ProfileGetRelatedSewerElevData(ppAxMapControl,pGeoNetwork,m_ipEnumNetEID_Edges, m_ipEnumNetEID_Junctions ); } catch (Exception eX) { MessageBox.Show(eX.Message); } }
//初始化几何网络和地图 private bool InitializeNetworkAndMap(IFeatureDataset FeatureDataset) { IFeatureClassContainer ipFeatureClassContainer; IFeatureClass ipFeatureClass; IGeoDataset ipGeoDataset; ILayer ipLayer; IFeatureLayer ipFeatureLayer; IEnvelope ipEnvelope, ipMaxEnvelope; double dblSearchTol; INetworkCollection ipNetworkCollection = FeatureDataset as INetworkCollection; int count = ipNetworkCollection.GeometricNetworkCount; //获取第一个几何网络工作空间 m_ipGeometricNetwork = ipNetworkCollection.get_GeometricNetwork(0); INetwork ipNetwork = m_ipGeometricNetwork.Network; if (m_ipMap != null) { //m_ipMap = new MapClass(); ipFeatureClassContainer = m_ipGeometricNetwork as IFeatureClassContainer; count = ipFeatureClassContainer.ClassCount; for (int i = 0; i < count; i++) { ipFeatureClass = ipFeatureClassContainer.get_Class(i); ipFeatureLayer = new FeatureLayerClass(); ipFeatureLayer.FeatureClass = ipFeatureClass; for (int j = 0; j < m_ipMap.LayerCount; j++) { if (m_ipMap.get_Layer(j).Name.ToUpper() == ipFeatureLayer.Name.ToUpper()) { continue; } } m_ipMap.AddLayer(ipFeatureLayer); } m_ipActiveView.Refresh(); } count = m_ipMap.LayerCount; ipMaxEnvelope = new EnvelopeClass(); for (int i = 0; i < count; i++) { ipLayer = m_ipMap.get_Layer(i); ipFeatureLayer = ipLayer as IFeatureLayer; ipGeoDataset = ipFeatureLayer as IGeoDataset; ipEnvelope = ipGeoDataset.Extent; ipMaxEnvelope.Union(ipEnvelope); } m_ipPointToEID = new PointToEIDClass(); m_ipPointToEID.SourceMap = m_ipMap; m_ipPointToEID.GeometricNetwork = m_ipGeometricNetwork; double dblWidth = ipMaxEnvelope.Width; double dblHeight = ipMaxEnvelope.Height; if (dblWidth > dblHeight) dblSearchTol = dblWidth / 100; else dblSearchTol = dblHeight / 100; m_ipPointToEID.SnapTolerance = dblSearchTol; return true; }
//////////////////////////////////�����������ǰ���ý����С�� public static void ProfileSetJunctionFlag(AxMapControl ppAxMapControl, ref IArray pNetFlagArray, IPoint pPoint, IGeometricNetwork pGeoNetwork) { try { //�����ͼ��ѡ�� ppAxMapControl.ActiveView.FocusMap.ClearSelection(); INetElements pNetElements = pGeoNetwork.Network as INetElements; IPointToEID pPtToEID = new PointToEIDClass(); int pJunctionID = 0; int iUserClassID; int iUserID; int iUserSubID; IPoint pLocation; pPtToEID.SourceMap = ppAxMapControl.ActiveView.FocusMap; pPtToEID.GeometricNetwork = pGeoNetwork; pPtToEID.SnapTolerance = ppAxMapControl.ActiveView.Extent.Envelope.Width / 100; pPtToEID.GetNearestJunction(pPoint, out pJunctionID, out pLocation); if (pJunctionID == 0) { MessageBox.Show("û�в������ٽ��ĵ�"); } else { pNetElements.QueryIDs(pJunctionID, esriElementType.esriETJunction, out iUserClassID, out iUserID, out iUserSubID); INetFlag ipNetFlag = new JunctionFlagClass(); ipNetFlag.UserClassID = iUserClassID; ipNetFlag.UserID = iUserID; ipNetFlag.UserSubID = iUserSubID; IMarkerSymbol pMarkerSym = new SimpleMarkerSymbolClass(); IRgbColor pRGBColor = new RgbColorClass(); pRGBColor.Red = 255; pRGBColor.Green = 0; pRGBColor.Blue = 0; pMarkerSym.Color = pRGBColor; pMarkerSym.Size = 20; //���Ƹõ� IScreenDisplay pScreenDisplay = ppAxMapControl.ActiveView.ScreenDisplay; pScreenDisplay.StartDrawing(pScreenDisplay.hDC, 0); pScreenDisplay.SetSymbol(pMarkerSym as ISymbol); pScreenDisplay.DrawPoint(pLocation); pScreenDisplay.FinishDrawing(); if (pLocation != null) { pNetFlagArray.Add(ipNetFlag); } if (pNetFlagArray.Count == 2) { //�����ٽ�� ProfileFindPath(ppAxMapControl, pNetFlagArray, pGeoNetwork); } } } catch (Exception eX) { MessageBox.Show(eX.Message); } }
public ZGeometricNetwork(IGeometricNetwork geometricNetwork) : base(geometricNetwork as IDataset) { // Initialize collections this.NetworkClasses = new ObservableCollection<ZNetworkClass>(); this.Weights = new ObservableCollection<ZNetWeight>(); this.EdgeRules = new ObservableCollection<ZRule>(); this.JunctionRules = new ObservableCollection<ZRule>(); // Report addition GeometricNetworkViewModel.Default.AddMessage(string.Format("Finding network classes..."), MessageType.Information); // Add network classes IEnumFeatureClass enumFeatureClass1 = geometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleJunction); IEnumFeatureClass enumFeatureClass2 = geometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleEdge); IEnumFeatureClass enumFeatureClass3 = geometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexEdge); foreach (IEnumFeatureClass enumFeatureClass in new IEnumFeatureClass[] { enumFeatureClass1, enumFeatureClass2, enumFeatureClass3 }) { IFeatureClass featureClass = enumFeatureClass.Next(); while (featureClass != null) { INetworkClass networkClass = featureClass as INetworkClass; if (networkClass != null) { // Create network class ZNetworkClass znc = new ZNetworkClass(networkClass); // Add class to collection this.NetworkClasses.Add(znc); // Report addition GeometricNetworkViewModel.Default.AddMessage(string.Format("Adding class: {0}", znc.Path.Table), MessageType.Information); } featureClass = enumFeatureClass.Next(); } } // Add weights and weight associations INetwork network = geometricNetwork.Network; INetSchema netSchema = (INetSchema)network; for (int i = 0; i < netSchema.WeightCount; i++) { // Create network weight INetWeight netWeight = netSchema.get_Weight(i); IEnumNetWeightAssociation enumNetWeightAssocation = netSchema.get_WeightAssociations(i); ZNetWeight znw = new ZNetWeight(this, netWeight, enumNetWeightAssocation); // Add weight to collection this.Weights.Add(znw); // Report addition GeometricNetworkViewModel.Default.AddMessage(string.Format("Adding weight: {0}", znw.Name), MessageType.Information); } // Add connectivity rules IEnumRule rules = geometricNetwork.Rules; IRule rule = rules.Next(); while (rule != null) { if (rule is IJunctionConnectivityRule) { // Create junction rule IJunctionConnectivityRule junctionConnectivityRule = (IJunctionConnectivityRule)rule; ZJunctionConnectivityRule jcr = new ZJunctionConnectivityRule(this, junctionConnectivityRule); // Add junction rule this.JunctionRules.Add(jcr); // Report GeometricNetworkViewModel.Default.AddMessage(string.Format("Adding junction rule: {0}", jcr.Id), MessageType.Information); } else if (rule is IEdgeConnectivityRule) { // Create edge rule IEdgeConnectivityRule edgeConnectivityRule = (IEdgeConnectivityRule)rule; ZEdgeConnectivityRule ecr = new ZEdgeConnectivityRule(this, edgeConnectivityRule); // Add edge rule this.EdgeRules.Add(ecr); // Report GeometricNetworkViewModel.Default.AddMessage(string.Format("Adding edge rule: {0}", ecr.Id), MessageType.Information); } rule = rules.Next(); } }
public static void UpStreamTrace(AxMapControl ppAxMapControl, IPoint pPoint, IGeometricNetwork pGeoNetwork) { try { //�����ͼ��ѡ�� ppAxMapControl.ActiveView.FocusMap.ClearSelection(); INetElements pNetElements = pGeoNetwork.Network as INetElements; IPointToEID pPtToEID = new PointToEIDClass(); int pJunctionID = 0; int iUserClassID; int iUserID; int iUserSubID; IPoint pLocation; pPtToEID.SourceMap = ppAxMapControl.ActiveView.FocusMap; pPtToEID.GeometricNetwork = pGeoNetwork; pPtToEID.SnapTolerance = ppAxMapControl.ActiveView.Extent.Envelope.Width / 100; pPtToEID.GetNearestJunction(pPoint, out pJunctionID, out pLocation); if (pJunctionID == 0) { MessageBox.Show("û�в������ٽ��ĵ�"); } else { pNetElements.QueryIDs(pJunctionID, esriElementType.esriETJunction, out iUserClassID, out iUserID, out iUserSubID); INetFlag ipNetFlag = new JunctionFlagClass(); ipNetFlag.UserClassID = iUserClassID; ipNetFlag.UserID = iUserID; ipNetFlag.UserSubID = iUserSubID; IMarkerSymbol pMarkerSym = new SimpleMarkerSymbolClass(); IRgbColor pRGBColor = new RgbColorClass(); pRGBColor.Red = 255; pRGBColor.Green = 0; pRGBColor.Blue = 0; pMarkerSym.Color = pRGBColor; pMarkerSym.Size = 20; //�����µ�Flag IEdgeFlagDisplay pEdgeFlagDisplay = new EdgeFlagDisplayClass(); IFlagDisplay pFlagDisplay = pEdgeFlagDisplay as IFlagDisplay; pFlagDisplay.Symbol = pMarkerSym as ISymbol; pFlagDisplay.Geometry = pLocation; pFlagDisplay.FeatureClassID = iUserClassID; pFlagDisplay.FID = iUserID; pFlagDisplay.SubID = iUserSubID; //���Ƹõ� IScreenDisplay pScreenDisplay = ppAxMapControl.ActiveView.ScreenDisplay; pScreenDisplay.StartDrawing(pScreenDisplay.hDC, 0); pScreenDisplay.SetSymbol(pMarkerSym as ISymbol); pScreenDisplay.DrawPoint(pLocation as IGeometry); pScreenDisplay.FinishDrawing(); //�����ٽ�� FindStreamTraceResult(ppAxMapControl, ipNetFlag, pGeoNetwork); } } catch (Exception eX) { MessageBox.Show(eX.Message); } }
public void setGNetwork(IGeometricNetwork _mNetwork) { m_ipGeometricNetwork=_mNetwork; }
private void CloseWorkspace() { m_ipGeometricNetwork = null; m_ipPoints = null; m_ipPointToEID = null; m_ipEnumNetEID_Junctions = null; m_ipEnumNetEID_Edges = null; m_ipPolyline = null; }
private bool ShutdownArcMap() { IApplication pApp; IDocument pDoc; IMxDocument pMXDoc; IDocumentDirty2 pDocDirty; Type t = Type.GetTypeFromProgID("esriFramework.AppRef"); System.Object obj = Activator.CreateInstance(t); pApp = obj as IApplication; pDoc = pApp.Document; pMXDoc = (IMxDocument)pDoc; pDocDirty = (IDocumentDirty2)pMXDoc; pDocDirty.SetClean(); Workspace = null; ScriptEngine.BroadcastProperty("Workspace", this.Workspace, this); ScriptEngine.BroadcastProperty("FeatureClass", null, this); _SDMGR = null; _PTMGR = null; pSelection = null; m_pGN = null; pSC = null; pEditor = null; pDoc = null; pMXDoc = null; pApp.Shutdown(); //Process iProc = Process.GetCurrentProcess(); //iProc.Kill(); Logger.WriteLine("Closing Arcmap"); return true; }
/// <summary> /// 将几何网络添加到地图上 /// </summary> /// <param name="_pMap"></param> /// <param name="_pGeometricNetwork"></param> void LoadGeometric(IMap _pMap,IGeometricNetwork _pGeometricNetwork) { IFeatureClassContainer pFtContainer = _pGeometricNetwork as IFeatureClassContainer; int pCount = pFtContainer.ClassCount; for (int i = 0; i < pCount; i++) { IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFtContainer.get_Class(i); _pMap.AddLayer(pFeatureLayer as ILayer); } }
private bool PlaceFlag(string sClassName, string sOID) { IFeatureClass pFC; IFeatureWorkspace pFWKS; IFeature pFeat; INetElements pNetElements; ISimpleJunctionFeature pJunc; INetworkAnalysisExt pNetworkAnalysisExt; IMxDocument pMXDoc; IApplication pApp; IMxApplication pMXApp; INetworkAnalysisExtFlags pNetworkAnalysisExtFlags; UID pUID; ITraceFlowSolverGEN pTraceFlowSolver; INetSolver pNetSolver; Miner.Interop.IMMTraceUIUtilities pTraceUtils; IPolycurve pPoly; int iCLSID; int iOID; int iSUBID; try { SW1.Reset(); SW1.Start(); Type t = Type.GetTypeFromProgID("esriFramework.AppRef"); System.Object obj = Activator.CreateInstance(t); pApp = obj as IApplication; pMXApp = (IMxApplication)pApp; pMXDoc = (IMxDocument)pApp.Document; pUID = new UID(); pUID.Value = "esriEditorExt.UtilityNetworkAnalysisExt"; pNetworkAnalysisExt = (INetworkAnalysisExt)pApp.FindExtensionByCLSID(pUID); pNetworkAnalysisExtFlags = (INetworkAnalysisExtFlags)pNetworkAnalysisExt; pNetElements = (INetElements)pNetworkAnalysisExt.CurrentNetwork.Network; pTraceUtils = new Miner.Interop.MMTraceUIUtilities(); pFWKS = (IFeatureWorkspace)Workspace; pFC = pFWKS.OpenFeatureClass(sClassName); if (pFC != null) { pFeat = pFC.GetFeature(Convert.ToInt32(sOID)); INetworkFeature pNetFeat = (INetworkFeature)pFeat; m_pGN = pNetFeat.GeometricNetwork; if (pFeat != null) { pTraceFlowSolver = (ITraceFlowSolverGEN)new TraceFlowSolver(); pNetSolver = (INetSolver)pTraceFlowSolver; if (pFeat.FeatureType == esriFeatureType.esriFTSimpleJunction) { pJunc = (ISimpleJunctionFeature)pFeat; pNetElements.QueryIDs(pJunc.EID, esriElementType.esriETEdge, out iCLSID, out iOID, out iSUBID); //pJFlag = (INetFlag)new JunctionFlag(); //pJFlag.UserClassID = iCLSID; //pJFlag.UserID = iOID; //pJFlag.UserSubID = iSUBID; IFlagDisplay pFlagDisplay = new JunctionFlagDisplay(); pFlagDisplay.Symbol = (ISymbol)CreateMarkerSymbol(0); pFlagDisplay.Geometry = (IPoint)pFeat.ShapeCopy; //Set pNetSolver.SourceNetwork = pNetElements pNetworkAnalysisExtFlags.AddJunctionFlag((IJunctionFlagDisplay)pFlagDisplay); } else { IPoint pPoint; pPoint = new Point(); double dDist; dDist = .5; pPoly = (IPolycurve)pFeat.ShapeCopy; pPoly.QueryPoint(esriSegmentExtension.esriNoExtension, dDist, true, pPoint); IFlagDisplay pFlagDisplay = new EdgeFlagDisplay(); IEdgeFeature pEdge = (IEdgeFeature)pFeat; IObjectClass pOC = (IObjectClass)pFeat.Table; int iEID = pNetElements.GetEID(pOC.ObjectClassID, pFeat.OID, 0, esriElementType.esriETEdge); //pNetElements.QueryIDs(pEdge.ToJunctionEID, esriElementType.esriETEdge, out iCLSID, out iOID, out iSUBID); pFlagDisplay.FeatureClassID = pOC.ObjectClassID; pFlagDisplay.FID = pFeat.OID; pFlagDisplay.SubID = 0; //pFlagDisplay.Geometry = pPoint; pFlagDisplay.Symbol = (ISymbol)CreateMarkerSymbol(0); ISimpleMarkerSymbol pSMS = (ISimpleMarkerSymbol)pFlagDisplay.Symbol; IColor pColor; pColor = new RgbColor(); pColor.RGB = 100; pSMS.Size = 10; pNetworkAnalysisExtFlags.AddEdgeFlag((IEdgeFlagDisplay)pFlagDisplay); } } } SW1.Stop(); RecordActionTime("PLACEFLAG" , SW1.ElapsedMilliseconds); return true; } catch (Exception EX) { Logger.WriteLine("Error in PlaceFlags " + EX.Message + " " + EX.StackTrace); return false; } }
//上朔追踪查找管线涉及的地块 public static void UpStreamFindParcels(MainFrm pMainFrm, IEnumNetEID pEnumResultEdges, IGeometricNetwork pGeoNetwork) { try { AxMapControl axMap = pMainFrm.getMapControl(); IFeatureLayer pFeatLayerSewerLines = FindFeatLayer("Sewer Lines", pMainFrm); IFeatureLayer pFeatLayerParcels = FindFeatLayer("Parcels", pMainFrm); //从所选择的Sewer线特征中创建几何包 IGeometryCollection pGeomBag = new GeometryBagClass(); object missing = Type.Missing; int lEID; int iUserClassID; int iUserID; int iUserSubID; INetElements pNetElements = pGeoNetwork.Network as INetElements; pEnumResultEdges.Reset(); IFeature pFeature; for (int j = 0; j <= pEnumResultEdges.Count - 1; j++) { lEID = pEnumResultEdges.Next(); pNetElements.QueryIDs(lEID, esriElementType.esriETEdge, out iUserClassID, out iUserID, out iUserSubID); pFeature = pFeatLayerSewerLines.FeatureClass.GetFeature(iUserID); pGeomBag.AddGeometry(pFeature.Shape, ref missing, ref missing); // MessageBox.Show(iUserClassID.ToString()+","+iUserID.ToString()+","+iUserSubID.ToString()); } //进行空间拓扑叠加操作以用于查找地块信息 ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.Geometry = pGeomBag as IGeometry ; pSpatialFilter.GeometryField = "Shape"; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.SearchOrder = esriSearchOrder.esriSearchOrderSpatial; //获得交叉到的地块信息 IFeatureCursor pFeatCursor=pFeatLayerParcels.FeatureClass.Search(pSpatialFilter, false); //增加被选择的地块数据到地图的图形图层数据中 ICompositeGraphicsLayer pComGraphicLayer = new CompositeGraphicsLayerClass(); ILayer pLayer = pComGraphicLayer as ILayer ; pLayer.Name = "受影响的地块"; IGraphicsContainer pGraphicContainer = pComGraphicLayer as IGraphicsContainer; //增加所选择的地块到图形容器中 ISimpleFillSymbol pSymFill=new SimpleFillSymbolClass(); IFillSymbol pFillSymbol=pSymFill as IFillSymbol; IRgbColor pRgbColor=new RgbColorClass(); pRgbColor.Red=0; pRgbColor.Green=200; pRgbColor.Blue=100; pFillSymbol.Color=pRgbColor as IColor; ICartographicLineSymbol pCartoLine=new CartographicLineSymbolClass(); IRgbColor pRgbColor2=new RgbColorClass(); pRgbColor2.Red=100; pRgbColor2.Green=200; pRgbColor2.Blue=100; pCartoLine.Width=2; pCartoLine.Color =pRgbColor2 as IColor; pFillSymbol.Outline=pCartoLine; //创建存放所有地块特征的数组 IArray pFeatArray = new ArrayClass(); pFeature=pFeatCursor.NextFeature(); while (pFeature != null) { IElement pPolyElement = new PolygonElementClass(); IFillShapeElement pFillShapeElement = pPolyElement as IFillShapeElement; pPolyElement.Geometry = pFeature.Shape; pFillShapeElement.Symbol = pFillSymbol; pGraphicContainer.AddElement(pPolyElement, 0); pFeatArray.Add(pFeature); pFeature = pFeatCursor.NextFeature(); } axMap.AddLayer(pGraphicContainer as ILayer); axMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null); frmUpstreamCreateOwnerList frmUpstreamCreateOwnerList1 = new frmUpstreamCreateOwnerList(pMainFrm,pFeatLayerParcels, pFeatArray); frmUpstreamCreateOwnerList1.Show(); } catch (Exception eX) { MessageBox.Show(eX.Message); } }
private static Dictionary<IFeature, int> GetFeaturesFromNetEID(IGeometricNetwork geomNet, IEnumNetEIDBuilder enumEIDBuilder) { string fileName = "eidGeomLines.txt"; if (((IEnumNetEID)enumEIDBuilder).ElementType == esriElementType.esriETJunction) { fileName = "eidGeomPoints.txt"; } Dictionary<IFeature, int> featuresInPath = new Dictionary<IFeature, int>(); using (System.IO.StreamWriter sw = System.IO.File.CreateText("C:\\temp\\" + fileName)) { sw.Write("["); IEIDHelper eidHelper = new EIDHelperClass(); //eidHelper.AddField("OBJECTID"); //eidHelper.AddField("SHAPE"); eidHelper.ReturnGeometries = true; int multiplier = 1; if (((IEnumNetEID)enumEIDBuilder).ElementType == esriElementType.esriETEdge) { multiplier = -1; } eidHelper.ReturnFeatures = true; eidHelper.GeometricNetwork = geomNet; IEnumEIDInfo enumEIDInfo = eidHelper.CreateEnumEIDInfo(enumEIDBuilder as IEnumNetEID); enumEIDInfo.Reset(); for (int i = 0; i < enumEIDInfo.Count; i++) { IEIDInfo eidInfo = enumEIDInfo.Next(); try { IFeature fe = eidInfo.Feature; int eid = eidInfo.EID; featuresInPath.Add(fe, eidInfo.EID); sw.Write("["); sw.Write(eid * multiplier); sw.Write(","); sw.Write("["); if (fe.Shape.GeometryType == esriGeometryType.esriGeometryPolyline) { #region Loop through the point collection of the polyline and write out to the file IPointCollection pc = fe.Shape as IPointCollection; for (int j = 0; j < pc.PointCount; j++) { sw.Write("["); sw.Write(pc.get_Point(j).X + "," + pc.get_Point(j).Y); sw.Write("]"); if (j + 1 < pc.PointCount) { sw.Write("],"); } } #endregion } else if (fe.Shape.GeometryType == esriGeometryType.esriGeometryPoint) { IPoint pnt = fe.Shape as IPoint; sw.Write(pnt.X.ToString() + "," + pnt.Y.ToString()); sw.Write("]"); } if (i + 1 < enumEIDInfo.Count) { sw.Write(",");//more geometries coming! } } catch { } } sw.Write("]"); // This closes off all the geoemtries sw.Close(); } return featuresInPath; }