/// <summary>
        /// 设置边线权重
        /// </summary>
        /// <param name="weightName"></param>
        /// <param name="pTraceFlowGen"></param>
        /// <param name="pNetwork"></param>
        private static void SetWeight(string weightName, ITraceFlowSolverGEN pTraceFlowGen, INetwork pNetwork)
        {
            INetSchema pNetSchema = pNetwork as INetSchema;
            //根据名字获取权重
            INetWeight           pNetWeight          = pNetSchema.get_WeightByName(weightName);
            INetSolverWeightsGEN pNetSolverWeightGen = pTraceFlowGen as INetSolverWeightsGEN;

            //开始边线权重
            pNetSolverWeightGen.FromToEdgeWeight = pNetWeight;
            //终止边线权重
            pNetSolverWeightGen.ToFromEdgeWeight = pNetWeight;
        }
        /// <summary>
        /// set weights in traceFlowSolver
        /// </summary>
        /// <param name="traceFlowSolver">object traceFlowSolver</param>
        private void SetWeights(ref ITraceFlowSolverGEN traceFlowSolver)
        {
            INetSolverWeightsGEN netSolverWeights = traceFlowSolver as INetSolverWeightsGEN;

            // Junction Weight
            if (this.JunctionWeight != null)
            {
                netSolverWeights.JunctionWeight = this.JunctionWeight;
            }

            // FromTo Edge Weight
            if (this.FromToEdgeWeight != null)
            {
                netSolverWeights.FromToEdgeWeight = this.FromToEdgeWeight;
            }

            // ToFrom Edge Weight
            if (this.ToFromEdgeWeight != null)
            {
                netSolverWeights.ToFromEdgeWeight = this.ToFromEdgeWeight;
            }

            // Junction Filter Weight
            if (this.JunctionFilterWeight != null)
            {
                netSolverWeights.JunctionFilterWeight = this.JunctionFilterWeight;
                netSolverWeights.SetFilterType(esriElementType.esriETJunction, esriWeightFilterType.esriWFRange, this.JunctionFilterNotOperator);
                object[] junctionFilterRangesFrom = this.JunctionFilterRangesFrom.ToArray();
                object[] junctionFilterRangesTo   = this.JunctionFilterRangesTo.ToArray();
                netSolverWeights.SetFilterRanges(esriElementType.esriETJunction, ref junctionFilterRangesFrom, ref junctionFilterRangesTo);
            }

            // FromTo ToFrom Edge Filter Weight
            if ((this.FromToEdgeFilterWeight != null) && (this.ToFromEdgeFilterWeight != null))
            {
                netSolverWeights.FromToEdgeFilterWeight = this.FromToEdgeFilterWeight;
                netSolverWeights.ToFromEdgeFilterWeight = this.ToFromEdgeFilterWeight;
                netSolverWeights.SetFilterType(esriElementType.esriETEdge, esriWeightFilterType.esriWFRange, this.EdgeFilterNotOperator);
                object[] edgeFilterRangesFrom = this.EdgeFilterRangesFrom.ToArray();
                object[] edgeFilterRangesTo   = this.EdgeFilterRangesTo.ToArray();
                netSolverWeights.SetFilterRanges(esriElementType.esriETEdge, ref edgeFilterRangesFrom, ref edgeFilterRangesTo);
            }
        }
        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);
        }
예제 #4
0
        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);
        }