Exemplo n.º 1
0
        //返回路径的几何体
        public IPolyline PathPolyLine()
        {
            IEIDInfo  ipEIDInfo;
            IGeometry ipGeometry;

            if (m_ipPolyline != null)
            {
                return(m_ipPolyline);
            }

            m_ipPolyline = new PolylineClass();
            IGeometryCollection ipNewGeometryColl = m_ipPolyline as IGeometryCollection;//引用传递

            ISpatialReference ipSpatialReference = m_ipMap.SpatialReference;
            IEIDHelper        ipEIDHelper        = new EIDHelperClass();

            ipEIDHelper.GeometricNetwork       = m_ipGeometricNetwork;
            ipEIDHelper.OutputSpatialReference = ipSpatialReference;
            ipEIDHelper.ReturnGeometries       = true;
            IEnumEIDInfo ipEnumEIDInfo = ipEIDHelper.CreateEnumEIDInfo(m_ipEnumNetEID_Edges);
            int          count         = ipEnumEIDInfo.Count;

            ipEnumEIDInfo.Reset();
            for (int i = 0; i < count; i++)
            {
                ipEIDInfo  = ipEnumEIDInfo.Next();
                ipGeometry = ipEIDInfo.Geometry;
                ipNewGeometryColl.AddGeometryCollection(ipGeometry as IGeometryCollection);
            }
            return(m_ipPolyline);
        }
