コード例 #1
0
        /// <summary>
        /// Add two junction flags to TraceSolver
        /// </summary>
        /// <param name="traceFlowSolver">object TraceSolver</param>
        /// <param name="netflag1">1° junction flag</param>
        /// <param name="netflag2">2° junction flag</param>
        internal static void AddTwoJunctionFlagsToTraceSolver(ref ITraceFlowSolverGEN traceFlowSolver, INetFlag netflag1, INetFlag netflag2)
        {
            IJunctionFlag junctionflag1 = netflag1 as IJunctionFlag;
            IJunctionFlag junctionflag2 = netflag2 as IJunctionFlag;

            if (junctionflag1 != null && junctionflag2 != null)
            {
                IJunctionFlag[] junctionflags = new IJunctionFlag[2];
                junctionflags[0] = junctionflag1 as IJunctionFlag;
                junctionflags[1] = junctionflag2 as IJunctionFlag;
                traceFlowSolver.PutJunctionOrigins(ref junctionflags);
            }
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        private void ResultBtn_Click(object sender, EventArgs e)
        {
            try
            {
                #region 设置管点分析分析条件
                //为追踪任务分析器设置管点
                IJunctionFlag[] arrayJunctionFlag = new IJunctionFlag[listJunctionsFlag.Count];
                for (int i = 0; i < arrayJunctionFlag.Length; i++)
                {
                    arrayJunctionFlag[i] = listJunctionsFlag[i];
                }
                traceFlowsolverGen.PutJunctionOrigins(ref arrayJunctionFlag);
                //为追踪任务分析器设置管线
                IEdgeFlag[] arrayEdgeFlag = new IEdgeFlag[listEdgeFlag.Count];
                for (int i = 0; i < arrayEdgeFlag.Length; i++)
                {
                    traceFlowsolverGen.PutEdgeOrigins(ref arrayEdgeFlag);
                }

                //为管点分析器设置障碍点
                INetElementBarriersGEN netElementBarriersGEN = new NetElementBarriersClass();
                netElementBarriersGEN.Network = m_GeometryNetwork.Network;
                if (JunctionBarrierEIDs.Count > 0)
                {
                    int[] junctionBarrierEIDs = new int[JunctionBarrierEIDs.Count];
                    for (int j = 0; j < junctionBarrierEIDs.Length; j++)
                    {
                        junctionBarrierEIDs[j] = JunctionBarrierEIDs[j];
                    }
                    netElementBarriersGEN.ElementType = esriElementType.esriETJunction;
                    netElementBarriersGEN.SetBarriersByEID(ref junctionBarrierEIDs);
                    netsolver.set_ElementBarriers(esriElementType.esriETJunction, netElementBarriersGEN as INetElementBarriers);
                }
                else  //否则将管点设置为空
                {
                    netsolver.set_ElementBarriers(esriElementType.esriETJunction, null);
                }
                //未管点分析器设置障碍线
                if (EdgeBarrierEIDs.Count > 0)
                {
                    int[] edgeBarrierEIDs = new int[EdgeBarrierEIDs.Count];
                    for (int j = 0; j < EdgeBarrierEIDs.Count; j++)
                    {
                        edgeBarrierEIDs[j] = EdgeBarrierEIDs[j];
                    }
                    netElementBarriersGEN.ElementType = esriElementType.esriETEdge;
                    netElementBarriersGEN.SetBarriersByEID(ref edgeBarrierEIDs);
                    netsolver.set_ElementBarriers(esriElementType.esriETEdge, netElementBarriersGEN as INetElementBarriers);
                }
                else //否则将管线设置为空
                {
                    netsolver.set_ElementBarriers(esriElementType.esriETEdge, null);
                }

                #endregion

                //定义相关变量
                IEnumNetEID junctionEIDs = new EnumNetEIDArrayClass();
                IEnumNetEID edgeEIDs     = new EnumNetEIDArrayClass();

                object[] segmentsCosts = null;
                object   totalCost     = null;
                int      Counts        = -1;
                #region 各种几何网络分析的结果
                switch (this.AnalysisCategoryCmbx.SelectedIndex)
                {
                //查询共同祖先
                case 0:
                    traceFlowsolverGen.FindCommonAncestors(esriFlowElements.esriFEJunctionsAndEdges, out junctionEIDs, out edgeEIDs);
                    break;

                //查找相连接的网络要素
                case 1:
                    traceFlowsolverGen.FindFlowElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctionsAndEdges, out junctionEIDs, out edgeEIDs);
                    break;

                //查找网络中连接的环
                case 2:
                    traceFlowsolverGen.FindCircuits(esriFlowElements.esriFEJunctionsAndEdges, out junctionEIDs, out edgeEIDs);
                    break;

                //查找未连接的网络要素
                case 3:
                    traceFlowsolverGen.FindFlowUnreachedElements(esriFlowMethod.esriFMConnected, esriFlowElements.esriFEJunctionsAndEdges, out junctionEIDs, out edgeEIDs);
                    break;

                //查找上游路径,同时跟踪耗费
                case 4:
                    Counts        = GetSegmentCounts();
                    segmentsCosts = new object[Counts];
                    traceFlowsolverGen.FindSource(esriFlowMethod.esriFMUpstream, esriShortestPathObjFn.esriSPObjFnMinSum, out junctionEIDs, out edgeEIDs, Counts, ref segmentsCosts);
                    break;

                //获取网络路径,追踪网络耗费。count比所有的的标识总数少一个,但如果管点和管线标识同时存在的时候该功能不可用
                case 5:
                    if (listEdgeFlag.Count > 0 && listJunctionsFlag.Count > 0)
                    {
                        break;
                    }
                    else if (listJunctionsFlag.Count > 0)
                    {
                        Counts = listJunctionsFlag.Count - 1;
                    }
                    else if (listEdgeFlag.Count > 0)
                    {
                        Counts = listEdgeFlag.Count - 1;
                    }
                    else
                    {
                        break;
                    }
                    segmentsCosts = new object[Counts];
                    traceFlowsolverGen.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinSum, out junctionEIDs, out edgeEIDs, Counts, ref segmentsCosts);
                    break;

                //下游追踪
                case 6:
                    traceFlowsolverGen.FindFlowElements(esriFlowMethod.esriFMDownstream, esriFlowElements.esriFEJunctionsAndEdges, out junctionEIDs, out edgeEIDs);
                    break;

                //查找上游路径消耗,同时获取网络追踪的耗费
                case 7:
                    totalCost = new object();
                    traceFlowsolverGen.FindAccumulation(esriFlowMethod.esriFMUpstream, esriFlowElements.esriFEJunctionsAndEdges, out junctionEIDs, out edgeEIDs, out totalCost);
                    break;

                //上游追踪
                case 8:
                    Counts        = GetSegmentCounts();
                    segmentsCosts = new object[Counts];
                    traceFlowsolverGen.FindSource(esriFlowMethod.esriFMUpstream, esriShortestPathObjFn.esriSPObjFnMinSum, out junctionEIDs, out edgeEIDs, Counts, ref segmentsCosts);
                    break;

                default:
                    break;
                }

                #endregion

                //绘制结果图像
                DrawTraceRsult(junctionEIDs, edgeEIDs);
                this.Mapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, this.Mapcontrol.ActiveView.Extent);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
