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 ...
随机推荐
- x01.Weiqi.10: 死活问题
估计得不错,点目后,仅一个方法:UpdateMeshes5() 就完美解决了梅花六.刀把五.斗笠四.盘角曲四等死活问题.先来看看效果图: 其代码如下: void UpdateMeshes5(bool ...
- ik扩展支持Solr配置
扩展ik原生代码:public class IKAnalyzerTokenizerFactory extends TokenizerFactory{ private boolean useSmart; ...
- java进程占用CPU资源过高分析脚本
#!/bin/bash #输入占用CPU较高的进程号 pid=$ if [ -z $pid ] then echo "PID is NULL" exit fi #找到该进程中占用较 ...
- 【2016-11-7】【坚持学习】【Day22】【C# 委托的应用】
我觉得我对委托的概念还没有完全掌握,于是,我需要继续思考,学习它的应用实现.
- 我觉得有意思的JavaScript题目(01-05更新中)
对于以下js题目均来至于网络中.有的来至于文章之中,有的也许来至于问答题型中.如果您有更好的问题解释,请留言交流! 1.相关问题描述:到底该怎么去理解闭包? 代码片段A !function(){ va ...
- ajax返回值中有回车换行、空格的解决方法分享
最近在写一个页面,用jquery ajax来实现判断,刚写好测试完全没有问题,过了两天发现出现问题,判断不成了.后来发现所有alert出来的返回值前面都会加若干换行和空格.(至今不明白,同一台电脑,同 ...
- Vue系列:在vux的popup组件中使用百度地图遇到显示不全的问题
问题描述: 将百度地图封装成一个独立的组件BMapComponent,具体见 Vue系列:如何将百度地图包装成Vue的组件(http://www.cnblogs.com/strinkbug/p/576 ...
- LeetCode:Max Points on a Line
题目链接 Given n points on a 2D plane, find the maximum number of points that lie on the same straight l ...
- C++11笔记<一>
目录: 1.std::share_ptr智能指针: 2.std::tr1::function模板类: 3.stringstream: 4.set/vector/map: 5.static_cast&l ...
- 51Nod--1010 只包含235的数
51Nod: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 1010 只包含因子2 3 5的数 基准时间限制:1 ...