private void btnOK_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; // IServerContext serverContext = null; try { INASolverSettings2 pNaSolverSetting = pMainFrm.m_NAContext.Solver as INASolverSettings2; SetINASolverSettings(pNaSolverSetting); SetSolverSpecificInterface(); pMainFrm.m_NAContext.Solver.UpdateContext(pMainFrm.m_NAContext, Utility.GetDENetworkDataset(pMainFrm.m_pNetDataset), new GPMessagesClass()); ToolBarButton toolbarbutton1 = pMainFrm.returnToolbarButton(); toolbarbutton1.Enabled = true; this.Dispose(); } catch (Exception exception) { MessageBox.Show(exception.Message, "An error has occurred"); } finally { // Release the ServerContext // if (serverContext != null) // serverContext.ReleaseContext(); } this.Cursor = Cursors.Default; }
/// <summary> /// Set general solver settings (Impedance, Restrictions, Accumulates, etc.) /// </summary> private void SetINASolverSettings(INASolverSettings2 solverSettings) { //1.设置Impedance solverSettings.ImpedanceAttributeName = ExtractImpedanceName(cboImpedance.Text); //2.设置限制属性 IStringArray restrictionAttributes = solverSettings.RestrictionAttributeNames; restrictionAttributes.RemoveAll(); for (int i = 0; i < chklstRestrictions.CheckedItems.Count; i++) { restrictionAttributes.Add(chklstRestrictions.Items[chklstRestrictions.CheckedIndices[i]].ToString()); } solverSettings.RestrictionAttributeNames = restrictionAttributes; //3.设置累计属性 IStringArray accumulateAttributes = solverSettings.AccumulateAttributeNames; accumulateAttributes.RemoveAll(); for (int i = 0; i < chklstAccumulateAttributes.CheckedItems.Count; i++) { accumulateAttributes.Add(chklstAccumulateAttributes.Items[chklstAccumulateAttributes.CheckedIndices[i]].ToString()); } solverSettings.AccumulateAttributeNames = accumulateAttributes; //4.设置允许拐点策略 solverSettings.RestrictUTurns = (esriNetworkForwardStarBacktrack)cboUturnPolicy.SelectedIndex; //5.设置忽略无效位置 solverSettings.IgnoreInvalidLocations = chkIgnoreInvalidLocations.Checked; //6.设置使用高级属性 solverSettings.UseHierarchy = chkUseHierarchy.Checked; }
private void Initialize() { int ImpedanceIndex = 0; //Get Attributes cboImpedance.Items.Clear(); chklstAccumulateAttributes.Items.Clear(); chklstRestrictions.Items.Clear(); cboUturnPolicy.SelectedIndex = -1; //声明网络分析参数设置并赋予数值 INASolverSettings2 pNaSolverSetting = pMainFrm.m_NAContext.Solver as INASolverSettings2; //获得网络分析累积属性名 IStringArray accumulateAttributeNames = pNaSolverSetting.AccumulateAttributeNames; //获得网络分析限制属性名 IStringArray restrictionAttributeNames = pNaSolverSetting.RestrictionAttributeNames; //获得网络分析属性 INetworkAttribute pNetworkAttribute; for (int i = 0; i < pMainFrm.m_pNetDataset.AttributeCount; i++) { pNetworkAttribute = pMainFrm.m_pNetDataset.get_Attribute(i); string networkAttributeName = pNetworkAttribute.Name; //如果网络分析属性等于消耗 if (pNetworkAttribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost) { chklstAccumulateAttributes.Items.Add(networkAttributeName, IsStringInStringArray(networkAttributeName, accumulateAttributeNames)); int index = cboImpedance.Items.Add(pNetworkAttribute.Name + " (" + pNetworkAttribute.Units.ToString().Substring(7) + ")"); if (networkAttributeName == pNaSolverSetting.ImpedanceAttributeName) { ImpedanceIndex = index; } } //如果网络分析属性等于限制 if (pNetworkAttribute.UsageType == esriNetworkAttributeUsageType.esriNAUTRestriction) { chklstRestrictions.Items.Add(pNetworkAttribute.Name, IsStringInStringArray(networkAttributeName, restrictionAttributeNames)); } } if (cboImpedance.Items.Count > 0) { cboImpedance.SelectedIndex = ImpedanceIndex; } //是否使用高级 chkUseHierarchy.Checked = pNaSolverSetting.UseHierarchy; //是否使用高级 chkUseHierarchy.Enabled = pNaSolverSetting.HierarchyAttributeName.Length > 0; //是否忽略无效的位置 chkIgnoreInvalidLocations.Checked = pNaSolverSetting.IgnoreInvalidLocations; //是否允许拐点 cboUturnPolicy.SelectedIndex = System.Convert.ToInt32(pNaSolverSetting.RestrictUTurns); }
/// <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()); } }
/// <summary> /// Set general solver settings (Impedance, Restrictions, Accumulates, etc.) /// </summary> private void SetINASolverSettings(INASolverSettings2 solverSettings) { //1.����Impedance solverSettings.ImpedanceAttributeName = ExtractImpedanceName(cboImpedance.Text); //2.������������ IStringArray restrictionAttributes = solverSettings.RestrictionAttributeNames; restrictionAttributes.RemoveAll(); for (int i = 0; i < chklstRestrictions.CheckedItems.Count; i++) restrictionAttributes.Add(chklstRestrictions.Items[chklstRestrictions.CheckedIndices[i]].ToString()); solverSettings.RestrictionAttributeNames = restrictionAttributes; //3.�����ۼ����� IStringArray accumulateAttributes = solverSettings.AccumulateAttributeNames; accumulateAttributes.RemoveAll(); for (int i = 0; i < chklstAccumulateAttributes.CheckedItems.Count; i++) accumulateAttributes.Add(chklstAccumulateAttributes.Items[chklstAccumulateAttributes.CheckedIndices[i]].ToString()); solverSettings.AccumulateAttributeNames = accumulateAttributes; //4.��������յ���� solverSettings.RestrictUTurns = (esriNetworkForwardStarBacktrack)cboUturnPolicy.SelectedIndex; //5.���ú�����Чλ�� solverSettings.IgnoreInvalidLocations = chkIgnoreInvalidLocations.Checked; //6.����ʹ�ø����� solverSettings.UseHierarchy = chkUseHierarchy.Checked; }
public static void PushParameterValuesToNetwork(INetworkAnalystExtension nax) { try { if (nax == null) { return; } bool naxEnabled = false; IExtensionConfig naxConfig = nax as IExtensionConfig; naxEnabled = naxConfig.State == esriExtensionState.esriESEnabled; if (!naxEnabled) { return; } INAWindow naWindow = nax.NAWindow; INALayer naLayer = null; INAContext naContext = null; INetworkDataset nds = null; naLayer = naWindow.ActiveAnalysis; if (naLayer != null) { naContext = naLayer.Context; } if (naContext != null) { nds = naContext.NetworkDataset; } if (nds == null) { return; } IDatasetComponent dsComponent = nds as IDatasetComponent; IDENetworkDataset deNet = dsComponent.DataElement as IDENetworkDataset; INASolver naSolver = naContext.Solver; INASolverSettings2 naSolverSettings2 = naSolver as INASolverSettings2; if (naSolverSettings2 == null) { return; } INetworkAttribute2 netAttribute; string attributeName; IArray netParameters; INetworkAttributeParameter netParameter; string paramName; int cParameters; object paramValue; int cAttributes = nds.AttributeCount; for (int a = 0; a < cAttributes; ++a) { netAttribute = nds.get_Attribute(a) as INetworkAttribute2; attributeName = netAttribute.Name; netParameters = netAttribute.Parameters; cParameters = netParameters.Count; for (int p = 0; p < cParameters; ++p) { netParameter = netParameters.get_Element(p) as INetworkAttributeParameter; paramName = netParameter.Name; paramValue = naSolverSettings2.get_AttributeParameterValue(attributeName, paramName); netParameter.Value = paramValue; } netAttribute.Refresh(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Push Parameter Values To Network"); } }
public static void UpdateEIDArrayParameterValuesFromEIDLists(INetworkAnalystExtension nax, Dictionary <string, List <int> > eidsBySourceName, string baseName) { if (nax == null) { return; } bool naxEnabled = false; IExtensionConfig naxConfig = nax as IExtensionConfig; naxEnabled = naxConfig.State == esriExtensionState.esriESEnabled; if (!naxEnabled) { return; } INAWindow naWindow = nax.NAWindow; INALayer naLayer = null; INAContext naContext = null; INetworkDataset nds = null; naLayer = naWindow.ActiveAnalysis; if (naLayer != null) { naContext = naLayer.Context; } if (naContext != null) { nds = naContext.NetworkDataset; } if (nds == null) { return; } IDatasetComponent dsComponent = nds as IDatasetComponent; IDENetworkDataset deNet = dsComponent.DataElement as IDENetworkDataset; INASolver naSolver = naContext.Solver; INASolverSettings2 naSolverSettings2 = naSolver as INASolverSettings2; if (naSolverSettings2 == null) { return; } string prefix = GetEIDArrayPrefixFromBaseName(baseName); VarType vt = GetEIDArrayParameterType(); int cAttributes = nds.AttributeCount; for (int a = 0; a < cAttributes; ++a) { INetworkAttribute2 netAttribute = nds.get_Attribute(a) as INetworkAttribute2; IArray netParams = netAttribute.Parameters; int cParams = netParams.Count; object paramValue; for (int p = 0; p < cParams; ++p) { INetworkAttributeParameter param = netParams.get_Element(p) as INetworkAttributeParameter; if (param.VarType != (int)vt) { continue; } string paramName = param.Name; string sourceName = GetSourceNameFromParameterName(prefix, paramName); if (sourceName.Length == 0) { continue; } List <int> eids = null; if (eidsBySourceName.TryGetValue(sourceName, out eids)) { if (eids != null) { if (eids.Count == 0) { eids = null; } } } paramValue = (eids != null) ? eids.ToArray() : null; naSolverSettings2.set_AttributeParameterValue(netAttribute.Name, param.Name, paramValue); } } }