コード例 #4
0
        //����׷�ٵĽ��
        public static void FindStreamTraceResult(AxMapControl ppAxMapControl, INetFlag ipNetFlag, IGeometricNetwork pGeoNetwork)
        {
            try
            {

                IEnumNetEID m_ipEnumNetEID_Junctions, m_ipEnumNetEID_Edges;//����������������Junctions��Edges
                IJunctionFlag[] pArrayJFlag = new IJunctionFlag[1];
                pArrayJFlag[0] = ipNetFlag as IJunctionFlag;
                ITraceFlowSolverGEN ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;

                //get the inetsolver interface
                INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver;
                ipNetSolver.SourceNetwork = pGeoNetwork.Network;

                ipTraceFlowSolver.PutJunctionOrigins(ref pArrayJFlag);

                ipTraceFlowSolver.TraceIndeterminateFlow = false;

                object[] totalCost = new object[1];

                //ipTraceFlowSolver.FindSource(esriFlowMethod.esriFMUpstream,esriShortestPathObjFn.esriSPObjFnMinSum,out m_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges,1,ref totalCost);

                ipTraceFlowSolver.FindFlowElements(esriFlowMethod.esriFMUpstream,
                    esriFlowElements.esriFEEdges,
                    out m_ipEnumNetEID_Junctions,
                    out m_ipEnumNetEID_Edges);

                //ma
                //SpatialHelperFunction.pathToPolyline(pGeoNetwork, ppAxMapControl.ActiveView, m_ipEnumNetEID_Edges);
                //UpStreamFindParcels(ppAxMapControl, m_ipEnumNetEID_Edges,pGeoNetwork);
            }
            catch (Exception eX)
            {
                MessageBox.Show(eX.Message);

            }
        }
