Example #1
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (Button != 1)
            {
                return;
            }
            IPoint inPoint = new PointClass();

            inPoint = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
            IMap map = this.m_hookHelper.FocusMap;
            //获取最邻近的要素ID
            IPointToEID pointToEID = new PointToEIDClass();

            pointToEID.GeometricNetwork = geometricNetwork;
            pointToEID.SourceMap        = map;
            pointToEID.SnapTolerance    = 10;
            int    nearstJunctionEID = -1;
            IPoint outPoint          = new PointClass();

            pointToEID.GetNearestJunction(inPoint, out nearstJunctionEID, out outPoint);
            if (outPoint == null || outPoint.IsEmpty)
            {
                return;
            }
            junctionBarrierEIDs.Add(nearstJunctionEID);
            //绘制要素
            DrawElement(outPoint);
        }
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            base.OnMouseDown(Button, Shift, X, Y);
            if (Button != 1)
            {
                return;
            }
            //获取坐标点
            IPoint inPoint = new PointClass();

            inPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

            IMap map = m_hookHelper.FocusMap;

            //查询与坐标点最近的管点
            IPointToEID pointToEID = new PointToEIDClass();

            //
            if (geomretyNetwork == null)
            {
                return;
            }
            pointToEID.GeometricNetwork = geomretyNetwork;
            pointToEID.SourceMap        = map;
            pointToEID.SnapTolerance    = 10;
            IPoint outPoint           = new PointClass();
            int    nearestJunctionEID = -1;

            pointToEID.GetNearestJunction(inPoint, out nearestJunctionEID, out outPoint);
            if (outPoint == null || outPoint.IsEmpty)
            {
                return;
            }
            //获取管点标识并加入列表
            INetElements netElemnts = geomretyNetwork.Network  as INetElements;

            int UserClassID = 0;
            int UserID      = 0;
            int UserSubID   = 0;

            netElemnts.QueryIDs(nearestJunctionEID, esriElementType.esriETJunction, out UserClassID, out UserID, out UserSubID);

            //设置并添加管点标识
            INetFlag netFlag = new JunctionFlagClass() as INetFlag;

            netFlag.UserClassID = UserClassID;
            netFlag.UserID      = UserID;
            netFlag.UserSubID   = UserSubID;
            //
            listJunctionFlags.Add(netFlag as IJunctionFlag);
            //绘制点要素
            DrawElement(outPoint);
        }
        /// <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);
        }
Example #4
0
        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);

            }
        }
