/// <summary>

        /// Solves this instance.

        /// </summary>

        /// <returns>IFeatureClass.</returns>

        public IFeatureClass Solve()

        {

            log.WriteLog("Solving...");

            IGPMessages gpMessages = new GPMessagesClass();

            try

            {

                ConfigureSolverSettings();

                m_NAContext.Solver.Solve(m_NAContext, gpMessages, null);

                return m_NAContext.NAClasses.get_ItemByName("SALines") as IFeatureClass;

            }

            catch (Exception e)

            {

                log.WriteLog("GP执行失败:" + e.Message);

                return null;

            }

            finally

            {

                ////记录GPMessages

                string sGPMessages = GetGPMessagesAsString(gpMessages);

                log.WriteLog("GP执行信息:" + sGPMessages);

                log.WriteLog("Solve完成!");

            }

        }

/// <summary>

        /// Prepare the solver

        /// </summary>

        private void ConfigureSolverSettings()

        {

            ConfigureSettingsSpecificToServiceAreaSolver();

            ConfigureGenericSolverSettings();

            UpdateContextAfterChangingSettings();

        }

        /// <summary>

        /// Update settings that only apply to the Service Area

        /// </summary>

        private void ConfigureSettingsSpecificToServiceAreaSolver()

        {

            INAServiceAreaSolver naSASolver = m_NAContext.Solver as INAServiceAreaSolver;

            naSASolver.DefaultBreaks = ParseBreaks("");

            naSASolver.MergeSimilarPolygonRanges = false;

            naSASolver.OutputPolygons = esriNAOutputPolygonType.esriNAOutputPolygonNone;

            naSASolver.OverlapLines = false;

            naSASolver.SplitLinesAtBreaks = true;

            naSASolver.TravelDirection = esriNATravelDirection.esriNATravelDirectionFromFacility;

            naSASolver.OutputLines = esriNAOutputLineType.esriNAOutputLineTrueShape;

        }

        /// <summary>

        /// Update settings that apply to all solvers

        /// </summary>

        private void ConfigureGenericSolverSettings()

        {

            INASolverSettings naSolverSettings = m_NAContext.Solver as INASolverSettings;

            naSolverSettings.ImpedanceAttributeName = "Time";

            // set the oneway restriction, if necessary

            IStringArray restrictions = naSolverSettings.RestrictionAttributeNames;

            restrictions.RemoveAll();

            naSolverSettings.RestrictionAttributeNames = restrictions;

            //naSolverSettings.RestrictUTurns = esriNetworkForwardStarBacktrack.esriNFSBNoBacktrack;

        }

        /// <summary>

        /// When the solver has been update, the context must be updated as well

        /// </summary>

        private void UpdateContextAfterChangingSettings()

        {

            IDatasetComponent datasetComponent = m_NAContext.NetworkDataset as IDatasetComponent;

            IDENetworkDataset deNetworkDataset = datasetComponent.DataElement as IDENetworkDataset;

            m_NAContext.Solver.UpdateContext(m_NAContext, deNetworkDataset, new GPMessagesClass());

        }

/// <summary>

        /// Prepare the text string for breaks

        /// </summary>

        /// <param name="p">The p.</param>

        /// <returns>IDoubleArray.</returns>

        private IDoubleArray ParseBreaks(string p)

        {

            String[] breaks = p.Split(' ');

            IDoubleArray pBrks = new DoubleArrayClass();

            int firstIndex = breaks.GetLowerBound();

            int lastIndex = breaks.GetUpperBound();

            for (int splitIndex = firstIndex; splitIndex <= lastIndex; splitIndex++)

            {

                try

                {

                    pBrks.Add(Convert.ToDouble(breaks[splitIndex]));

                }

                catch (FormatException)

                {

                    log.WriteLog("Breaks are not properly formatted.  Use only digits separated by spaces");

                    pBrks.RemoveAll();

                    return pBrks;

                }

            }

            return pBrks;

        }