コード例 #5
0
        public static void ProfileFindPath(AxMapControl ppAxMapControl, IArray pNetFlagArray, IGeometricNetwork pGeoNetwork)
        {
            try
            {

                IEnumNetEID m_ipEnumNetEID_Junctions, m_ipEnumNetEID_Edges;//����������������Junctions��Edges
                IJunctionFlag[] pArrayJFlag = new IJunctionFlag[2];
                pArrayJFlag[0] = pNetFlagArray.get_Element(0) as IJunctionFlag;
                pArrayJFlag[1] = pNetFlagArray.get_Element(1) as IJunctionFlag;
                ITraceFlowSolverGEN ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;

                //get the inetsolver interface
                INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver;
                ipNetSolver.SourceNetwork = pGeoNetwork.Network;

                ipTraceFlowSolver.PutJunctionOrigins(ref pArrayJFlag);

                ipTraceFlowSolver.TraceIndeterminateFlow = false;

                object[] totalCost = new object[1];

                //ipTraceFlowSolver.FindSource(esriFlowMethod.esriFMUpstream,esriShortestPathObjFn.esriSPObjFnMinSum,out m_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges,1,ref totalCost);

                ipTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected,
                    esriShortestPathObjFn.esriSPObjFnMinMax,
                    out m_ipEnumNetEID_Junctions,
                    out m_ipEnumNetEID_Edges, 1, ref totalCost);
                //��������еĽ����Ԫ��
                pNetFlagArray.RemoveAll();
                //ma
                //              SpatialHelperFunction.pathToPolyline(pGeoNetwork, ppAxMapControl.ActiveView, m_ipEnumNetEID_Edges);
                //ProfileGetRelatedSewerElevData(ppAxMapControl,pGeoNetwork,m_ipEnumNetEID_Edges, m_ipEnumNetEID_Junctions  );
            }
            catch (Exception eX)
            {
                MessageBox.Show(eX.Message);

            }
        }
        public ITraceFlowSolverGEN UTIL_coreTraceSetup()
        {
            // get the current network's logical network
            INetworkAnalysisExt nax = m_utilNetExt as INetworkAnalysisExt;
            INetwork            net = nax.CurrentNetwork.Network;

            // create a new TraceFlowSolver object and
            // set the source network for the solve
            ITraceFlowSolverGEN tfs       = new TraceFlowSolverClass() as ITraceFlowSolverGEN;
            INetSolver          netSolver = tfs as INetSolver;

            netSolver.SourceNetwork = net;

            // get the barriers for the network, using the element barriers and
            // selection barriers that have been added using the user interface
            INetworkAnalysisExtBarriers naxBarriers = m_utilNetExt as INetworkAnalysisExtBarriers;
            INetElementBarriers         juncElemBarriers, edgeElemBarriers;

            naxBarriers.CreateElementBarriers(out juncElemBarriers, out edgeElemBarriers);
            ISelectionSetBarriers selSetBarriers;

            naxBarriers.CreateSelectionBarriers(out selSetBarriers);
            netSolver.set_ElementBarriers(esriElementType.esriETJunction, juncElemBarriers);
            netSolver.set_ElementBarriers(esriElementType.esriETEdge, edgeElemBarriers);
            netSolver.SelectionSetBarriers = selSetBarriers;

            // set up the disabled layers for the network solver
            // for each feature layer belonging to this network, determine if it is
            // enabled or disabled; if it's disabled, then notify the network solver
            for (int i = 0; i < nax.FeatureLayerCount; i++)
            {
                IFeatureLayer featureLayer = nax.get_FeatureLayer(i);
                if (naxBarriers.GetDisabledLayer(featureLayer))
                {
                    netSolver.DisableElementClass(featureLayer.FeatureClass.FeatureClassID);
                }
            }

            INetworkAnalysisExtWeightFilter naxWeightFilter  = m_utilNetExt as INetworkAnalysisExtWeightFilter;
            INetSolverWeightsGEN            netSolverWeights = netSolver as INetSolverWeightsGEN;
            INetSchema netSchema = net as INetSchema;

            // create the junction weight filter
            int juncFilterRangeCount = naxWeightFilter.get_FilterRangeCount(esriElementType.esriETJunction);

            if (juncFilterRangeCount > 0)
            {
                INetWeight netWeight = netSchema.get_WeightByName(naxWeightFilter.JunctionWeightFilterName);
                netSolverWeights.JunctionFilterWeight = netWeight;

                esriWeightFilterType juncWeightFilterType;
                bool juncApplyNotOperator;
                naxWeightFilter.GetFilterType(esriElementType.esriETJunction,
                                              out juncWeightFilterType, out juncApplyNotOperator);
                netSolverWeights.SetFilterType(esriElementType.esriETJunction,
                                               juncWeightFilterType, juncApplyNotOperator);

                object[] juncFromValues = new object[juncFilterRangeCount];
                object[] juncToValues   = new object[juncFilterRangeCount];
                for (int i = 0; i < juncFilterRangeCount; i++)
                {
                    naxWeightFilter.GetFilterRange(esriElementType.esriETJunction, i,
                                                   out juncFromValues[i], out juncToValues[i]);
                }
                netSolverWeights.SetFilterRanges(esriElementType.esriETJunction,
                                                 ref juncFromValues, ref juncToValues);
            }

            // create the edge weight filters
            int edgeFilterRangeCount = naxWeightFilter.get_FilterRangeCount(esriElementType.esriETEdge);

            if (edgeFilterRangeCount > 0)
            {
                INetWeight fromToNetWeight = netSchema.get_WeightByName(naxWeightFilter.FromToEdgeWeightFilterName);
                netSolverWeights.FromToEdgeFilterWeight = fromToNetWeight;
                INetWeight toFromNetWeight = netSchema.get_WeightByName(naxWeightFilter.ToFromEdgeWeightFilterName);
                netSolverWeights.ToFromEdgeFilterWeight = toFromNetWeight;

                esriWeightFilterType edgeWeightFilterType;
                bool edgeApplyNotOperator;
                naxWeightFilter.GetFilterType(esriElementType.esriETEdge,
                                              out edgeWeightFilterType, out edgeApplyNotOperator);
                netSolverWeights.SetFilterType(esriElementType.esriETEdge,
                                               edgeWeightFilterType, edgeApplyNotOperator);

                object[] edgeFromValues = new object[edgeFilterRangeCount];
                object[] edgeToValues   = new object[edgeFilterRangeCount];
                for (int i = 0; i < edgeFilterRangeCount; i++)
                {
                    naxWeightFilter.GetFilterRange(esriElementType.esriETEdge, i,
                                                   out edgeFromValues[i], out edgeToValues[i]);
                }
                netSolverWeights.SetFilterRanges(esriElementType.esriETEdge,
                                                 ref edgeFromValues, ref edgeToValues);
            }

            INetworkAnalysisExtFlags naxFlags = m_utilNetExt as INetworkAnalysisExtFlags;

            // assign the edge flags to the network solver
            int edgeFlagCount = naxFlags.EdgeFlagCount;

            if (edgeFlagCount > 0)
            {
                IEdgeFlag[] edgeFlags = new IEdgeFlag[edgeFlagCount];
                for (int i = 0; i < edgeFlagCount; i++)
                {
                    IEdgeFlagDisplay edgeFlagDisplay = naxFlags.get_EdgeFlag(i);
                    IFlagDisplay     flagDisplay     = edgeFlagDisplay as IFlagDisplay;
                    IEdgeFlag        edgeFlag        = new EdgeFlagClass();
                    edgeFlag.Position = Convert.ToSingle(edgeFlagDisplay.Percentage);
                    INetFlag netFlag = edgeFlag as INetFlag;
                    netFlag.UserClassID = flagDisplay.FeatureClassID;
                    netFlag.UserID      = flagDisplay.FID;
                    netFlag.UserSubID   = flagDisplay.SubID;
                    edgeFlags[i]        = edgeFlag;
                }
                tfs.PutEdgeOrigins(ref edgeFlags);
            }

            // assign the junction flags to the network solver
            int juncFlagCount = naxFlags.JunctionFlagCount;

            if (juncFlagCount > 0)
            {
                IJunctionFlag[] juncFlags = new IJunctionFlag[juncFlagCount];
                for (int i = 0; i < juncFlagCount; i++)
                {
                    IJunctionFlagDisplay juncFlagDisplay = naxFlags.get_JunctionFlag(i);
                    IFlagDisplay         flagDisplay     = juncFlagDisplay as IFlagDisplay;
                    IJunctionFlag        juncFlag        = new JunctionFlagClass();
                    INetFlag             netFlag         = juncFlag as INetFlag;
                    netFlag.UserClassID = flagDisplay.FeatureClassID;
                    netFlag.UserID      = flagDisplay.FID;
                    netFlag.UserSubID   = flagDisplay.SubID;
                    juncFlags[i]        = juncFlag;
                }
                tfs.PutJunctionOrigins(ref juncFlags);
            }

            // set the option for tracing on indeterminate flow
            ITraceTasks traceTasks = m_utilNetExt as ITraceTasks;

            tfs.TraceIndeterminateFlow = traceTasks.TraceIndeterminateFlow;

            return(tfs);
        }
		public ITraceFlowSolverGEN UTIL_coreTraceSetup()
		{
			// get the current network's logical network
			INetworkAnalysisExt nax = m_utilNetExt as INetworkAnalysisExt;
			INetwork net = nax.CurrentNetwork.Network;

			// create a new TraceFlowSolver object and
			// set the source network for the solve
			ITraceFlowSolverGEN tfs = new TraceFlowSolverClass() as ITraceFlowSolverGEN;
			INetSolver netSolver = tfs as INetSolver;
			netSolver.SourceNetwork = net;

			// get the barriers for the network, using the element barriers and 
			// selection barriers that have been added using the user interface
			INetworkAnalysisExtBarriers naxBarriers = m_utilNetExt as INetworkAnalysisExtBarriers;
			INetElementBarriers juncElemBarriers, edgeElemBarriers;
			naxBarriers.CreateElementBarriers(out juncElemBarriers, out edgeElemBarriers);
			ISelectionSetBarriers selSetBarriers;
			naxBarriers.CreateSelectionBarriers(out selSetBarriers);
			netSolver.set_ElementBarriers(esriElementType.esriETJunction, juncElemBarriers);
			netSolver.set_ElementBarriers(esriElementType.esriETEdge, edgeElemBarriers);
			netSolver.SelectionSetBarriers = selSetBarriers;

			// set up the disabled layers for the network solver
			// for each feature layer belonging to this network, determine if it is
			// enabled or disabled; if it's disabled, then notify the network solver
			for (int i = 0; i < nax.FeatureLayerCount; i++)
			{
				IFeatureLayer featureLayer = nax.get_FeatureLayer(i);
				if (naxBarriers.GetDisabledLayer(featureLayer))
					netSolver.DisableElementClass(featureLayer.FeatureClass.FeatureClassID);
			}

			INetworkAnalysisExtWeightFilter naxWeightFilter = m_utilNetExt as INetworkAnalysisExtWeightFilter;
			INetSolverWeightsGEN netSolverWeights = netSolver as INetSolverWeightsGEN;
			INetSchema netSchema = net as INetSchema;
			
			// create the junction weight filter
			int juncFilterRangeCount = naxWeightFilter.get_FilterRangeCount(esriElementType.esriETJunction);
			if (juncFilterRangeCount > 0)
			{
				INetWeight netWeight = netSchema.get_WeightByName(naxWeightFilter.JunctionWeightFilterName);
				netSolverWeights.JunctionFilterWeight = netWeight;

				esriWeightFilterType juncWeightFilterType;
				bool juncApplyNotOperator;
				naxWeightFilter.GetFilterType(esriElementType.esriETJunction,
					out juncWeightFilterType, out juncApplyNotOperator);
				netSolverWeights.SetFilterType(esriElementType.esriETJunction,
					juncWeightFilterType, juncApplyNotOperator);

				object[] juncFromValues = new object[juncFilterRangeCount];
				object[] juncToValues = new object[juncFilterRangeCount];
				for (int i = 0; i < juncFilterRangeCount; i++)
				{
					naxWeightFilter.GetFilterRange(esriElementType.esriETJunction, i,
						out juncFromValues[i], out juncToValues[i]);
				}
				netSolverWeights.SetFilterRanges(esriElementType.esriETJunction,
					ref juncFromValues, ref juncToValues);
			}

			// create the edge weight filters
			int edgeFilterRangeCount = naxWeightFilter.get_FilterRangeCount(esriElementType.esriETEdge);
			if (edgeFilterRangeCount > 0)
			{
				INetWeight fromToNetWeight = netSchema.get_WeightByName(naxWeightFilter.FromToEdgeWeightFilterName);
				netSolverWeights.FromToEdgeFilterWeight = fromToNetWeight;
				INetWeight toFromNetWeight = netSchema.get_WeightByName(naxWeightFilter.ToFromEdgeWeightFilterName);
				netSolverWeights.ToFromEdgeFilterWeight = toFromNetWeight;

				esriWeightFilterType edgeWeightFilterType;
				bool edgeApplyNotOperator;
				naxWeightFilter.GetFilterType(esriElementType.esriETEdge,
					out edgeWeightFilterType, out edgeApplyNotOperator);
				netSolverWeights.SetFilterType(esriElementType.esriETEdge,
					edgeWeightFilterType, edgeApplyNotOperator);

				object[] edgeFromValues = new object[edgeFilterRangeCount];
				object[] edgeToValues = new object[edgeFilterRangeCount];
				for (int i = 0; i < edgeFilterRangeCount; i++)
				{
					naxWeightFilter.GetFilterRange(esriElementType.esriETEdge, i,
						out edgeFromValues[i], out edgeToValues[i]);
				}
				netSolverWeights.SetFilterRanges(esriElementType.esriETEdge,
					ref edgeFromValues, ref edgeToValues);
			}

			INetworkAnalysisExtFlags naxFlags = m_utilNetExt as INetworkAnalysisExtFlags;

			// assign the edge flags to the network solver
			int edgeFlagCount = naxFlags.EdgeFlagCount;
			if (edgeFlagCount > 0)
			{
				IEdgeFlag[] edgeFlags = new IEdgeFlag[edgeFlagCount];
				for (int i = 0; i < edgeFlagCount; i++)
				{
					IEdgeFlagDisplay edgeFlagDisplay = naxFlags.get_EdgeFlag(i);
					IFlagDisplay flagDisplay = edgeFlagDisplay as IFlagDisplay;
					IEdgeFlag edgeFlag = new EdgeFlagClass();
					edgeFlag.Position = Convert.ToSingle(edgeFlagDisplay.Percentage);
					INetFlag netFlag = edgeFlag as INetFlag;
					netFlag.UserClassID = flagDisplay.FeatureClassID;
					netFlag.UserID = flagDisplay.FID;
					netFlag.UserSubID = flagDisplay.SubID;
					edgeFlags[i] = edgeFlag;
				}
				tfs.PutEdgeOrigins(ref edgeFlags);
			}

			// assign the junction flags to the network solver
			int juncFlagCount = naxFlags.JunctionFlagCount;
			if (juncFlagCount > 0)
			{
				IJunctionFlag[] juncFlags = new IJunctionFlag[juncFlagCount];
				for (int i = 0; i < juncFlagCount; i++)
				{
					IJunctionFlagDisplay juncFlagDisplay = naxFlags.get_JunctionFlag(i);
					IFlagDisplay flagDisplay = juncFlagDisplay as IFlagDisplay;
					IJunctionFlag juncFlag = new JunctionFlagClass();
					INetFlag netFlag = juncFlag as INetFlag;
					netFlag.UserClassID = flagDisplay.FeatureClassID;
					netFlag.UserID = flagDisplay.FID;
					netFlag.UserSubID = flagDisplay.SubID;
					juncFlags[i] = juncFlag;
				}
				tfs.PutJunctionOrigins(ref juncFlags);
			}

			// set the option for tracing on indeterminate flow
			ITraceTasks traceTasks = m_utilNetExt as ITraceTasks;
			tfs.TraceIndeterminateFlow = traceTasks.TraceIndeterminateFlow;

			return tfs;
		}
