Solve
/// <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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- 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 ...
- 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 ...
- 数论 - 组合数学 + 素数分解 --- 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 ...
- hdu 2199 Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 看ImplicitBackwardEulerSparse关于static solve的代码
当选择static solve的时候,求解的流程如下: 1.获得内力 2.qresidual = 外力-内力,qdelta = qresidual, qdelta的非约束元素赋给bufferConst ...
随机推荐
- MyEclipse中没有自动提示如何设置
步骤: window->Preferences->Java->Editor->Content Assist->Advanced 将该页面上的所有的未打上勾的选项都勾上就可 ...
- ASP.NET Core AD 域登录
在选择AD登录时,其实可以直接选择 Windows 授权,不过因为有些网站需要的是LDAP获取信息进行授权,而非直接依赖Web Server自带的Windows 授权功能. 当然如果使用的是Azure ...
- redis、memcache、mongoDB 做了对比
from: http://yang.u85.us/memcache_redis_mongodb.pdf 从以下几个维度,对redis.memcache.mongoDB 做了对比. 1.性能 都比较 ...
- WPF 开源Chart控件
控件: Icon URL Supplier Dynamic Data Display 2009
- 基于Zabbix IPMI监控服务器硬件状况
基于Zabbix IPMI监控服务器硬件状况 zabbix ipmi 公司有多个分部,且机房没有专业值班,机房等级不够.在这种情况下,又想实时监控机房环境,于是使用IPMI方式来达到目的.由于之前已经 ...
- 我的CS考研路
说在前面 从去年7月15号正式准备考研以来,直到今天,3月19号,一共经历8个多月,考研初步告捷,在此想跟大家分享一下自己的经验,希望能对接下来考研的学弟学妹们有所帮助. 首先介绍下我自己的情况,本科 ...
- Serial Port Programming using Win32 API(转载)
In this tutorial we will learn How to communicate with an external device like a microcontroller boa ...
- 多个不同的app应用间应该如何进行消息推送呢?
现在很多公司做app应用都会用到推送,推送这个不多说了,怎么做网上一堆,用的比较多的还数极光推送(Jpush)以及百度推送,目前我们使用Jpush,文档方面质量是差了点..这个先不吐槽,主要现在的ap ...
- unity 实现物体破碎效果的一些方法 - 细雨淅淅
游戏越来越接近现实的感觉,如果有一个真是的 虚拟现实设备,可能我们真的会感觉是在真实世界.场景的逼真是在渲染效果.角色AI.游戏逻辑.物理效果等等一起导致的结果.现在游戏越来越大,除了渲染,物理估计是 ...
- Python的with用法理解
Python的with理解 标签(空格分隔): Python with做为一种上下文管理器,在Python中的作用可以简单的理解为是用来代替try...except...finally的处理流程. w ...