Exemplo n.º 2
0
        //获取应急资源调度路线
        public void GetIElement(Collection <RouteNode> routeNodes)
        {
            try
            {
                IPolyline           pPolyLine           = new PolylineClass();
                IGeometryCollection pGeometryCollection = pPolyLine as IGeometryCollection;
                object    pObject   = Type.Missing;
                IGeometry pGeometry = null;
                for (int i = 0; i < routeNodes.Count; i++)
                {
                    if (i == routeNodes.Count - 1)
                    {
                        break;
                    }
                    int    StartID = Convert.ToInt32(routeNodes[i].NodeID);
                    string EndID   = Convert.ToString(routeNodes[i + 1].NodeID);
                    Node   pNode   = NodeList[StartID - 1];

                    for (int j = 0; j < pNode.EdgeList.Count; j++)
                    {
                        if (pNode.EdgeList[j].EndNodeID == EndID)
                        {
                            pGeometry = pNode.EdgeList[j].line as IGeometry;
                            pGeometryCollection.AddGeometryCollection(pGeometry as IGeometryCollection);
                            break;
                        }
                    }
                }
                Variable.PElement.Geometry = pPolyLine;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 合并两个几何形体
        /// </summary>
        /// <param name="pGeo"></param>
        /// <param name="pOtherGeo"></param>
        /// <returns></returns>
        private static IGeometry UnionGeometry(IGeometry Merge, IGeometry pOtherGeo)
        {
            IGeometryCollection geometryCollection1 = Merge as IGeometryCollection;
            IGeometryCollection geometryCollection2 = pOtherGeo as IGeometryCollection;

            try
            {
                geometryCollection1.AddGeometryCollection(geometryCollection2);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(geometryCollection1 as IGeometry);
        }
        /// <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);
        }
Exemplo n.º 5
0
        private void InitControls()
        {
            Item           item;
            IFeatureCursor fCursor;
            IFeature       pFeature;

            if (fcUpdata == null)
            {
                return;
            }
            fCursor  = fcUpdata.Search(null, true);
            pFeature = fCursor.NextFeature();
            if (pFeature == null)
            {
                XtraMessageBox.Show("当前地图中没有修测范围,已合并完成或没有进行更新数据操作!");
                return;
            }
            pGeometryC = new PolygonClass();
            int indexMark = pFeature.Fields.FindField(MARK);
            int index1    = pFeature.Fields.FindField(REGIONNAME);

            while (pFeature != null)
            {
                if (pFeature.Shape != null)
                {
                    if (pFeature.get_Value(indexMark).ToString() == "已导出,未导入更新")
                    {
                        item = new Item(pFeature.get_Value(index1).ToString(), pFeature);
                        lbx_UnMerge.Items.Add(item);
                    }
                    else
                    {
                        item = new Item(pFeature.get_Value(index1).ToString(), pFeature);
                        lbx_Merge.Items.Add(item);
                        pGeometryC.AddGeometryCollection(pFeature.Shape as IGeometryCollection);
                    }
                }
                pFeature = fCursor.NextFeature();
            }
            ITopologicalOperator pTopOperator = pGeometryC as ITopologicalOperator;

            pTopOperator.Simplify();
        }
Exemplo n.º 6
0
 //获取应急资源调度路线
 public static void GetIElement(List <IPolyline> routeroad)
 {
     try
     {
         IPolyline           pPolyLine           = new PolylineClass();
         IGeometryCollection pGeometryCollection = pPolyLine as IGeometryCollection;
         object    pObject   = Type.Missing;
         IGeometry pGeometry = null;
         for (int i = 0; i < routeroad.Count; i++)
         {
             pGeometry = routeroad[i] as IGeometry;
             pGeometryCollection.AddGeometryCollection(pGeometry as IGeometryCollection);
         }
         Variable.PElement.Geometry = pPolyLine;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常");
     }
 }
Exemplo n.º 7
0
        private IPolyline PathToPolyLine()
        {
            IPolyline           pPolyLine = new PolylineClass();
            IGeometryCollection pNewGeometryCollection = pPolyLine as IGeometryCollection;

            if (mEnumNetEID_Edges == null)
            {
                return(null);
            }

            IEIDHelper pEIDHelper = new EIDHelperClass();

            //获取几何网络
            pEIDHelper.GeometricNetwork = mGeometricNetwork;
            //获取地图空间参考
            ISpatialReference pSpatialReference = this.axMapControl1.Map.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);
        }
Exemplo n.º 8
0
        private static IPolycurve GetOriginalGeometry(
            [NotNull] IFeature feature,
            [CanBeNull] FeatureVertexInfo featureVertexInfo)
        {
            bool isPolygon = feature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon;

            if (featureVertexInfo == null)
            {
                return(GeometryFactory.CreatePolyline(feature.Shape));
            }

            featureVertexInfo.SimplifyCrackPoints();

            if (_msg.IsVerboseDebugEnabled)
            {
                _msg.VerboseDebugFormat(
                    "Cutting input geometry with protected points. Generalization Info: {0}",
                    featureVertexInfo.ToString(true));
            }

            IPolyline originalGeometry = featureVertexInfo.OriginalClippedPolyline;

            if (featureVertexInfo.CrackPointCollection == null ||
                featureVertexInfo.CrackPointCollection.PointCount == 0)
            {
                return(originalGeometry);
            }

            // TODO: consider consolidating points equal in XY: get average Z (or Z from non-editable feature)
            //		 to really make coincident!
            IPointCollection protectedPoints = featureVertexInfo.CrackPointCollection;

            IGeometryCollection splittedResult = null;

            foreach (IPath path in GeometryUtils.GetPaths(originalGeometry))
            {
                bool splitHappenedAtFrom;

                double     cutOffDistance = GeometryUtils.GetXyTolerance(originalGeometry);
                const bool projectPointsOntoPathToSplit = true;

                IGeometryCollection splittedPaths = GeometryUtils.SplitPath(
                    path, protectedPoints, projectPointsOntoPathToSplit, cutOffDistance,
                    out splitHappenedAtFrom);

                if (isPolygon && path.IsClosed && !splitHappenedAtFrom &&
                    splittedPaths.GeometryCount > 1)
                {
                    MergeLastWithFirstPart(splittedPaths);
                }

                if (splittedResult == null)
                {
                    splittedResult = splittedPaths;
                }
                else
                {
                    splittedResult.AddGeometryCollection(splittedPaths);
                }
            }

            if (_msg.IsVerboseDebugEnabled)
            {
                _msg.VerboseDebugFormat("Original feature {0} splitted by protected points: {1}",
                                        GdbObjectUtils.ToString(feature),
                                        GeometryUtils.ToString((IGeometry)splittedResult));
            }

            return(splittedResult as IPolycurve);
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
 public void EndSketch()
 {
     try
     {
         IGeometry geometry = null;
         if (SketchToolAssist.Feedback is INewLineFeedback)
         {
             INewLineFeedback newLineFeedback = (INewLineFeedback)SketchToolAssist.Feedback;
             IPolyline        polyline        = newLineFeedback.Stop();
             if (polyline != null)
             {
                 IPointCollection pointCollection = (IPointCollection)polyline;
                 if (pointCollection.PointCount >= 2)
                 {
                     geometry = (IGeometry)pointCollection;
                     if (SketchShareEx.m_LastPartGeometry != null &&
                         SketchShareEx.m_LastPartGeometry is IPolyline)
                     {
                         IGeometryCollection geometryCollection =
                             SketchShareEx.m_LastPartGeometry as IGeometryCollection;
                         geometryCollection.AddGeometryCollection(polyline as IGeometryCollection);
                         geometry = (geometryCollection as IGeometry);
                         SketchShareEx.m_LastPartGeometry = null;
                     }
                 }
             }
         }
         else if (SketchToolAssist.Feedback is INewPolygonFeedback)
         {
             INewPolygonFeedback newPolygonFeedback = (INewPolygonFeedback)SketchToolAssist.Feedback;
             IPolygon            polygon            = newPolygonFeedback.Stop();
             if (polygon != null)
             {
                 IPointCollection pointCollection = (IPointCollection)polygon;
                 if (pointCollection.PointCount >= 3)
                 {
                     geometry = (IGeometry)pointCollection;
                     if (SketchShareEx.m_LastPartGeometry != null && SketchShareEx.m_LastPartGeometry is IPolygon)
                     {
                         IGeometryCollection geometryCollection =
                             SketchShareEx.m_LastPartGeometry as IGeometryCollection;
                         geometryCollection.AddGeometryCollection(polygon as IGeometryCollection);
                         geometry = (geometryCollection as IGeometry);
                         SketchShareEx.m_LastPartGeometry = null;
                     }
                 }
             }
         }
         if (geometry == null)
         {
             return;
         }
         this.CreateFeature(geometry);
     }
     catch (Exception ex2)
     {
         COMException ex = ex2 as COMException;
         if (ex.ErrorCode == -2147220936)
         {
             System.Windows.Forms.MessageBox.Show("坐标值或量测值超出范围!", "创建要素",
                                                  System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
         }
         CErrorLog.writeErrorLog(this, ex2, "");
     }
     _context.ActiveView.Refresh();
     SketchShareEx.m_bInUse    = false;
     SketchShareEx.LastPoint   = null;
     SketchToolAssist.Feedback = null;
     SketchShareEx.PointCount  = 0;
 }
Exemplo n.º 11
0
        /// <summary>
        /// 完成新建对象,取得绘制的对象,并添加到图层中
        /// 建议在Map.DblClick或Map.MouseDown(Button = 2)事件中调用本方法
        /// </summary>
        public void NewFeatureEnd()
        {
            IGeometry        pGeom = null;
            IPointCollection pPointCollection;
            object           obj = Type.Missing;

            try
            {
                if (m_pFeedback is INewMultiPointFeedback)
                {
                    INewMultiPointFeedback pMPFeed = (INewMultiPointFeedback)m_pFeedback;
                    pMPFeed.Stop();
                    pGeom = (IGeometry)m_pPointCollection;

                    if (m_GeometryCollection == null)
                    {
                        m_GeometryCollection = new PointClass() as IGeometryCollection;
                    }

                    m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection);
                }
                else if (m_pFeedback is INewLineFeedback)
                {
                    INewLineFeedback pLineFeed = (INewLineFeedback)m_pFeedback;

                    if (m_GeometryCollection == null)
                    {
                        m_GeometryCollection = new PolylineClass() as IGeometryCollection;
                    }

                    IPolyline pPolyLine = pLineFeed.Stop();

                    pPointCollection = (IPointCollection)pPolyLine;
                    if (pPointCollection.PointCount < 2)
                    {
                        MessageBox.Show("至少输入两个节点");
                    }
                    else
                    {
                        pGeom = (IGeometry)pPointCollection;
                    }

                    m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection);
                }
                else if (m_pFeedback is INewPolygonFeedback)
                {
                    INewPolygonFeedback pPolyFeed = (INewPolygonFeedback)m_pFeedback;

                    if (m_GeometryCollection == null)
                    {
                        m_GeometryCollection = new PolygonClass() as IGeometryCollection;
                    }

                    IPolygon pPolygon;
                    pPolygon = pPolyFeed.Stop();
                    if (pPolygon != null)
                    {
                        pPointCollection = (IPointCollection)pPolygon;
                        if (pPointCollection.PointCount < 3)
                        {
                            MessageBox.Show("至少输入三个节点");
                        }
                        else
                        {
                            pGeom = (IGeometry)pPointCollection;
                        }

                        m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection);
                    }
                }
                if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    IPolyline pline = MyMapHelp.PolygonToPolyline(m_GeometryCollection as IPolygon);
                    CreateFeature(pline as IGeometry);
                }
                else
                {
                    CreateFeature(m_GeometryCollection as IGeometry);
                }
                m_pFeedback          = null;
                m_bInUse             = false;
                m_GeometryCollection = null;
            }
            catch (Exception e)
            {
                m_pFeedback          = null;
                m_bInUse             = false;
                m_GeometryCollection = null;
                Console.WriteLine(e.Message.ToString());
            }
        }