コード例 #8
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);
            }
        }
コード例 #9
0
ファイル: NetworkAnalyst.cs プロジェクト: secondii/Yutai
        private static ITraceFlowSolver CreateTraceFlowSolver()
        {
            int              num;
            INetFlag         netFlag;
            ITraceFlowSolver solver  = (ITraceFlowSolver) new TraceFlowSolverClass();
            INetSolver       solver2 = (INetSolver)solver;
            INetwork         network = m_pAnalystGN.Network;

            solver2.SourceNetwork = network;
            INetElements elements = (INetElements)network;

            if (m_JunFlags.Count > 0)
            {
                IJunctionFlag[] junctionOrigins = new IJunctionFlag[m_JunFlags.Count];
                for (num = 0; num < m_JunFlags.Count; num++)
                {
                    netFlag = (m_JunFlags[num] as NetFlagWrap).NetFlag;
                    junctionOrigins[num] = (IJunctionFlag)netFlag;
                }
                (solver as ITraceFlowSolverGEN).PutJunctionOrigins(ref junctionOrigins);
            }
            if (m_EdgeFlags.Count > 0)
            {
                IEdgeFlag[] edgeOrigins = new IEdgeFlag[m_EdgeFlags.Count];
                for (num = 0; num < m_EdgeFlags.Count; num++)
                {
                    netFlag          = (m_EdgeFlags[num] as NetFlagWrap).NetFlag;
                    edgeOrigins[num] = (IEdgeFlag)netFlag;
                }
                (solver as ITraceFlowSolverGEN).PutEdgeOrigins(ref edgeOrigins);
            }
            INetSolverWeightsGEN sgen = (INetSolverWeightsGEN)solver;

            if (JunctionWeight != null)
            {
                sgen.JunctionWeight = JunctionWeight;
            }
            if (FromToEdgeWeight != null)
            {
                sgen.JunctionWeight = FromToEdgeWeight;
            }
            if (ToFromEdgeWeight != null)
            {
                sgen.JunctionWeight = ToFromEdgeWeight;
            }
            if (JunctionFilterWeight != null)
            {
                sgen.JunctionFilterWeight = JunctionFilterWeight;
            }
            if (FromToEdgeFilterWeight != null)
            {
                sgen.FromToEdgeFilterWeight = FromToEdgeFilterWeight;
            }
            if (ToFromEdgeFilterWeight != null)
            {
                sgen.ToFromEdgeFilterWeight = ToFromEdgeFilterWeight;
            }
            if (JuncfromValues != null)
            {
                sgen.SetFilterRanges(esriElementType.esriETJunction, ref JuncfromValues, ref JunctoValues);
                sgen.SetFilterType(esriElementType.esriETJunction, esriWeightFilterType.esriWFRange,
                                   ApplyJuncFilterWeight);
            }
            else
            {
                sgen.SetFilterType(esriElementType.esriETJunction, esriWeightFilterType.esriWFNone,
                                   ApplyJuncFilterWeight);
            }
            if (EdgefromValues != null)
            {
                sgen.SetFilterRanges(esriElementType.esriETEdge, ref EdgefromValues, ref EdgetoValues);
                sgen.SetFilterType(esriElementType.esriETEdge, esriWeightFilterType.esriWFRange, ApplyJuncFilterWeight);
            }
            else
            {
                sgen.SetFilterType(esriElementType.esriETEdge, esriWeightFilterType.esriWFNone, ApplyEdgeFilterWeight);
            }
            INetElementBarriers netElementBarriers = GetNetElementBarriers(esriElementType.esriETJunction);

            if (netElementBarriers != null)
            {
                (solver as INetSolver).set_ElementBarriers(esriElementType.esriETJunction, netElementBarriers);
            }
            netElementBarriers = GetNetElementBarriers(esriElementType.esriETEdge);
            if (netElementBarriers != null)
            {
                (solver as INetSolver).set_ElementBarriers(esriElementType.esriETEdge, netElementBarriers);
            }
            return(solver);
        }
