Example #1
0
        public static INALayer CreateRouteAnalysisLayer(string layerName, INetworkDataset networkDataset,
                                                        INARouteSolver naRouteSolver)
        {
            INASolverSettings settings    = naRouteSolver as INASolverSettings;
            INASolver         solver      = naRouteSolver as INASolver;
            IDatasetComponent component   = networkDataset as IDatasetComponent;
            IDENetworkDataset dataElement = component.DataElement as IDENetworkDataset;
            INAContext        context     = solver.CreateContext(dataElement, layerName);

            (context as INAContextEdit).Bind(networkDataset, new GPMessagesClass());
            INALayer layer = solver.CreateLayer(context);

            (layer as ILayer).Name          = layerName;
            naRouteSolver.FindBestSequence  = true;
            naRouteSolver.PreserveFirstStop = true;
            naRouteSolver.PreserveLastStop  = false;
            naRouteSolver.UseTimeWindows    = false;
            naRouteSolver.OutputLines       = esriNAOutputLineType.esriNAOutputLineTrueShapeWithMeasure;
            IStringArray restrictionAttributeNames = settings.RestrictionAttributeNames;

            restrictionAttributeNames.Add("Oneway");
            settings.RestrictionAttributeNames = restrictionAttributeNames;
            solver.UpdateContext(context, dataElement, new GPMessagesClass());
            return(layer);
        }
 /// <summary>
 /// 设置解决器 暂时没有使用到
 /// 有问题待修正
 /// </summary>
 /// <param name="pNAContext"></param>
 private static void SetSolverSettings(INAContext pNAContext)
 {
     if (pNAContext.Solver.CanAccumulateAttributes)
     {
         INASolver      naSolver      = pNAContext.Solver;
         INARouteSolver naRouteSolver = naSolver as INARouteSolver;
         naRouteSolver.FindBestSequence  = true;
         naRouteSolver.PreserveFirstStop = true;
         naRouteSolver.PreserveLastStop  = false;
         naRouteSolver.UseTimeWindows    = false;
         naRouteSolver.OutputLines       = esriNAOutputLineType.esriNAOutputLineTrueShapeWithMeasure;
         INASolverSettings2 naSolverSettings = naSolver as INASolverSettings2;
         IStringArray       restrictions     = naSolverSettings.RestrictionAttributeNames;
         restrictions.Add("Oneway");
         naSolverSettings.RestrictionAttributeNames = restrictions;
         //基于上述设置更新Solver
         naSolver.UpdateContext(pNAContext, GetDENetworkDataset(pNAContext.NetworkDataset), new GPMessagesClass());
     }
 }
Example #3
0
		//the rest of the class if for the best route

		/*
		 * '*********************************************************************************
			  ' Set Route Solver Settings
		   '*********************************************************************************
		 * */

		public void SetSolverSettings(ref INAContext pContext , string sImpedanceName,bool bOneWay ,bool bUseHierarchy)
		{
			
			INASolver pSolver;
            
			pSolver = pContext.Solver;
             
			INARouteSolver pRteSolver=pSolver as INARouteSolver;

			pRteSolver.OutputLines =esriNAOutputLineType.esriNAOutputLineTrueShapeWithMeasure;
			pRteSolver.CreateTraversalResult = true;
			pRteSolver.UseTimeWindows = false;
			pRteSolver.FindBestSequence = false;
			pRteSolver.PreserveFirstStop = false;
			pRteSolver.PreserveLastStop = false;


			//Set generic Solver settings
			// set the impedance attribute
			INASolverSettings pSolverSettings=pSolver as INASolverSettings;
            
			pSolverSettings.ImpedanceAttributeName = sImpedanceName;

			// Set the OneWay Restriction if necessary

			IStringArray restrictions;
			restrictions = pSolverSettings.RestrictionAttributeNames;
			restrictions.RemoveAll();
			if(bOneWay==true)
				restrictions.Add("oneway");
			pSolverSettings.RestrictionAttributeNames=restrictions;

			/*
			 *  'Restrict UTurns
			 * */
			pSolverSettings.RestrictUTurns =esriNetworkForwardStarBacktrack.esriNFSBNoBacktrack;

			//IgnoreInvalidLocations allows the network analyst solvers to ignore locations that have not snapped to a network edge
			pSolverSettings.IgnoreInvalidLocations=true;


			if(bUseHierarchy==true)
			{
				
				pSolverSettings.UseHierarchy=true;
				pSolverSettings.HierarchyAttributeName = "hierarchy";
				pSolverSettings.HierarchyLevelCount = 3;
                
				pSolverSettings.set_MaxValueForHierarchy(1,1);
				pSolverSettings.set_NumTransitionToHierarchy(1,9);

				pSolverSettings.set_MaxValueForHierarchy(2,2);
				pSolverSettings.set_NumTransitionToHierarchy(2,9);


			
			} 
			else
				pSolverSettings.UseHierarchy=false;


			// Do not forget to update the context after you set your impedance
			pSolver.UpdateContext(pContext, GetDENetworkDataset(pContext.NetworkDataset),new GPMessagesClass());

    
				   
		}