private static void ClearEIDArrayParameterValues(INetworkAnalystExtension nax, List <string> sourceNames, string baseName) { if (nax == null) { return; } bool naxEnabled = false; IExtensionConfig naxConfig = nax as IExtensionConfig; naxEnabled = naxConfig.State == esriExtensionState.esriESEnabled; if (!naxEnabled) { return; } Dictionary <string, List <int> > eidsBySourceName = new Dictionary <string, List <int> >(); foreach (string sourceName in sourceNames) { List <int> eids = null; if (!eidsBySourceName.TryGetValue(sourceName, out eids)) { eidsBySourceName.Add(sourceName, null); } } UpdateEIDArrayParameterValuesFromEIDLists(nax, eidsBySourceName, baseName); }
/// <summary> /// Occurs when this command is created /// </summary> /// <param name="hook">Instance of the application</param> public override void OnCreate(object hook) { if (hook == null) { return; } m_application = hook as IApplication; m_nax = SubsetHelperUI.GetNAXConfiguration(m_application) as INetworkAnalystExtension; }
public override void OnCreate(object hook) { // Try to get the ArcGIS Network Analyst extension from the desktop app's extensions IApplication app; app = hook as IApplication; if (app != null) { m_naExt = app.FindExtensionByName("Network Analyst") as INetworkAnalystExtension; } }
/// <summary> /// Occurs when this command is created /// </summary> /// <param name="hook">Instance of the application</param> /// public override void OnCreate(object hook) { if (hook == null) { return; } m_application = hook as IApplication; base.m_enabled = true; if (m_application != null) { m_naExt = m_application.FindExtensionByName("Network Analyst") as INetworkAnalystExtension; } }
/// <summary> /// Occurs when this command is created /// </summary> /// <param name="hook">Instance of the application</param> public override void OnCreate(object hook) { if (hook == null) { return; } m_application = hook as IApplication; m_nax = null; m_naWindowEventSource = null; m_mapEventSource = null; m_graphicsEventSource = null; m_nax = SubsetHelperUI.GetNAXConfiguration(m_application) as INetworkAnalystExtension; }
public static void ClearEIDArrayParameterValues(INetworkAnalystExtension nax, string baseName) { try { 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; } VarType vt = SubsetHelperUI.GetEIDArrayParameterType(); List <string> sourceNames = SubsetHelperUI.FindParameterizedSourceNames(nds, baseName, vt); SubsetHelperUI.ClearEIDArrayParameterValues(nax, sourceNames, baseName); SubsetHelperUI.PushParameterValuesToNetwork(nax); } catch (Exception ex) { string msg = SubsetHelperUI.GetFullExceptionMessage(ex); MessageBox.Show(msg, "Clear Network Element Array Parameters"); } }
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 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"); } }
private static Dictionary<string, List<int>> GetEIDListsBySourceName(INetworkAnalystExtension nax, object searchObject, string baseName) { if (nax == null) return null; bool naxEnabled = false; IExtensionConfig naxConfig = nax as IExtensionConfig; naxEnabled = naxConfig.State == esriExtensionState.esriESEnabled; if (!naxEnabled) return null; 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; INetworkQuery netQuery = nds as INetworkQuery; if (netQuery == null) return null; bool oidSearch = false; bool geometrySearch = false; if (searchObject == null) return null; else if (searchObject is Dictionary<string, ILongArray>) oidSearch = true; else if (searchObject is IGeometry) geometrySearch = true; else return null; VarType vt = GetEIDArrayParameterType(); List<string> sourceNames = FindParameterizedSourceNames(nds, baseName, vt); Dictionary<string, List<int>> eidsBySourceName = new Dictionary<string, List<int>>(); foreach (string sourceName in sourceNames) { INetworkSource netSource = nds.get_SourceByName(sourceName); int sourceID = netSource.ID; List<int> eids = new List<int>(); if (oidSearch) { Dictionary<string, ILongArray> oidArraysBySourceName = (Dictionary<string, ILongArray>)searchObject; ILongArray oids = null; IEnumNetworkElement enumNetElement; INetworkElement netElement; if (oidArraysBySourceName.TryGetValue(sourceName, out oids)) { enumNetElement = netQuery.get_ElementsByOIDs(sourceID, oids); enumNetElement.Reset(); netElement = enumNetElement.Next(); while (netElement != null) { eids.Add(netElement.EID); netElement = enumNetElement.Next(); } } } else if (geometrySearch) { IGeometry searchGeometry = (IGeometry)searchObject; if (searchGeometry != null && !searchGeometry.IsEmpty) { IGeometry elementGeometry = null; esriNetworkElementType elementType = esriNetworkElementType.esriNETEdge; int eid = -1; // Search for the network dataset layer associated with the active analysis layer or create one using the // network dataset if matching one not found. // If, for example, multiple network dataset layers are added to the map, the active analysis layer // might not reference the current network dataset layer (nax.CurrentNetworkLayer). INetworkLayer ndsLayer = new NetworkLayerClass(); ndsLayer.NetworkDataset = nds; int count = nax.NetworkLayerCount; for (int i = 0; i < count; ++i) { ndsLayer = nax.get_NetworkLayer(i); if (ndsLayer.NetworkDataset == nds) break; else ndsLayer = null; } if (ndsLayer == null) { ndsLayer = new NetworkLayerClass(); ndsLayer.NetworkDataset = nds; } IEnumLocatedNetworkElement enumLocatedNetElement = null; if (ndsLayer != null) { enumLocatedNetElement = ndsLayer.SearchLocatedNetworkElements(sourceName, searchGeometry); enumLocatedNetElement.Reset(); eid = enumLocatedNetElement.Next(ref elementGeometry, ref elementType); while (eid != -1) { eids.Add(eid); eid = enumLocatedNetElement.Next(ref elementGeometry, ref elementType); } } } } eidsBySourceName.Add(sourceName, eids); } return eidsBySourceName; }
public static void UpdateEIDArrayParameterValuesFromGeometry(INetworkAnalystExtension nax, IGeometry searchGeometry, string baseName) { Dictionary<string, List<int>> eidsBySourceName = GetEIDListsBySourceName(nax, searchGeometry, baseName); UpdateEIDArrayParameterValuesFromEIDLists(nax, eidsBySourceName, baseName); }
public static void UpdateEIDArrayParameterValuesFromOIDArrays(INetworkAnalystExtension nax, Dictionary<string, ILongArray> oidArraysBySourceName, string baseName) { Dictionary<string, List<int>> eidsBySourceName = GetEIDListsBySourceName(nax, oidArraysBySourceName, baseName); UpdateEIDArrayParameterValuesFromEIDLists(nax, eidsBySourceName, baseName); }
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); } } }
public override void OnCreate(object hook) { // Try to get the ArcGIS Network Analyst extension from the desktop app's extensions IApplication app; app = hook as IApplication; if (app != null) m_naExt = app.FindExtensionByName("Network Analyst") as INetworkAnalystExtension; }
private static Dictionary <string, List <int> > GetEIDListsBySourceName(INetworkAnalystExtension nax, object searchObject, string baseName) { if (nax == null) { return(null); } bool naxEnabled = false; IExtensionConfig naxConfig = nax as IExtensionConfig; naxEnabled = naxConfig.State == esriExtensionState.esriESEnabled; if (!naxEnabled) { return(null); } 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; } INetworkQuery netQuery = nds as INetworkQuery; if (netQuery == null) { return(null); } bool oidSearch = false; bool geometrySearch = false; if (searchObject == null) { return(null); } else if (searchObject is Dictionary <string, ILongArray> ) { oidSearch = true; } else if (searchObject is IGeometry) { geometrySearch = true; } else { return(null); } VarType vt = GetEIDArrayParameterType(); List <string> sourceNames = FindParameterizedSourceNames(nds, baseName, vt); Dictionary <string, List <int> > eidsBySourceName = new Dictionary <string, List <int> >(); foreach (string sourceName in sourceNames) { INetworkSource netSource = nds.get_SourceByName(sourceName); int sourceID = netSource.ID; List <int> eids = new List <int>(); if (oidSearch) { Dictionary <string, ILongArray> oidArraysBySourceName = (Dictionary <string, ILongArray>)searchObject; ILongArray oids = null; IEnumNetworkElement enumNetElement; INetworkElement netElement; if (oidArraysBySourceName.TryGetValue(sourceName, out oids)) { enumNetElement = netQuery.get_ElementsByOIDs(sourceID, oids); enumNetElement.Reset(); netElement = enumNetElement.Next(); while (netElement != null) { eids.Add(netElement.EID); netElement = enumNetElement.Next(); } } } else if (geometrySearch) { IGeometry searchGeometry = (IGeometry)searchObject; if (searchGeometry != null && !searchGeometry.IsEmpty) { IGeometry elementGeometry = null; esriNetworkElementType elementType = esriNetworkElementType.esriNETEdge; int eid = -1; // Search for the network dataset layer associated with the active analysis layer or create one using the // network dataset if matching one not found. // If, for example, multiple network dataset layers are added to the map, the active analysis layer // might not reference the current network dataset layer (nax.CurrentNetworkLayer). INetworkLayer ndsLayer = new NetworkLayerClass(); ndsLayer.NetworkDataset = nds; int count = nax.NetworkLayerCount; for (int i = 0; i < count; ++i) { ndsLayer = nax.get_NetworkLayer(i); if (ndsLayer.NetworkDataset == nds) { break; } else { ndsLayer = null; } } if (ndsLayer == null) { ndsLayer = new NetworkLayerClass(); ndsLayer.NetworkDataset = nds; } IEnumLocatedNetworkElement enumLocatedNetElement = null; if (ndsLayer != null) { enumLocatedNetElement = ndsLayer.SearchLocatedNetworkElements(sourceName, searchGeometry); enumLocatedNetElement.Reset(); eid = enumLocatedNetElement.Next(ref elementGeometry, ref elementType); while (eid != -1) { eids.Add(eid); eid = enumLocatedNetElement.Next(ref elementGeometry, ref elementType); } } } } eidsBySourceName.Add(sourceName, eids); } return(eidsBySourceName); }
public static void UpdateEIDArrayParameterValuesFromGeometry(INetworkAnalystExtension nax, IGeometry searchGeometry, string baseName) { Dictionary <string, List <int> > eidsBySourceName = GetEIDListsBySourceName(nax, searchGeometry, baseName); UpdateEIDArrayParameterValuesFromEIDLists(nax, eidsBySourceName, baseName); }
public static void UpdateEIDArrayParameterValuesFromOIDArrays(INetworkAnalystExtension nax, Dictionary <string, ILongArray> oidArraysBySourceName, string baseName) { Dictionary <string, List <int> > eidsBySourceName = GetEIDListsBySourceName(nax, oidArraysBySourceName, baseName); UpdateEIDArrayParameterValuesFromEIDLists(nax, eidsBySourceName, baseName); }
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); } } }
/// <summary> /// Occurs when this command is created /// </summary> /// <param name="hook">Instance of the application</param> /// public override void OnCreate(object hook) { if (hook == null) return; m_application = hook as IApplication; base.m_enabled = true; if (m_application != null) m_naExt = m_application.FindExtensionByName("Network Analyst") as INetworkAnalystExtension; }
/// <summary> /// Occurs when this command is created /// </summary> /// <param name="hook">Instance of the application</param> public override void OnCreate(object hook) { if (hook == null) return; m_application = hook as IApplication; m_nax = SubsetHelperUI.GetNAXConfiguration(m_application) as INetworkAnalystExtension; }
public static void ClearEIDArrayParameterValues(INetworkAnalystExtension nax, string baseName) { try { 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; VarType vt = SubsetHelperUI.GetEIDArrayParameterType(); List<string> sourceNames = SubsetHelperUI.FindParameterizedSourceNames(nds, baseName, vt); SubsetHelperUI.ClearEIDArrayParameterValues(nax, sourceNames, baseName); SubsetHelperUI.PushParameterValuesToNetwork(nax); } catch (Exception ex) { string msg = SubsetHelperUI.GetFullExceptionMessage(ex); MessageBox.Show(msg, "Clear Network Element Array Parameters"); } }
private static void ClearEIDArrayParameterValues(INetworkAnalystExtension nax, List<string> sourceNames, string baseName) { if (nax == null) return; bool naxEnabled = false; IExtensionConfig naxConfig = nax as IExtensionConfig; naxEnabled = naxConfig.State == esriExtensionState.esriESEnabled; if (!naxEnabled) return; Dictionary<string, List<int>> eidsBySourceName = new Dictionary<string, List<int>>(); foreach (string sourceName in sourceNames) { List<int> eids = null; if (!eidsBySourceName.TryGetValue(sourceName, out eids)) eidsBySourceName.Add(sourceName, null); } UpdateEIDArrayParameterValuesFromEIDLists(nax, eidsBySourceName, baseName); }
/// <summary> /// Occurs when this command is created /// </summary> /// <param name="hook">Instance of the application</param> public override void OnCreate(object hook) { if (hook == null) return; m_application = hook as IApplication; m_nax = null; m_naWindowEventSource = null; m_mapEventSource = null; m_graphicsEventSource = null; m_nax = SubsetHelperUI.GetNAXConfiguration(m_application) as INetworkAnalystExtension; }