/// <summary>

        /// Gets the GP messages as string.

        /// </summary>

        /// <param name="gpMessages">The gp messages.</param>

        /// <returns>System.String.</returns>

        public string GetGPMessagesAsString(IGPMessages gpMessages)

        {

            // Gather Error/Warning/Informative Messages

            var messages = new StringBuilder();

            if (gpMessages != null)

            {

                for (int i = ; i < gpMessages.Count; i++)

                {

                    IGPMessage gpMessage = gpMessages.GetMessage(i);

                    string message = gpMessage.Description;

                    switch (gpMessages.GetMessage(i).Type)

                    {

                        case esriGPMessageType.esriGPMessageTypeError:

                            messages.AppendLine("Error " + gpMessage.ErrorCode + ": " + message);

                            break;

                        case esriGPMessageType.esriGPMessageTypeWarning:

                            messages.AppendLine("Warning: " + message);

                            break;

                        default:

                            messages.AppendLine("Information: " + message);

                            break;

                    }

                }

            }

            return messages.ToString();

        }

Solve的更多相关文章

  1. Solve VS2010 Error "Exceptions has been thrown by the target of an invocation"

    Sometimes when you open a VS2010 project, an error window will pop up with the error message "E ...

  2. solve the problem of 'java web project cannot display verification code'

    my java code of the function: package com.util; import java.awt.Color; import java.awt.Font; import ...

  3. HDU1086You can Solve a Geometry Problem too(判断线段相交)

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  4. ACM: FZU 2102 Solve equation - 手速题

     FZU 2102   Solve equation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  5. ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分

    Can you solve this equation? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...

  6. hdu 1086 You can Solve a Geometry Problem too

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  7. 数论 - 组合数学 + 素数分解 --- hdu 2284 : Solve the puzzle, Save the world!

    Solve the puzzle, Save the world! Problem Description In the popular TV series Heroes, there is a ta ...

  8. hdu 2199 Can you solve this equation?(二分搜索)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  9. 看ImplicitBackwardEulerSparse关于static solve的代码

    当选择static solve的时候,求解的流程如下: 1.获得内力 2.qresidual = 外力-内力,qdelta = qresidual, qdelta的非约束元素赋给bufferConst ...

随机推荐

  1. Asp.Net MVC+BootStrap+EF6.0实现简单的用户角色权限管理1

    首先给上项目的整体框架图:,这里我没有使用BLL,因为感觉太烦了就没有去使用. 那么接下来我们首先先去Model层中添加Model. 管理员类: using System; using System. ...

  2. android Dialog实例

    Dialog类 public class DialogUtil { public static Dialog EditDialog(Activity context,View view){ final ...

  3. java http工具类和HttpUrlConnection上传文件分析

    利用java中的HttpUrlConnection上传文件,我们其实只要知道Http协议上传文件的标准格式.那么就可以用任何一门语言来模拟浏览器上传文件.下面有几篇文章从http协议入手介绍了java ...

  4. java中System.getenv和System.getProperties的区别

    System.getenv获取的是系统的环境变量(就是用户在操作系统中设置的环境变量),windows和linux下环境变量的设置就不说了哦. System.getProperties获取的是系统的相 ...

  5. 深度理解Jquery 中 offset() 方法

    参考原文:深度理解Jquery 中 offset() 方法

  6. Java程序性能优化——让你的java程序更快、更稳定

    1.Java性能调优概述 1.1.Web服务器,响应时间.吞吐量是两个重要的性能参数. 1.2.程序性能的几个表现: 执行速度:程序的反映是否迅速,响应时间是否足够短 内存分配:分配是否合理,是否过多 ...

  7. win7+ubuntu双系统 重装win7后grub修复

    问题:之前安装的是win7+ubuntu双系统,重装win7后启动选项没有了,直接进入的是win7系统,无法进入ubuntu系统了. 解决办法:我们需要修复grub,将ubuntu系统重新挂载一下,具 ...

  8. Ubuntu PPTP 服务器安装

    安装相应的包 sudo apt-get install pptpd 修改配置文件pptpd.conf sudo vim /etc/pptpd.conf 设置对应的VPN网络,localip是服务器的, ...

  9. eclipse下maven项目保持原有目录结构配置resin运行环境

    maven项目用起来很方便,但是它的目录结构和eclipse的目录结构是有区别的,故而在eclipse下的maven项目,直接运行调试是有一些问题的. 为了方便maven项目的运行调试,因而也就有了像 ...

  10. 解决www.github.com访问太慢的问题

    解决www.github.com访问太慢的问题 使用www.github.com的过程中,有时候打开会特别的慢,原因github.com的域名被一堵伟大的墙挡在了外面.但是我们可以通过修改本机的hos ...