コード例 #10
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);
                    }
                }
            }
        }
コード例 #11
0
        private void setUpstreamJunctionFlag(IPoint pPoint)
        {
            try
            {
                if (pGeometricNetwork == null)
                {
                    openGeoNetwork();
                }

                IEnumNetEID m_ipEnumNetEID_Junctions, m_ipEnumNetEID_Edges;               //用来存放搜索结果的Junctions和Edges

                ipNetwork = pGeometricNetwork.Network;

                /*
                 * IMarkerSymbol pMarkerSym=SpatialHelperFunction.FindMarkerSym("Civic.ServerStyle", "Default", "Pin Flag Square");
                 * if(pMarkerSym==null){
                 *      MessageBox.Show("无法取得Symbol");
                 *      return;
                 * }
                 *
                 * IRgbColor pRGBColor=Utility.getRGBColor(255, 0, 0);
                 *
                 * pMarkerSym.Color=pRGBColor;
                 * pMarkerSym.Size=26;
                 * pMarkerSym.XOffset=10;
                 * pMarkerSym.YOffset=10;
                 * //无法使用 IFlagDisplay,只有 INetworkAnalysisExtFlags才可以使用IFlagDisplay
                 *
                 * Utility.drawPointToGraphicLayer(m_HookHelper.ActiveView,pPoint,pMarkerSym);
                 */


                int          pJunctionID;
                IPoint       pLocation;
                int          iUserClassID, iUserID, iUserSubID;
                INetElements ipNetElements;

                ipNetElements = ipNetwork as INetElements;                 //得到network中所有的Elements

                mPointToEID = new PointToEIDClass();

                //设置它的GeometricNetwork
                mPointToEID.GeometricNetwork = pGeometricNetwork;

                //设置容限值
                mPointToEID.SnapTolerance = m_HookHelper.ActiveView.Extent.Envelope.Width / 100;

                //设置Source Map
                mPointToEID.SourceMap = m_HookHelper.ActiveView.FocusMap;

                //得到最近的JunctionID
                mPointToEID.GetNearestJunction(pPoint, out pJunctionID, out pLocation);

                //Each element in a logical network has a unique element ID (EID).
                ipNetElements.QueryIDs(pJunctionID, esriElementType.esriETJunction, out iUserClassID, out iUserID, out iUserSubID);

                //得到所在Junction的ID

                //无法使用 IFlagDisplay,只有 INetworkAnalysisExtFlags才可以使用IFlagDisplay

                INetFlag ipNetFlag = new JunctionFlagClass();

                ipNetFlag.UserClassID = iUserClassID;

                ipNetFlag.UserID = iUserID;

                ipNetFlag.UserSubID = iUserSubID;



                IJunctionFlag [] pArrayJFlag = new IJunctionFlag[1];

                pArrayJFlag[0] = ipNetFlag as IJunctionFlag;

                ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;

                //get the inetsolver interface
                ipNetSolver = ipTraceFlowSolver as INetSolver;

                ipNetSolver.SourceNetwork = pGeometricNetwork.Network;



                ipTraceFlowSolver.PutJunctionOrigins(ref pArrayJFlag);

                ipTraceFlowSolver.TraceIndeterminateFlow = false;

                object[] totalCost = new object[1];


                //ipTraceFlowSolver.FindSource(esriFlowMethod.esriFMUpstream,esriShortestPathObjFn.esriSPObjFnMinSum,out m_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges,1,ref totalCost);

                ipTraceFlowSolver.FindFlowElements(esriFlowMethod.esriFMUpstream,
                                                   esriFlowElements.esriFEEdges,
                                                   out m_ipEnumNetEID_Junctions,
                                                   out m_ipEnumNetEID_Edges);


                SpatialHelperFunction.pathToPolyline(pGeometricNetwork, m_HookHelper.ActiveView, m_ipEnumNetEID_Edges);



                //ipTraceFlowSolver.FindFlowEndElements(esriFlowMethod.esriFMUpstream,esriFlowElements.esriFEJunctionsAndEdges,out m_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges);

                m_HookHelper.ActiveView.Refresh();
            }
            catch (Exception e) {
                MessageBox.Show(e.Message);
            }
        }