Exemplo n.º 12
0
        private void SetButton_Click(object obj, EventArgs eventArgs)
        {
            int count  = this.listJunctionFlag.Count;
            int count2 = this.listEdgeFlag.Count;
            int count3 = this.listJunctionBarrier.Count;
            int count4 = this.listEdgeBarrier.Count;

            if (count < 1 && count2 < 1)
            {
                MessageBox.Show("请用户选择要分析的点或线!");
            }
            else
            {
                IEdgeFlag[]     array        = new EdgeFlag[count2];
                IJunctionFlag[] array2       = new JunctionFlag[count];
                INetwork        network      = null;
                INetworkClass   networkClass = null;
                if (count > 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        IFeature feature = this.listJunctionFlag[i];
                        networkClass = (feature.Class as INetworkClass);
                        network      = networkClass.GeometricNetwork.Network;
                        INetElements           netElements           = network as INetElements;
                        INetFlag               netFlag               = new JunctionFlag() as INetFlag;
                        ISimpleJunctionFeature simpleJunctionFeature = feature as ISimpleJunctionFeature;
                        int userClassID;
                        int userID;
                        int userSubID;
                        netElements.QueryIDs(simpleJunctionFeature.EID, (esriElementType)1, out userClassID, out userID,
                                             out userSubID);
                        netFlag.UserClassID = (userClassID);
                        netFlag.UserID      = (userID);
                        netFlag.UserSubID   = (userSubID);
                        IJunctionFlag junctionFlag = netFlag as IJunctionFlag;
                        array2[i] = junctionFlag;
                    }
                }
                if (count2 > 0)
                {
                    for (int j = 0; j < count2; j++)
                    {
                        IFeature feature2 = this.listEdgeFlag[j];
                        networkClass = (feature2.Class as INetworkClass);
                        network      = networkClass.GeometricNetwork.Network;
                        INetElements       netElements2      = network as INetElements;
                        INetFlag           netFlag2          = new EdgeFlag() as INetFlag;
                        ISimpleEdgeFeature simpleEdgeFeature = feature2 as ISimpleEdgeFeature;
                        int userClassID2;
                        int userID2;
                        int userSubID2;
                        netElements2.QueryIDs(simpleEdgeFeature.EID, (esriElementType)2, out userClassID2, out userID2,
                                              out userSubID2);
                        netFlag2.UserClassID = (userClassID2);
                        netFlag2.UserID      = (userID2);
                        netFlag2.UserSubID   = (userSubID2);
                        IEdgeFlag edgeFlag = netFlag2 as IEdgeFlag;
                        array[j] = edgeFlag;
                    }
                }
                ITraceFlowSolverGEN    traceFlowSolverGEN    = new TraceFlowSolver() as ITraceFlowSolverGEN;
                INetSolver             netSolver             = traceFlowSolverGEN as INetSolver;
                INetElementBarriersGEN netElementBarriersGEN = new NetElementBarriers();
                netElementBarriersGEN.Network     = (network);
                netElementBarriersGEN.ElementType = (esriElementType)(1);
                int[] array3 = new int[count3];
                int   num    = 0;
                if (count3 > 0)
                {
                    for (int k = 0; k < count3; k++)
                    {
                        IFeature feature3 = this.listJunctionBarrier[k];
                        networkClass = (feature3.Class as INetworkClass);
                        network      = networkClass.GeometricNetwork.Network;
                        INetElements netElements3 = network as INetElements;
                        new EdgeFlag();
                        ISimpleJunctionFeature simpleJunctionFeature2 = feature3 as ISimpleJunctionFeature;
                        int num2;
                        int num3;
                        netElements3.QueryIDs(simpleJunctionFeature2.EID, (esriElementType)1, out num, out num2,
                                              out num3);
                        array3[k] = num2;
                    }
                    netElementBarriersGEN.SetBarriers(num, ref array3);
                    netSolver.set_ElementBarriers((esriElementType)1, (INetElementBarriers)netElementBarriersGEN);
                }
                INetElementBarriersGEN netElementBarriersGEN2 = new NetElementBarriers();
                netElementBarriersGEN2.Network     = (network);
                netElementBarriersGEN2.ElementType = (esriElementType)(2);
                int[] array4 = new int[count4];
                if (count4 > 0)
                {
                    for (int l = 0; l < count4; l++)
                    {
                        IFeature feature4 = this.listEdgeBarrier[l];
                        networkClass = (feature4.Class as INetworkClass);
                        network      = networkClass.GeometricNetwork.Network;
                        INetElements netElements4 = network as INetElements;
                        new EdgeFlag();
                        ISimpleEdgeFeature simpleEdgeFeature2 = feature4 as ISimpleEdgeFeature;
                        int num4;
                        int num5;
                        netElements4.QueryIDs(simpleEdgeFeature2.EID, (esriElementType)2, out num, out num4, out num5);
                        array4[l] = num4;
                    }
                    netElementBarriersGEN2.SetBarriers(num, ref array4);
                    netSolver.set_ElementBarriers((esriElementType)2, (INetElementBarriers)netElementBarriersGEN2);
                }
                netSolver.SourceNetwork = (network);
                if (count > 0)
                {
                    traceFlowSolverGEN.PutJunctionOrigins(ref array2);
                }
                if (count2 > 0)
                {
                    traceFlowSolverGEN.PutEdgeOrigins(ref array);
                }
                IEnumNetEID enumNetEID  = null;
                IEnumNetEID enumNetEID2 = null;
                object[]    array5      = new object[1];
                if (this.WayCom.SelectedIndex == 0)
                {
                    traceFlowSolverGEN.FindSource(0, (esriShortestPathObjFn)1, out enumNetEID, out enumNetEID2,
                                                  count + count2, ref array5);
                }
                if (this.WayCom.SelectedIndex == 1)
                {
                    traceFlowSolverGEN.FindSource((esriFlowMethod)1, (esriShortestPathObjFn)1, out enumNetEID,
                                                  out enumNetEID2, count + count2, ref array5);
                }
                IPolyline           polyline           = new Polyline() as IPolyline;
                IGeometryCollection geometryCollection = polyline as IGeometryCollection;
                ISpatialReference   spatialReference   = this.m_iApp.FocusMap.SpatialReference;
                IEIDHelper          iEIDHelper         = new EIDHelper();
                iEIDHelper.GeometricNetwork       = (networkClass.GeometricNetwork);
                iEIDHelper.OutputSpatialReference = (spatialReference);
                iEIDHelper.ReturnGeometries       = (true);
                iEIDHelper.ReturnFeatures         = (true);
                int selectedIndex = this.LayerCom.SelectedIndex;
                if (selectedIndex >= 0 && this.MapControl != null)
                {
                    this.LayerCom.SelectedItem.ToString();
                    IFeatureLayer ifeatureLayer_ = ((TrackingAnalyForm.LayerInfo) this.LayerCom.SelectedItem)._layer;
                    if (ifeatureLayer_ != null)
                    {
                        IFeatureSelection featureSelection = (IFeatureSelection)ifeatureLayer_;
                        featureSelection.Clear();
                        if (enumNetEID2 != null)
                        {
                            IEnumEIDInfo enumEIDInfo = iEIDHelper.CreateEnumEIDInfo(enumNetEID2);
                            int          count5      = enumEIDInfo.Count;
                            enumEIDInfo.Reset();
                            for (int m = 0; m < count5; m++)
                            {
                                IEIDInfo iEIDInfo = enumEIDInfo.Next();
                                featureSelection.Add(iEIDInfo.Feature);
                                IGeometry geometry = iEIDInfo.Geometry;
                                geometryCollection.AddGeometryCollection(geometry as IGeometryCollection);
                            }
                        }
                        featureSelection.SelectionSet.Refresh();
                        IActiveView activeView = this.m_iApp.ActiveView;
                        activeView.Refresh();
                        CMapOperator.ShowFeatureWithWink(this.m_iApp.ActiveView.ScreenDisplay, polyline);
                    }
                }
            }
        }
