protected override void OnUpdate() { // by default, disable the command Enabled = false; // if there is not a current edit session, then disable the command if (m_editorExt.EditState != esriEditState.esriStateEditing) { return; } // otherwise, check to see if the flow direction is properly set for each edge EID IUtilityNetwork utilNet = GetCurrentNetwork() as IUtilityNetwork; IEnumNetEID edgeEIDs = GetCurrentEIDs(esriElementType.esriETEdge); edgeEIDs.Reset(); for (int i = 0; i < edgeEIDs.Count; i++) { int edgeEID = edgeEIDs.Next(); esriFlowDirection flowDir = utilNet.GetFlowDirection(edgeEID); if (flowDir != esriFlowDirection.esriFDWithFlow) { // enable the command if the flow direction is not with the digitized direction Enabled = true; // we can return right now, since only one edge needs to have // incorrect flow direction in order to enable the command return; } } }
public void ShowFlow(IActiveView ipAV) { if (this.m_pPointcol != null) { double num = 4.0 * Math.Atan(1.0); IScreenDisplay screenDisplay = ipAV.ScreenDisplay; screenDisplay.StartDrawing(0, 0); IMarkerSymbol determinateFolwArrow = NetworkAnalyst.m_pFlowSymbol.DeterminateFolwArrow as IMarkerSymbol; for (int i = 0; i < this.m_pPointcol.PointCount; i++) { esriFlowDirection direction = (esriFlowDirection)this.m_eFlowDirection[i]; if (direction == esriFlowDirection.esriFDWithFlow) { determinateFolwArrow.Angle = (180.0 * ((double)this.m_angle[i])) / num; screenDisplay.SetSymbol(determinateFolwArrow as ISymbol); } else if (direction == esriFlowDirection.esriFDAgainstFlow) { determinateFolwArrow.Angle = ((180.0 * ((double)this.m_angle[i])) / num) + 180.0; screenDisplay.SetSymbol(determinateFolwArrow as ISymbol); } else if (direction == esriFlowDirection.esriFDIndeterminate) { screenDisplay.SetSymbol(NetworkAnalyst.m_pFlowSymbol.IndeterminateFolwArrow); } else { screenDisplay.SetSymbol(NetworkAnalyst.m_pFlowSymbol.UninitializedFolwArrow); } IPoint point = this.m_pPointcol.get_Point(i); screenDisplay.DrawPoint(point); } screenDisplay.FinishDrawing(); } }
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 DrawFlowDirection(IFeature feature, IMapControlDefault mapc, esriFlowDirection flowdir) { //获取线段中点 IPolyline polyline = feature.Shape as IPolyline; IPoint midpoint = new PointClass(); polyline.QueryPoint(esriSegmentExtension.esriNoExtension, polyline.Length / 2, false, midpoint); //绘制特征符号 IArrowMarkerSymbol arrowSymbol = new ArrowMarkerSymbolClass(); ISimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbolClass(); IElement element = null; //绘制沿顺着数字化流向 if (flowdir == esriFlowDirection.esriFDWithFlow) { arrowSymbol.Size = 12; arrowSymbol.Color = ExportMap.Getcolor(0, 0, 0); arrowSymbol.Angle = GetlineAngle(polyline.FromPoint, polyline.ToPoint); //绘制 element = new MarkerElementClass(); element.Geometry = midpoint; ((IMarkerElement)element).Symbol = arrowSymbol; //设置绘制元素名称 ((IElementProperties)element).Name = "Flow"; } //方向顺着逆数字化的 if (flowdir == esriFlowDirection.esriFDAgainstFlow) { arrowSymbol.Size = 12; arrowSymbol.Color = ExportMap.Getcolor(0, 0, 0); arrowSymbol.Angle = GetlineAngle(polyline.FromPoint, polyline.ToPoint); //绘制 element = new MarkerElementClass(); element.Geometry = midpoint; ((IMarkerElement)element).Symbol = arrowSymbol; //设置绘制元素名称 ((IElementProperties)element).Name = "Flow"; } //方向未初始化的 if (flowdir == esriFlowDirection.esriFDUninitialized) { markerSymbol.Color = ExportMap.Getcolor(0, 0, 0); markerSymbol.Size = 8; element = new MarkerElementClass(); element.Geometry = midpoint; ((IMarkerElement)element).Symbol = markerSymbol; //设置绘制元素名称 ((IElementProperties)element).Name = "Flow"; } //方向未定义的 if (flowdir == esriFlowDirection.esriFDIndeterminate) { markerSymbol.Color = ExportMap.Getcolor(0, 0, 0); markerSymbol.Size = 8; element = new MarkerElementClass(); element.Geometry = midpoint; ((IMarkerElement)element).Symbol = markerSymbol; //设置绘制元素名称 ((IElementProperties)element).Name = "Flow"; } mapc.ActiveView.GraphicsContainer.AddElement(element, 0); }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { DF2DApplication app = DF2DApplication.Application; IGraphicsContainer gc = app.Current2DMapControl.Map as IGraphicsContainer; gc.DeleteAllElements(); bool ready = true; if (app == null || app.Current2DMapControl == null) { return; } m_ActiveView = app.Current2DMapControl.ActiveView; IScreenDisplay m_Display = app.Current2DMapControl.ActiveView.ScreenDisplay; try { if (button == 1) { ISimpleLineSymbol pLineSym = new SimpleLineSymbol(); IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 255; pColor.Blue = 0; pLineSym.Color = pColor; pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; ISimpleFillSymbol pFillSym = new SimpleFillSymbol(); pFillSym.Color = pColor; pFillSym.Style = esriSimpleFillStyle.esriSFSDiagonalCross; pFillSym.Outline = pLineSym; object symbol = pFillSym as object; IRubberBand band = new RubberRectangularPolygonClass(); IGeometry geo = band.TrackNew(m_Display, null); app.Current2DMapControl.DrawShape(geo, ref symbol); WaitForm.Start("正在查询...", "请稍后"); if (geo.IsEmpty) { IPoint searchPoint = new PointClass(); searchPoint.PutCoords(mapX, mapY); geo = PublicFunction.DoBuffer(searchPoint, PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate)); //m_ActiveView.FocusMap.SelectByShape(geo, s, false); } if (ready) { foreach (MajorClass mc in LogicDataStructureManage2D.Instance.GetAllMajorClass()) { if (mc.Alias == "电力" || mc.Alias == "通信" || mc.Alias == "架空") { continue; } string[] arrFc2DId = mc.Fc2D.Split(';'); if (arrFc2DId == null) { continue; } foreach (SubClass sc in mc.SubClasses) { if (!sc.Visible2D) { continue; } foreach (string fc2DId in arrFc2DId) { DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); if (dffc == null) { continue; } FacilityClass facc = dffc.GetFacilityClass(); IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null || facc == null || facc.Name != "PipeLine") { continue; } DFDataConfig.Class.FieldInfo fiDirection = facc.GetFieldInfoBySystemName("FlowDirection"); if (fiDirection == null) { continue; } IFields pFields = fc.Fields; //string[] name = new string[pFields.FieldCount]; //for (int i = 0; i < pFields.FieldCount; i++) //{ // name[i] = pFields.get_Field(i).Name; //} int indexDirection = pFields.FindField(fiDirection.Name); if (indexDirection < 0) { continue; } IField pField = pFields.get_Field(indexDirection); ISpatialFilter filter = new SpatialFilter(); filter.Geometry = geo; filter.SubFields = pField.Name; filter.WhereClause = mc.ClassifyField + " = '" + sc.Name + "'"; filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; if (fc == null || geo == null) { return; } IFeatureCursor pFeatureCursor = null; IFeature pFeature = null; try { pFeatureCursor = fc.Search(filter, false); esriFlowDirection flowDirection = new esriFlowDirection(); while ((pFeature = pFeatureCursor.NextFeature()) != null) { object tempobj = pFeature.get_Value(indexDirection); int dtemp; if (tempobj != null && Int32.TryParse(tempobj.ToString(), out dtemp)) { switch (dtemp) { case 0: flowDirection = esriFlowDirection.esriFDWithFlow; break; case 1: flowDirection = esriFlowDirection.esriFDAgainstFlow; break; } } else { flowDirection = esriFlowDirection.esriFDIndeterminate; } IPolyline polyline = pFeature.Shape as IPolyline; IPoint middlePoint = new PointClass(); polyline.QueryPoint(esriSegmentExtension.esriNoExtension, polyline.Length / 2, false, middlePoint); IArrowMarkerSymbol arrowMarkerSymbol = new ArrowMarkerSymbolClass(); ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass(); IElement element = null; if (flowDirection == esriFlowDirection.esriFDWithFlow) { arrowMarkerSymbol.Angle = GetLineAngleFrom2Points(polyline.FromPoint, polyline.ToPoint); arrowMarkerSymbol.Color = GetColorByRGBValue(0, 0, 0); arrowMarkerSymbol.Size = 12; element = new MarkerElementClass(); element.Geometry = middlePoint; ((IMarkerElement)element).Symbol = arrowMarkerSymbol; ((IElementProperties)element).Name = "Flow"; } else if (flowDirection == esriFlowDirection.esriFDAgainstFlow) { simpleMarkerSymbol.Angle = GetLineAngleFrom2Points(polyline.ToPoint, polyline.FromPoint); arrowMarkerSymbol.Color = GetColorByRGBValue(0, 0, 0); arrowMarkerSymbol.Size = 12; element = new MarkerElementClass(); element.Geometry = middlePoint; ((IMarkerElement)element).Symbol = arrowMarkerSymbol; ((IElementProperties)element).Name = "Flow"; } else if (flowDirection == esriFlowDirection.esriFDIndeterminate) { simpleMarkerSymbol.Color = GetColorByRGBValue(0, 0, 0); simpleMarkerSymbol.Size = 8; element = new MarkerElementClass(); element.Geometry = middlePoint; ((IMarkerElement)element).Symbol = simpleMarkerSymbol; ((IElementProperties)element).Name = "Flow"; } else { simpleMarkerSymbol.Color = GetColorByRGBValue(255, 0, 0); simpleMarkerSymbol.Size = 8; element = new MarkerElementClass(); element.Geometry = middlePoint; ((IMarkerElement)element).Symbol = simpleMarkerSymbol; ((IElementProperties)element).Name = "Flow"; } gc.AddElement(element, 0); } } catch (System.Exception ex) { } } } } WaitForm.Stop(); app.Current2DMapControl.ActiveView.Refresh(); } } } catch (System.Exception ex) { } }