コード例 #12
0
ファイル: UpStreamTrace.cs プロジェクト: chinasio/Control
        private void setUpstreamJunctionFlag(IPoint pPoint)
        {
            try
            {

                if(pGeometricNetwork==null){
                    openGeoNetwork();

                }

                IEnumNetEID m_ipEnumNetEID_Junctions,m_ipEnumNetEID_Edges;//����������������Junctions��Edges

                ipNetwork=pGeometricNetwork.Network;

                /*
                IMarkerSymbol pMarkerSym=SpatialHelperFunction.FindMarkerSym("Civic.ServerStyle", "Default", "Pin Flag Square");
                if(pMarkerSym==null){
                    MessageBox.Show("�޷�ȡ��Symbol");
                    return;
                }

                IRgbColor pRGBColor=Utility.getRGBColor(255, 0, 0);

                pMarkerSym.Color=pRGBColor;
                pMarkerSym.Size=26;
                pMarkerSym.XOffset=10;
                pMarkerSym.YOffset=10;
                //�޷�ʹ�� IFlagDisplay��ֻ�� INetworkAnalysisExtFlags�ſ���ʹ��IFlagDisplay

                Utility.drawPointToGraphicLayer(m_HookHelper.ActiveView,pPoint,pMarkerSym);
                */

                int pJunctionID;
                IPoint pLocation;
                int iUserClassID,iUserID,iUserSubID;
                INetElements ipNetElements;

                ipNetElements = ipNetwork as INetElements; //�õ�network�����е�Elements

                mPointToEID=new PointToEIDClass();

                //��������GeometricNetwork
                mPointToEID.GeometricNetwork=pGeometricNetwork;

                //��������ֵ
                mPointToEID.SnapTolerance=m_HookHelper.ActiveView.Extent.Envelope.Width/100;

                //����Source Map
                mPointToEID.SourceMap=m_HookHelper.ActiveView.FocusMap;

                //�õ������JunctionID
                mPointToEID.GetNearestJunction(pPoint,out pJunctionID,out pLocation);

                //Each element in a logical network has a unique element ID (EID).
                ipNetElements.QueryIDs(pJunctionID,esriElementType.esriETJunction,out iUserClassID,out iUserID,out iUserSubID);

                //�õ�����Junction��ID

                //�޷�ʹ�� IFlagDisplay��ֻ�� INetworkAnalysisExtFlags�ſ���ʹ��IFlagDisplay

                INetFlag ipNetFlag=new JunctionFlagClass();

                ipNetFlag.UserClassID=iUserClassID;

                ipNetFlag.UserID=iUserID;

                ipNetFlag.UserSubID=iUserSubID;

                IJunctionFlag [] pArrayJFlag=new IJunctionFlag[1];

                pArrayJFlag[0]=ipNetFlag as IJunctionFlag;

                ipTraceFlowSolver=new TraceFlowSolverClass() as ITraceFlowSolverGEN;

                //get the inetsolver interface
                ipNetSolver=ipTraceFlowSolver as INetSolver;

                ipNetSolver.SourceNetwork=pGeometricNetwork.Network;

                ipTraceFlowSolver.PutJunctionOrigins(ref pArrayJFlag);

                ipTraceFlowSolver.TraceIndeterminateFlow=false;

                object[] totalCost=new object[1];

                //ipTraceFlowSolver.FindSource(esriFlowMethod.esriFMUpstream,esriShortestPathObjFn.esriSPObjFnMinSum,out m_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges,1,ref totalCost);

                ipTraceFlowSolver.FindFlowElements(esriFlowMethod.esriFMUpstream,
                    esriFlowElements.esriFEEdges,
                    out m_ipEnumNetEID_Junctions,
                    out m_ipEnumNetEID_Edges);

                SpatialHelperFunction.pathToPolyline(pGeometricNetwork,m_HookHelper.ActiveView,m_ipEnumNetEID_Edges);

                //ipTraceFlowSolver.FindFlowEndElements(esriFlowMethod.esriFMUpstream,esriFlowElements.esriFEJunctionsAndEdges,out m_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges);

                m_HookHelper.ActiveView.Refresh();
            }
            catch(Exception e){
                MessageBox.Show(e.Message);

            }
        }
