コード例 #1
0
        /// <summary>
        /// 连通判断
        /// </summary>
        /// <param name="PipeConIdFlag">需要判断的ID</param>
        public void ConenectJudge(int PipeConIdFlag)
        {
            #region 找出上下游弧段 管点,并赋值给数组
            DatasetVector network = mConNetWorkName;
            try
            {
                //设置分析环境
                FacilityAnalystSetting3D facilityAnalystSetting = new FacilityAnalystSetting3D();
                facilityAnalystSetting.NetworkDataset = network;
                facilityAnalystSetting.EdgeIDField    = "SMEDGEID";
                facilityAnalystSetting.NodeIDField    = "SMNODEID";
                facilityAnalystSetting.FNodeIDField   = "SMFNODE";
                facilityAnalystSetting.TNodeIDField   = "SMTNODE";
                facilityAnalystSetting.Tolerance      = 0.001;


                //权字段信息设置
                WeightFieldInfo3D weightFieldInfo = new WeightFieldInfo3D();
                weightFieldInfo.Name          = "Length";
                weightFieldInfo.FTWeightField = "SMLENGTH";
                weightFieldInfo.TFWeightField = "SMLENGTH";
                WeightFieldInfos3D weightFieldInfos = new WeightFieldInfos3D();
                weightFieldInfos.Add(weightFieldInfo);
                facilityAnalystSetting.WeightFieldInfos = weightFieldInfos;


                FacilityAnalyst3D mfacilityAnalyst = new FacilityAnalyst3D();
                mfacilityAnalyst.AnalystSetting = facilityAnalystSetting;

                bool isLoad = mfacilityAnalyst.Load();//是否加载模型
                if (isLoad)
                {
                    if (recordsetTypeConId1 == GeometryType.GeoPoint3D)//以点查找上下游弧段
                    {
                        //根据点查上游
                        FacilityAnalystResult3D TraceUpFromNode = mfacilityAnalyst.TraceUpFromNode(PipeConIdFlag, "Length", true);
                        {
                            //判断是否为空 若为空则实例化,避免在删除时候出错
                            if (TraceUpFromNode != null)
                            {
                                mConnectUpEdges = new Int32[TraceUpFromNode.Edges.Length];
                                for (int i = 0; i < TraceUpFromNode.Edges.Length; i++)
                                {
                                    mConnectUpEdges[i] = TraceUpFromNode.Edges[i];
                                }
                            }
                            else
                            {
                                mConnectUpEdges = new Int32[1];
                            }
                        }


                        {
                            if (TraceUpFromNode != null)
                            {
                                mConnectUpNodes = new Int32[TraceUpFromNode.Nodes.Length];
                                for (int i = 0; i < TraceUpFromNode.Nodes.Length; i++)
                                {
                                    mConnectUpNodes[i] = TraceUpFromNode.Nodes[i];
                                }
                            }
                            else
                            {
                                mConnectUpNodes = new Int32[1];
                            }
                        }
                        //根据结点查下游
                        FacilityAnalystResult3D TraceDownFromNode = mfacilityAnalyst.TraceDownFromNode(PipeConIdFlag, "Length", true);
                        {
                            if (TraceDownFromNode != null)
                            {
                                mConnectDownEdges = new Int32[TraceDownFromNode.Edges.Length];
                                for (int i = 0; i < TraceDownFromNode.Edges.Length; i++)
                                {
                                    mConnectDownEdges[i] = TraceDownFromNode.Edges[i];
                                }
                            }
                            else
                            {
                                mConnectDownEdges = new Int32[1];
                            }
                        }

                        {
                            if (TraceDownFromNode != null)
                            {
                                mConnectDownNodes = new Int32[TraceDownFromNode.Nodes.Length];
                                for (int i = 0; i < TraceDownFromNode.Nodes.Length; i++)
                                {
                                    mConnectDownNodes[i] = TraceDownFromNode.Nodes[i];
                                }
                            }
                            else
                            {
                                mConnectDownNodes = new Int32[1];
                            }
                        }
                    }
                    else if (recordsetTypeConId1 == GeometryType.GeoLine3D)//以弧段查找弧段
                    {
                        //以弧段查找上游
                        FacilityAnalystResult3D TraceUpFromEdge = mfacilityAnalyst.TraceUpFromEdge(PipeConIdFlag, "Length", true);
                        {
                            if (TraceUpFromEdge != null)
                            {
                                mConnectUpEdges = new Int32[TraceUpFromEdge.Edges.Length];
                                for (int i = 0; i < TraceUpFromEdge.Edges.Length; i++)
                                {
                                    mConnectUpEdges[i] = TraceUpFromEdge.Edges[i];
                                }
                            }
                            else
                            {
                                mConnectUpEdges = new Int32[1];
                            }
                        }
                        {
                            if (TraceUpFromEdge != null)
                            {
                                mConnectUpNodes = new Int32[TraceUpFromEdge.Nodes.Length];
                                for (int i = 0; i < TraceUpFromEdge.Nodes.Length; i++)
                                {
                                    mConnectUpNodes[i] = TraceUpFromEdge.Nodes[i];
                                }
                            }
                            else
                            {
                                mConnectUpNodes = new Int32[1];
                            }
                        }
                        //根据弧段查下游
                        FacilityAnalystResult3D TraceDownFromEdge = mfacilityAnalyst.TraceDownFromEdge(PipeConIdFlag, "Length", true);
                        {
                            if (TraceDownFromEdge != null)
                            {
                                mConnectDownEdges = new Int32[TraceDownFromEdge.Edges.Length];
                                for (int i = 0; i < TraceDownFromEdge.Edges.Length; i++)
                                {
                                    mConnectDownEdges[i] = TraceDownFromEdge.Edges[i];
                                }
                            }
                            else
                            {
                                mConnectDownEdges = new Int32[1];
                            }
                        }
                        {
                            if (TraceDownFromEdge != null)
                            {
                                mConnectDownNodes = new Int32[TraceDownFromEdge.Nodes.Length];
                                for (int i = 0; i < TraceDownFromEdge.Nodes.Length; i++)
                                {
                                    mConnectDownNodes[i] = TraceDownFromEdge.Nodes[i];
                                }
                            }
                            else
                            {
                                mConnectDownNodes = new Int32[1];
                            }
                        }
                    }
                }

                #endregion

                #region 遍历上下游数组,寻找是否连通
                //若为线,遍历上下游弧段 若为点,遍历上下游管点

                if (recordsetTypeConId1 == GeometryType.GeoLine3D)
                {
                    //第一次遍历时,进入前mConnectFlag=0,进入后若mConnectFlag=0,则进入下一个判断,若=1,说明连通 不在进行判断
                    //遍历上游弧段
                    for (int i = 0; i < mConnectUpEdges.Length; i++)
                    {
                        if (mConnectUpEdges[i] == mPipeConId2)
                        {
                            mConnectFlag = 1;
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    if (mConnectFlag != 1)
                    {
                        //遍历下游弧段
                        for (int i = 0; i < mConnectDownEdges.Length; i++)
                        {
                            if (mConnectDownEdges[i] == mPipeConId2)
                            {
                                mConnectFlag = 1;
                                break;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                }
                if (recordsetTypeConId1 == GeometryType.GeoPoint3D)
                {
                    if (mConnectFlag != 1)
                    {
                        //遍历上游管点
                        for (int i = 0; i < mConnectUpNodes.Length; i++)
                        {
                            if (mConnectUpNodes[i] == mPipeConId2)
                            {
                                mConnectFlag = 1;
                                break;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    if (mConnectFlag != 1)
                    {
                        //遍历下游管点
                        for (int i = 0; i < mConnectDownNodes.Length; i++)
                        {
                            if (mConnectDownNodes[i] == mPipeConId2)
                            {
                                mConnectFlag = 1;
                                break;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
        }
コード例 #2
0
        /// <summary>
        /// 寻找源/汇/上游/下游
        /// </summary>
        /// <param name="SeachFlag"></param>
        public void FindSourceAndSink(string SeachFlag)
        {
            try
            {
                //三维网络信息设置
                FacilityAnalystSetting3D facilityAnalystSetting = new FacilityAnalystSetting3D();
                facilityAnalystSetting.NetworkDataset = network;
                // facilityAnalystSetting.DirectionField = "direction";
                facilityAnalystSetting.EdgeIDField  = "SMEDGEID";
                facilityAnalystSetting.NodeIDField  = "SMNODEID";
                facilityAnalystSetting.FNodeIDField = "SMFNODE";
                facilityAnalystSetting.TNodeIDField = "SMTNODE";
                facilityAnalystSetting.Tolerance    = 0.001;


                //权字段信息设置
                WeightFieldInfo3D weightFieldInfo = new WeightFieldInfo3D();
                weightFieldInfo.Name          = "Length";
                weightFieldInfo.FTWeightField = "SMLENGTH";
                weightFieldInfo.TFWeightField = "SMLENGTH";
                WeightFieldInfos3D weightFieldInfos = new WeightFieldInfos3D();
                weightFieldInfos.Add(weightFieldInfo);
                facilityAnalystSetting.WeightFieldInfos = weightFieldInfos;


                mfacilityAnalyst = new FacilityAnalyst3D();
                mfacilityAnalyst.AnalystSetting = facilityAnalystSetting;

                bool isLoad = mfacilityAnalyst.Load();//是否加载模型
                if (isLoad)
                {
                    switch (SeachFlag)
                    {
                    case "Line":
                        #region 根据弧段查找
                        //根据弧段查找汇
                        FacilityAnalystResult3D resultSinkFromEdges = mfacilityAnalyst.FindSinkFromEdge(mPipeId1, "Length", true);
                        //汇弧段ID数组
                        {
                            if (resultSinkFromEdges != null)
                            {
                                mSinkFromNodeCost = resultSinkFromEdges.Cost;
                                mSinkEdges        = new Int32[resultSinkFromEdges.Edges.Length];
                                for (int i = 0; i < resultSinkFromEdges.Edges.Length; i++)
                                {
                                    mSinkEdges[i] = resultSinkFromEdges.Edges[i];
                                }
                                //汇结点ID
                                for (int i = 0; i < resultSinkFromEdges.Nodes.Length; i++)
                                {
                                    if (i == resultSinkFromEdges.Nodes.Length - 1)
                                    {
                                        mSinkNode = resultSinkFromEdges.Nodes[i];
                                    }
                                }
                            }
                            else
                            {
                                mSinkEdges = new Int32[1]; mSinkFromNodeCost = 0;
                            }
                        }

                        //根据弧段查找源
                        FacilityAnalystResult3D resultSourceFromEdges = mfacilityAnalyst.FindSourceFromEdge(mPipeId1, "Length", true);


                        //源弧段ID数组
                        {
                            if (resultSourceFromEdges != null)
                            {
                                mSourceFromNodeCost = resultSourceFromEdges.Cost;
                                mSourceEdges        = new Int32[resultSourceFromEdges.Edges.Length];
                                for (int i = 0; i < resultSourceFromEdges.Edges.Length; i++)
                                {
                                    mSourceEdges[i] = resultSourceFromEdges.Edges[i];
                                }
                                //源节点ID
                                for (int i = 0; i < resultSourceFromEdges.Nodes.Length; i++)
                                {
                                    if (i == resultSourceFromEdges.Nodes.Length - 1)
                                    {
                                        mSourceNode = resultSourceFromEdges.Nodes[i];
                                    }
                                }
                            }
                            else
                            {
                                mSourceEdges = new Int32[1]; mSourceFromNodeCost = 0;
                            }
                        }



                        //根据弧段查上游
                        FacilityAnalystResult3D TraceUpFromEdges = mfacilityAnalyst.TraceUpFromEdge(mPipeId1, "Length", true);
                        {
                            if (TraceUpFromEdges != null)
                            {
                                mTraceUpEdges = new Int32[TraceUpFromEdges.Edges.Length];
                                for (int i = 0; i < TraceUpFromEdges.Edges.Length; i++)
                                {
                                    mTraceUpEdges[i] = TraceUpFromEdges.Edges[i];
                                }
                            }
                            else
                            {
                                mTraceUpEdges = new Int32[1];
                            }
                        }

                        //根据弧段查下游
                        FacilityAnalystResult3D TraceDownFromEdges = mfacilityAnalyst.TraceDownFromEdge(mPipeId1, "Length", true);
                        {
                            if (TraceDownFromEdges != null)
                            {
                                mTraceDownEdges = new Int32[TraceDownFromEdges.Edges.Length];
                                for (int i = 0; i < TraceDownFromEdges.Edges.Length; i++)
                                {
                                    mTraceDownEdges[i] = TraceDownFromEdges.Edges[i];
                                }
                            }
                            else
                            {
                                mTraceDownEdges = new Int32[1];
                            }
                        }

                        #endregion
                        break;

                    case "Node":
                        #region 根据结点查找
                        //根据结点查找汇
                        FacilityAnalystResult3D resultSinkFromNode = mfacilityAnalyst.FindSinkFromNode(mPipeId1, "Length", true);


                        //汇弧段ID数组
                        {
                            if (resultSinkFromNode != null)
                            {
                                mSinkFromNodeCost = resultSinkFromNode.Cost;
                                mSinkEdges        = new Int32[resultSinkFromNode.Edges.Length];
                                for (int i = 0; i < resultSinkFromNode.Edges.Length; i++)
                                {
                                    mSinkEdges[i] = resultSinkFromNode.Edges[i];
                                }
                            }
                            else
                            {
                                mSinkEdges = new Int32[1]; mSinkFromNodeCost = 0;
                            }
                        }

                        //汇结点数组
                        {
                            if (resultSinkFromNode != null)
                            {
                                Int32[] SinkNodes = new Int32[resultSinkFromNode.Nodes.Length];
                                for (int i = 0; i < resultSinkFromNode.Nodes.Length; i++)
                                {
                                    SinkNodes[i] = resultSinkFromNode.Nodes[i];
                                    if (i == resultSinkFromNode.Nodes.Length - 1)
                                    {
                                        mSinkNode = resultSinkFromNode.Nodes[i];
                                    }
                                }
                            }
                            else
                            {
                                Int32[] SinkNodes = new Int32[1];
                            }
                        }


                        //根据结点查找源
                        FacilityAnalystResult3D resultSourceFromNode = mfacilityAnalyst.FindSourceFromNode(mPipeId1, "Length", true);


                        //源弧段ID数组
                        {
                            if (resultSourceFromNode != null)
                            {
                                mSourceFromNodeCost = resultSourceFromNode.Cost;
                                mSourceEdges        = new Int32[resultSourceFromNode.Edges.Length];
                                for (int i = 0; i < resultSourceFromNode.Edges.Length; i++)
                                {
                                    mSourceEdges[i] = resultSourceFromNode.Edges[i];
                                }
                            }
                            else
                            {
                                mSourceEdges = new Int32[1]; mSourceFromNodeCost = 0;
                            }
                        }

                        //源节点ID数组
                        if (resultSourceFromNode != null)
                        {
                            Int32[] SourceNodes = new Int32[resultSourceFromNode.Nodes.Length];
                            for (int i = 0; i < resultSourceFromNode.Nodes.Length; i++)
                            {
                                SourceNodes[i] = resultSourceFromNode.Nodes[i];
                                if (i == resultSourceFromNode.Nodes.Length - 1)
                                {
                                    mSourceNode = resultSourceFromNode.Nodes[i];
                                }
                            }
                        }
                        else
                        {
                            Int32[] SourceNodes = new Int32[1];
                        }



                        //根据结点查上游
                        FacilityAnalystResult3D TraceUpFromNode = mfacilityAnalyst.TraceUpFromNode(mPipeId1, "Length", true);
                        {
                            if (TraceUpFromNode != null)
                            {
                                mTraceUpEdges = new Int32[TraceUpFromNode.Edges.Length];
                                for (int i = 0; i < TraceUpFromNode.Edges.Length; i++)
                                {
                                    mTraceUpEdges[i] = TraceUpFromNode.Edges[i];
                                }
                            }
                            else
                            {
                                mTraceUpEdges = new Int32[1];
                            }
                        }

                        //根据结点查下游
                        FacilityAnalystResult3D TraceDownFromNode = mfacilityAnalyst.TraceDownFromNode(mPipeId1, "Length", true);
                        if (TraceDownFromNode != null)
                        {
                            mTraceDownEdges = new Int32[TraceDownFromNode.Edges.Length];
                            for (int i = 0; i < TraceDownFromNode.Edges.Length; i++)
                            {
                                mTraceDownEdges[i] = TraceDownFromNode.Edges[i];
                            }
                        }
                        else
                        {
                            mTraceDownEdges = new Int32[1];
                        }

                        #endregion
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
        }