Exemplo n.º 13
0
 public void EndSketch()
 {
     SketchShareEx.LastPoint = null;
     if (SketchToolAssist.Feedback is INewLineFeedback)
     {
         (SketchToolAssist.Feedback as INewPolylineFeedback).CompletePart();
     }
     else if (SketchToolAssist.Feedback is INewPolygonFeedbackEx)
     {
         (SketchToolAssist.Feedback as INewPolygonFeedbackEx).CompletePart();
     }
     else
     {
         if (!(SketchToolAssist.Feedback is INewMultiPointFeedback))
         {
             if (SketchToolAssist.Feedback is INewLineFeedback)
             {
                 INewLineFeedback newLineFeedback = (INewLineFeedback)SketchToolAssist.Feedback;
                 IPolyline        polyline        = newLineFeedback.Stop();
                 if (polyline != null)
                 {
                     IPointCollection pointCollection = (IPointCollection)polyline;
                     if (pointCollection.PointCount >= 2)
                     {
                         IGeometry geometry = (IGeometry)pointCollection;
                         if (SketchShareEx.m_LastPartGeometry != null &&
                             SketchShareEx.m_LastPartGeometry is IPolyline)
                         {
                             if ((SketchShareEx.m_LastPartGeometry as ITopologicalOperator).IsSimple)
                             {
                                 (SketchShareEx.m_LastPartGeometry as ITopologicalOperator).Simplify();
                             }
                             if ((geometry as ITopologicalOperator).IsSimple)
                             {
                                 (geometry as ITopologicalOperator).Simplify();
                             }
                             geometry =
                                 (SketchShareEx.m_LastPartGeometry as ITopologicalOperator).Union(
                                     (IGeometry)pointCollection);
                         }
                         SketchShareEx.m_LastPartGeometry = geometry;
                     }
                 }
             }
             else if (SketchToolAssist.Feedback is INewPolygonFeedback)
             {
                 INewPolygonFeedback newPolygonFeedback = (INewPolygonFeedback)SketchToolAssist.Feedback;
                 IPolygon            polygon            = newPolygonFeedback.Stop();
                 if (polygon != null)
                 {
                     IPointCollection pointCollection = (IPointCollection)polygon;
                     if (pointCollection.PointCount >= 3)
                     {
                         IGeometry geometry = (IGeometry)pointCollection;
                         if (SketchShareEx.m_LastPartGeometry != null)
                         {
                             if (SketchShareEx.m_LastPartGeometry is IPolygon)
                             {
                                 if ((SketchShareEx.m_LastPartGeometry as ITopologicalOperator).IsSimple)
                                 {
                                     (SketchShareEx.m_LastPartGeometry as ITopologicalOperator).Simplify();
                                 }
                                 if ((geometry as ITopologicalOperator).IsSimple)
                                 {
                                     (geometry as ITopologicalOperator).Simplify();
                                 }
                                 IGeometryCollection geometryCollection =
                                     SketchShareEx.m_LastPartGeometry as IGeometryCollection;
                                 geometryCollection.AddGeometryCollection(polygon as IGeometryCollection);
                             }
                         }
                         else
                         {
                             SketchShareEx.m_LastPartGeometry = geometry;
                         }
                     }
                 }
             }
         }
         SketchToolAssist.Feedback = null;
         SketchShareEx.PointCount  = 0;
         SketchShareEx.m_bInUse    = false;
         _context.ActiveView.Refresh();
     }
 }