Example #5
0
        //////////////////////////////////�����������ǰ���ý����С��
        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 static void CalculateFlowAccumAtLocation(List<FlowLayerDetails> sumFlowAcc, IApplication app, double snapTol)
        {
            IMap pMap = null;

            IFeatureLayer pFLayer = null;

            IFeatureCursor pFCursor = null;
            IFeature pFeature = null;

            IPointToEID pPointToEid = null;

            string retAcc = "";
            int lSumFieldLoc;

            int lEID;
            IPoint pSnappedPoint = null;
            INetElements pNetElements = null;
            try
            {
                if (app == null)
                    return;
                pMap = ((app.Document as IMxDocument).FocusMap);
                if (pMap == null)
                    return;
                if (sumFlowAcc == null)
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20c"));
                if (sumFlowAcc.Count == 0)
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20c"));
                bool flowCalced = false;
                foreach (FlowLayerDetails sumAcc in sumFlowAcc)
                {
                    if (flowCalced == true)
                        break;

                    bool boolFoundAsLayer = true;

                    pFLayer = Globals.FindLayer(app, sumAcc.LayerName, ref boolFoundAsLayer) as IFeatureLayer;
                    if (pFLayer == null)
                    {
                        //MessageBox.Show(sumAcc.LayerName + " feature layer not found.\nAny selected features in this layer will be analyzed for acculmuation.");
                        continue;
                    }

                    if (pFLayer.FeatureClass == null)
                    {
                        MessageBox.Show(sumAcc.LayerName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20a"));
                        continue;
                    }

                    lSumFieldLoc = pFLayer.FeatureClass.Fields.FindField(sumAcc.SumFlowField);
                    if (lSumFieldLoc == -1)
                    {
                        MessageBox.Show(sumAcc.LayerName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20b") + sumAcc.SumFlowField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20e"));
                        return;
                    }

                    lEID = -1;
                    //Convert pixcel search distance to real world (map units)
                    //dRWSearchTolerance = c_iSearchTolerance;

                    //Find the closest network junction element to the user specified point

                    pPointToEid = new PointToEIDClass();
                    pPointToEid.GeometricNetwork = ((INetworkClass)pFLayer.FeatureClass).GeometricNetwork;
                    pPointToEid.SourceMap = pMap;
                    pPointToEid.SnapTolerance = snapTol;
                    bool bTest = false;
                    if (pFLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline || pFLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryLine)
                    {
                        double dblPercAlong = 0;

                        pPointToEid.GetNearestEdge((app.Document as IMxDocument).CurrentLocation, out lEID, out pSnappedPoint, out dblPercAlong);

                        if (pSnappedPoint == null)
                            continue;
                        if (lEID == 0)
                            continue;
                        //Get the complete id for the network element
                        pNetElements = (((INetworkClass)pFLayer.FeatureClass).GeometricNetwork.Network) as INetElements;

                        bTest = pNetElements.IsValidElement(lEID, esriElementType.esriETEdge);
                        pFeature = Globals.GetFeatureByEID(lEID, ((INetworkClass)pFLayer.FeatureClass).GeometricNetwork, pMap, esriElementType.esriETEdge);
                    }
                    else if (pFLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
                    {
                        pPointToEid.GetNearestJunction((app.Document as IMxDocument).CurrentLocation, out lEID, out pSnappedPoint);

                        if (pSnappedPoint == null)
                            continue;
                        if (lEID == 0)
                            continue;
                        //Get the complete id for the network element
                        pNetElements = (((INetworkClass)pFLayer.FeatureClass).GeometricNetwork.Network) as INetElements;

                        bTest = pNetElements.IsValidElement(lEID, esriElementType.esriETJunction);
                        pFeature = Globals.GetFeatureByEID(lEID, ((INetworkClass)pFLayer.FeatureClass).GeometricNetwork, pMap, esriElementType.esriETJunction);
                    }
                    if (bTest && pFeature != null)
                    {

                        retAcc = Globals.ReturnAccumulation(ref app, ref pFeature, sumAcc.WeightName, sumAcc.FlowDirection);
                        if (Globals.IsNumeric(retAcc))
                        {
                            MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_20b") + pFeature.OID + A4LGSharedFunctions.Localizer.GetString("In") + pFLayer.Name + A4LGSharedFunctions.Localizer.GetString("Is") + retAcc + ".");
                            //pFeature.set_Value(lSumFieldLoc, retAcc);
                            //pFeature.Store();
                        }
                    }
                    flowCalced =true;

                }

                if (flowCalced == false)
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20f"));

            }
            catch (Exception ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_20a") + "\n" + ex.Message);
            }
            finally
            {

                pMap = null;
                pFLayer = null;
                if (pFCursor != null)
                    Marshal.ReleaseComObject(pFCursor);
                pFCursor = null;
                pFeature = null;

                pSnappedPoint = null;
                pNetElements = null;
            }
        }
Example #7
0
        private void StartAnalysis(IFeature feature)
        {
            if (feature.FeatureType != esriFeatureType.esriFTSimpleJunction)
            {
                MessageService.Current.Warn("请选择管线点");
                return;
            }
            if (!_pipelineConfig.IsPipelineLayer(feature.Class.AliasName, enumPipelineDataType.Point))
            {
                MessageService.Current.Warn("请选择管线点");
                return;
            }
            double snapDist = CommonUtils.ConvertPixelsToMapUnits(_context.ActiveView,
                                                                  _context.Config.SnapTolerance);
            IBasicLayerInfo lineConfig =
                _plugin.PipeConfig.GetBasicLayerInfo(feature.Class as IFeatureClass) as IBasicLayerInfo;

            if (this._startPoint == null && _startEid == 0)
            {
                //开始记录起始点
                IPipelineLayer oldLayer = _pipelineConfig.GetPipelineLayer(feature.Class.AliasName,
                                                                           enumPipelineDataType.Point);
                if (oldLayer == null)
                {
                    MessageService.Current.Warn("你选择的图层不是合法的管线图层!");
                    return;
                }
                List <IBasicLayerInfo> basicInfos = oldLayer.GetLayers(enumPipelineDataType.Junction);

                IFeatureClass featureClass = basicInfos.Count > 0 ? basicInfos[0].FeatureClass : null;
                if (featureClass == null)
                {
                    MessageService.Current.Warn("管线图层没有构建网络图层!");
                    return;
                }
                INetworkClass networkClass = featureClass as INetworkClass;
                _geometricNetwork = networkClass.GeometricNetwork;
                IPointToEID pnToEid = new PointToEIDClass();
                pnToEid.GeometricNetwork = _geometricNetwork;
                pnToEid.SnapTolerance    = snapDist;
                pnToEid.SourceMap        = _context.FocusMap;
                pnToEid.GetNearestJunction(feature.Shape as IPoint, out _startEid, out _startPoint);
                return;
            }
            IPipelineLayer newLayer = _pipelineConfig.GetPipelineLayer(feature.Class.AliasName,
                                                                       enumPipelineDataType.Point);

            if (newLayer == null)
            {
                MessageService.Current.Warn("你选择的图层不是合法的管线图层!");
                return;
            }
            List <IBasicLayerInfo> basicInfos1 = newLayer.GetLayers(enumPipelineDataType.Junction);

            IFeatureClass featureClass2 = basicInfos1.Count > 0 ? basicInfos1[0].FeatureClass : null;

            if (featureClass2 == null)
            {
                MessageService.Current.Warn("第二个管线图层没有构建网络图层!");
                return;
            }
            INetworkClass networkClass2 = featureClass2 as INetworkClass;

            if (networkClass2.GeometricNetwork != _geometricNetwork)
            {
                if (MessageService.Current.Ask("两个点位属于不同的网络图层,使用第二个网络图层作为分析图层吗?") == false)
                {
                    return;
                }
                _geometricNetwork = networkClass2.GeometricNetwork;
                IPointToEID pnToEid = new PointToEIDClass();
                pnToEid.GeometricNetwork = _geometricNetwork;
                pnToEid.SnapTolerance    = snapDist;
                pnToEid.SourceMap        = _context.FocusMap;
                pnToEid.GetNearestJunction(feature.Shape as IPoint, out _startEid, out _startPoint);
                return;
            }

            try
            {
                IPointToEID pntEid = new PointToEIDClass();
                pntEid.GeometricNetwork = _geometricNetwork;
                pntEid.SourceMap        = _context.FocusMap;
                pntEid.SnapTolerance    = snapDist;

                pntEid.GetNearestJunction(feature.Shape as IPoint, out _endEid, out _endPoint);
                if (_endEid < 1)
                {
                    MessageService.Current.Warn("未能找到第二个分析点!");
                    return;
                }
                if (_startEid == _endEid)
                {
                    MessageService.Current.Warn("起点终点为同一个点!");
                    return;
                }

                INetElements  netElements  = _geometricNetwork.Network as INetElements;
                INetworkClass networkClass = feature.Class as INetworkClass;

                IJunctionFlag[] array   = new JunctionFlag[2];
                INetFlag        netFlag = new JunctionFlag() as INetFlag;

                int userClassID;
                int userID;
                int userSubID;
                netElements.QueryIDs(_endEid, esriElementType.esriETJunction, out userClassID, out userID, out userSubID);
                netFlag.UserClassID = (userClassID);
                netFlag.UserID      = (userID);
                netFlag.UserSubID   = (userSubID);
                IJunctionFlag value = netFlag as IJunctionFlag;
                array.SetValue(value, 0);
                INetFlag netFlag2 = new JunctionFlag() as INetFlag;
                netElements.QueryIDs(_startEid, esriElementType.esriETJunction, out userClassID,
                                     out userID, out userSubID);
                netFlag2.UserClassID = (userClassID);
                netFlag2.UserID      = (userID);
                netFlag2.UserSubID   = (userSubID);
                value = (netFlag2 as IJunctionFlag);
                array.SetValue(value, 1);
                ITraceFlowSolverGEN traceFlowSolverGEN = new TraceFlowSolver() as ITraceFlowSolverGEN;
                INetSolver          netSolver          = traceFlowSolverGEN as INetSolver;
                netSolver.SourceNetwork = _geometricNetwork.Network;
                traceFlowSolverGEN.PutJunctionOrigins(ref array);
                object[]    array2 = new object[1];
                IEnumNetEID enumNetEID;
                IEnumNetEID enumNetEID2;
                traceFlowSolverGEN.FindPath((esriFlowMethod)2, (esriShortestPathObjFn)1, out enumNetEID,
                                            out enumNetEID2, 1, ref array2);
                if (this.ipolyline_0 == null)
                {
                    this.ipolyline_0 = new Polyline() as IPolyline;
                }
                IGeometryCollection geometryCollection = this.ipolyline_0 as IGeometryCollection;
                geometryCollection.RemoveGeometries(0, geometryCollection.GeometryCount);
                if (enumNetEID2.Count <= 0)
                {
                    this.ifeature_0 = null;
                    MessageBox.Show("两点之间不存在路径可以连通!");
                }
                else
                {
                    ShowShortObjectForm showShortObjectForm = new ShowShortObjectForm(_context);
                    showShortObjectForm.pApp = _context;
                    ISpatialReference spatialReference = _context.FocusMap.SpatialReference;
                    IEIDHelper        eIDHelperClass   = new EIDHelper();
                    eIDHelperClass.GeometricNetwork       = (networkClass.GeometricNetwork);
                    eIDHelperClass.OutputSpatialReference = (spatialReference);
                    eIDHelperClass.ReturnGeometries       = (true);
                    eIDHelperClass.ReturnFeatures         = (true);
                    IEnumEIDInfo enumEIDInfo = eIDHelperClass.CreateEnumEIDInfo(enumNetEID2);
                    int          count       = enumEIDInfo.Count;
                    enumEIDInfo.Reset();
                    for (int i = 0; i < count; i++)
                    {
                        IEIDInfo  iEIDInfo = enumEIDInfo.Next();
                        IGeometry geometry = iEIDInfo.Geometry;
                        if (i == 0)
                        {
                            showShortObjectForm.AddPipeName(this.string_0);
                        }
                        showShortObjectForm.AddFeature(iEIDInfo.Feature);
                        geometryCollection.AddGeometryCollection(geometry as IGeometryCollection);
                    }
                    showShortObjectForm.AddShortPath(this.ipolyline_0);
                    showShortObjectForm.AddLenght(this.ipolyline_0.Length);
                    this.ifeature_2 = feature;
                    EsriUtils.ZoomToGeometry(this.ipolyline_0, _context.MapControl.Map, 1.3);
                    FlashUtility.FlashGeometry(this.ipolyline_0, _context.MapControl);
                    this.ifeature_0   = null;
                    _startEid         = 0;
                    _startPoint       = null;
                    _geometricNetwork = null;
                    showShortObjectForm.Show();
                }
            }
            catch (Exception ex)
            {
                this.ifeature_0 = null;
                MessageBox.Show(ex.Message);
            }
        }