コード例 #13
0
        /// <summary>
        /// operation solve trace
        /// </summary>
        /// <returns>solve trace</returns>
        public override JsonObject Solve()
        {
            try
            {
                if ((this.edgeFlags.Length == 0) && (this.junctionFlags.Length == 0))
                {
                    string message = "No input valid flags found";
                    if (this.flagNotFound.Count == 0)
                    {
                        throw new GeometricNetworkException(message);
                    }
                    else
                    {
                        JsonObject error = (new ObjectError(message)).ToJsonObject();
                        error.AddArray("flagsNotFound", Helper.GetListJsonObjects(this.flagNotFound));
                        if (this.barrierNotFound.Count > 0)
                        {
                            error.AddArray("barriersNotFound", Helper.GetListJsonObjects(this.barrierNotFound));
                        }

                        return(error);
                    }
                }

                ITraceFlowSolverGEN traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;
                INetSolver          netSolver       = traceFlowSolver as INetSolver;
                INetwork            network         = this.geometricNetwork.Network;
                netSolver.SourceNetwork = network;

                // flag origin
                this.SetFlagsOrigin(ref traceFlowSolver);

                // barrier
                this.SetBarriers(ref traceFlowSolver);

                // set disabled layers
                foreach (int i in this.DisableLayers)
                {
                    netSolver.DisableElementClass(i);
                }

                // set weight
                this.SetWeights(ref traceFlowSolver);

                if ((this.TraceSolverType != TraceSolverType.FindCircuits) && (this.TraceSolverType != TraceSolverType.FindCommonAncestors))
                {
                    // The TraceIndeterminateFlow property affects the trace results of trace solvers whose FlowMethod parameter is esriFMUpstream or esriFMDownstream
                    if ((this.FlowMethod == esriFlowMethod.esriFMDownstream) || (this.FlowMethod == esriFlowMethod.esriFMUpstream))
                    {
                        traceFlowSolver.TraceIndeterminateFlow = this.TraceIndeterminateFlow;
                    }
                }

                IEnumNetEID junctionEIDs = null;
                IEnumNetEID edgeEIDs     = null;
                object      totalCost;
                int         count;
                object[]    segmentCosts;

                JsonObject objectJson = new JsonObject();
                switch (this.TraceSolverType)
                {
                case TraceSolverType.FindAccumulation:
                    traceFlowSolver.FindAccumulation(this.FlowMethod, this.FlowElements, out junctionEIDs, out edgeEIDs, out totalCost);
                    objectJson.AddDouble("totalCost", (double)totalCost);
                    break;

                case TraceSolverType.FindCircuits:
                    traceFlowSolver.FindCircuits(this.FlowElements, out junctionEIDs, out edgeEIDs);
                    break;

                case TraceSolverType.FindCommonAncestors:
                    traceFlowSolver.FindCommonAncestors(this.FlowElements, out junctionEIDs, out edgeEIDs);
                    break;

                case TraceSolverType.FindFlowElements:
                    traceFlowSolver.FindFlowElements(this.FlowMethod, this.FlowElements, out junctionEIDs, out edgeEIDs);
                    break;

                case TraceSolverType.FindFlowEndElements:
                    traceFlowSolver.FindFlowEndElements(this.FlowMethod, this.FlowElements, out junctionEIDs, out edgeEIDs);
                    break;

                case TraceSolverType.FindFlowUnreachedElements:
                    traceFlowSolver.FindFlowUnreachedElements(this.FlowMethod, this.FlowElements, out junctionEIDs, out edgeEIDs);
                    break;

                case TraceSolverType.FindPath:
                    count = Math.Max(this.junctionFlags.Length, this.edgeFlags.Length);
                    if (count < 2)
                    {
                        throw new GeometricNetworkException("Edge or junction found < 2!");
                    }

                    --count;
                    segmentCosts = new object[count];
                    traceFlowSolver.FindPath(this.FlowMethod, this.ShortestPathObjFn, out junctionEIDs, out edgeEIDs, count, ref segmentCosts);
                    objectJson.AddArray("segmentCosts", segmentCosts);
                    break;

                case TraceSolverType.FindSource:
                    count        = this.junctionFlags.Length + this.edgeFlags.Length;
                    segmentCosts = new object[count];
                    traceFlowSolver.FindSource(this.FlowMethod, this.ShortestPathObjFn, out junctionEIDs, out edgeEIDs, count, ref segmentCosts);
                    objectJson.AddArray("segmentCosts", segmentCosts);
                    break;

                case TraceSolverType.FindLongest:
                    // get end junctions in upstream
                    IEnumNetEID junctionEIDsFindLongest = null;
                    IEnumNetEID edgeEIDsFindLongest     = null;
                    traceFlowSolver.FindFlowEndElements(esriFlowMethod.esriFMUpstream, esriFlowElements.esriFEJunctions, out junctionEIDsFindLongest, out edgeEIDsFindLongest);

                    int?   eidLongest       = null;
                    double eidLongestLenght = double.MinValue;

                    if (junctionEIDsFindLongest.Count > 0)
                    {
                        double eidLongestLenghtCurrent = double.NaN;
                        for (int i = 0; i < junctionEIDsFindLongest.Count; i++)
                        {
                            int         netEIDCurrent       = junctionEIDsFindLongest.Next();
                            object[]    segmentLenghts      = new object[1];
                            IEnumNetEID junctionEIDsLongest = null;
                            IEnumNetEID edgeEIDsLongest     = null;

                            INetFlag     netFlag = new JunctionFlagClass();
                            INetElements netElements = this.geometricNetwork.Network as INetElements;
                            int          featureClassID, featureID, subID;
                            netElements.QueryIDs(netEIDCurrent, esriElementType.esriETJunction, out featureClassID, out featureID, out subID);

                            netFlag.UserClassID = featureClassID;
                            netFlag.UserID      = featureID;
                            netFlag.UserSubID   = subID;

                            IJunctionFlag[] junctionFlags = new IJunctionFlag[] { this.junctionFlags[0], netFlag as IJunctionFlag };
                            traceFlowSolver.PutJunctionOrigins(ref junctionFlags);

                            traceFlowSolver.FindPath(esriFlowMethod.esriFMUpstream, esriShortestPathObjFn.esriSPObjFnMinMax, out junctionEIDsLongest, out edgeEIDsLongest, 1, ref segmentLenghts);
                            if (segmentLenghts[0] != null)
                            {
                                eidLongestLenghtCurrent = Convert.ToDouble(segmentLenghts[0]);
                                if (eidLongestLenghtCurrent > eidLongestLenght)
                                {
                                    eidLongestLenght = eidLongestLenghtCurrent;
                                    eidLongest       = netEIDCurrent;
                                    edgeEIDs         = edgeEIDsLongest;
                                    junctionEIDs     = junctionEIDsLongest;
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new GeometricNetworkException("Junction end not found!");
                    }

                    if (eidLongest.HasValue)
                    {
                        objectJson.AddDouble("totalCost", eidLongestLenght);
                    }
                    else
                    {
                        throw new GeometricNetworkException("EID longest not found!");
                    }

                    break;

                default:
                    throw new GeometricNetworkException("Trace solver type not found");
                }

                this.SetResults(ref objectJson, edgeEIDs, junctionEIDs);
                objectJson.AddArray("flagsNotFound", Helper.GetListJsonObjects(this.flagNotFound));
                objectJson.AddArray("barriersNotFound", Helper.GetListJsonObjects(this.barrierNotFound));
                return(objectJson);
            }
            catch (Exception e)
            {
                return((new ObjectError(e.Message)).ToJsonObject());
            }
        }