/// <summary> /// 加载停靠点 /// </summary> public void loadNANetworkLocations(string strNAClassName, IFeatureClass inputFC, double snapTolerance) { INAClass naClass; INamedSet classes; classes = m_NAContext.NAClasses; naClass = classes.get_ItemByName(strNAClassName) as INAClass; //删除naClasses中添加的项 naClass.DeleteAllRows(); //加载网络分析对象,设置容差值 INAClassLoader classLoader = new NAClassLoader(); classLoader.Locator = m_NAContext.Locator; if (snapTolerance > 0) { classLoader.Locator.SnapTolerance = snapTolerance; } classLoader.NAClass = naClass; //字段匹配 INAClassFieldMap pNAClassFieldMap = new NAClassFieldMap(); pNAClassFieldMap.CreateMapping(naClass.ClassDefinition, inputFC.Fields); classLoader.FieldMap = pNAClassFieldMap; //加载网络分析类 int rowsln = 0; int rowsLocated = 0; IFeatureCursor featureCursor = inputFC.Search(null, true); classLoader.Load((ICursor)featureCursor, null, ref rowsln, ref rowsLocated); ((INAContextEdit)m_NAContext).ContextChanged(); }
//加载参与分析的点要素 public static void LoadNANetworkLocations(string strNAClassName, IFeatureClass inputFC, INAContext m_NAContext, double snapTolerance) { //ITable b1 = inputFC as ITable;//将传入的要素类转化为一个Table对象,这个要素类如站点类、障碍点类等。 //int i1 = b1.RowCount(null);//获取行数 INAClass naClass; INamedSet classes; classes = m_NAContext.NAClasses; //上下文对象的有关网络分析类的对象集合NamedSet属性 naClass = classes.get_ItemByName(strNAClassName) as INAClass; //通过传入的名称参数,往classes中获取对应的NAClass naClass.DeleteAllRows(); //删除naClass中的所有要素 INAClassLoader classLoader = new NAClassLoader(); //新建一个NAClassLoader对象 classLoader.Locator = m_NAContext.Locator; //将上下文对象的locator属性赋给classLoader,locator用于确定网络上要加载的要素的位置。 if (snapTolerance > 0) { classLoader.Locator.SnapTolerance = snapTolerance; //设置容差 } classLoader.NAClass = naClass; //给classLoader对象的NAClass属性赋值 //设置字段映射 INAClassFieldMap fieldMap = null; fieldMap = new NAClassFieldMap(); fieldMap.set_MappedField("FID", "FID"); //set_MappedField方法用于建立源数据到NAClass类的映射 classLoader.FieldMap = fieldMap; //给classLoader对象的FieldMap属性赋值 int rowsIn = 0; int rowLocated = 0; IFeatureCursor featureCursor = inputFC.Search(null, true); classLoader.Load((ICursor)featureCursor, null, ref rowsIn, ref rowLocated);//ref类型关键字表示对于该参数,在函数过程中可以读也可以写,相当于引用传递。引用传递参数允许函数成员更改参数的值,并保持该更改。 ((INAContextEdit)m_NAContext).ContextChanged(); }
/// <summary> /// Set solver settings /// </summary> /// <param name="strNAClassName">NAClass name</param> /// <param name="inputFC">Input feature class</param> /// <param name="maxSnapTolerance">Max snap tolerance</param> public void LoadNANetworkLocations(string strNAClassName, IFeatureClass inputFC, double maxSnapTolerance) { INamedSet classes = m_NAContext.NAClasses; INAClass naClass = classes.get_ItemByName(strNAClassName) as INAClass; // Delete existing locations from the specified NAClass naClass.DeleteAllRows(); // Create a NAClassLoader and set the snap tolerance (meters unit) INAClassLoader classLoader = new NAClassLoader(); classLoader.Locator = m_NAContext.Locator; if (maxSnapTolerance > 0) ((INALocator3)classLoader.Locator).MaxSnapTolerance = maxSnapTolerance; classLoader.NAClass = naClass; // Create field map to automatically map fields from input class to NAClass INAClassFieldMap fieldMap = new NAClassFieldMapClass(); fieldMap.CreateMapping(naClass.ClassDefinition, inputFC.Fields); classLoader.FieldMap = fieldMap; // Avoid loading network locations onto non-traversable portions of elements INALocator3 locator = m_NAContext.Locator as INALocator3; locator.ExcludeRestrictedElements = true; locator.CacheRestrictedElements(m_NAContext); // Load network locations int rowsIn = 0; int rowsLocated = 0; classLoader.Load((ICursor)inputFC.Search(null, true), null, ref rowsIn, ref rowsLocated); // Message all of the network analysis agents that the analysis context has changed. ((INAContextEdit)m_NAContext).ContextChanged(); }
/// <summary> /// 加载参与分析的点要素 /// 按住Ctrl点击下行链接[Onclick]查看使用 /// <see cref="WhuGIS.ArcEngineTool.NetworkAnalysis.GetPathSolve.ShortPathSolveCommand.OnClick"/> /// </summary> /// <param name="strNAClassName"></param> /// <param name="inputFC"></param> /// <param name="m_NAContext"></param> /// <param name="snapTolerance"></param> public static void LoadNANetworkLocations(string strNAClassName, IFeatureClass inputFC, INAContext m_NAContext, double snapTolerance) { ITable b1 = inputFC as ITable; int i1 = b1.RowCount(null); INAClass naClass; INamedSet classes; classes = m_NAContext.NAClasses; naClass = classes.get_ItemByName(strNAClassName) as INAClass; ITable b2 = naClass as ITable; int i2 = b2.RowCount(null); naClass.DeleteAllRows(); ITable b3 = naClass as ITable; int i3 = b2.RowCount(null); INAClassLoader classLoader = new NAClassLoader(); classLoader.Locator = m_NAContext.Locator; if (snapTolerance > 0) { classLoader.Locator.SnapTolerance = snapTolerance; //设置容差 } classLoader.NAClass = naClass; //设置字段映射 INAClassFieldMap fieldMap = null; fieldMap = new NAClassFieldMap(); fieldMap.set_MappedField("FID", "FID"); classLoader.FieldMap = fieldMap; int rowsIn = 0; int rowLocated = 0; IFeatureCursor featureCursor = inputFC.Search(null, true); classLoader.Load((ICursor)featureCursor, null, ref rowsIn, ref rowLocated); INAClass na = classLoader.NAClass; ITable b5 = na as ITable; int i5 = b2.RowCount(null); ITable b4 = inputFC as ITable; int i4 = b1.RowCount(null); ((INAContextEdit)m_NAContext).ContextChanged(); }
/// <summary> /// Load the input table and create field map to map fields from input table to NAClass /// </summary> /// <param name="strNAClassName">NAClass name</param> /// <param name="inputTable">Input table</param> public void LoadNANetworkLocations(string strNAClassName, ITable inputTable) { INamedSet classes = m_NAContext.NAClasses; INAClass naClass = classes.get_ItemByName(strNAClassName) as INAClass; // Delete existing rows from the specified NAClass naClass.DeleteAllRows(); // Create a NAClassLoader and set the snap tolerance (meters unit) INAClassLoader loader = new NAClassLoader(); loader.Locator = m_NAContext.Locator; loader.Locator.SnapTolerance = 100; loader.NAClass = naClass; // Create field map to automatically map fields from input table to NAclass INAClassFieldMap fieldMap = new NAClassFieldMapClass(); fieldMap.CreateMapping(naClass.ClassDefinition, inputTable.Fields); loader.FieldMap = fieldMap; // Avoid loading network locations onto non-traversable portions of elements INALocator3 locator = m_NAContext.Locator as INALocator3; locator.ExcludeRestrictedElements = true; locator.CacheRestrictedElements(m_NAContext); // Load input table int rowsIn = 0; int rowsLocated = 0; loader.Load(inputTable.Search(null, true), null, ref rowsIn, ref rowsLocated); // Message all of the network analysis agents that the analysis context has changed. INAContextEdit naContextEdit = m_NAContext as INAContextEdit; naContextEdit.ContextChanged(); }
//装载网络分析元素的位置 private void LoadNANetworkLocations(string strNAClassName, IFeatureClass inputFC, double snapTolerance) { try { INAClass naClass; INamedSet classes; classes = pMainFrm.m_NAContext.NAClasses; naClass = classes.get_ItemByName(strNAClassName) as INAClass; // delete existing Locations except if that a barriers naClass.DeleteAllRows(); // Create a NAClassLoader and set the snap tolerance (meters unit) INAClassLoader classLoader = new NAClassLoader(); classLoader.Locator = pMainFrm.m_NAContext.Locator; if (snapTolerance > 0) { classLoader.Locator.SnapTolerance = snapTolerance; } classLoader.NAClass = naClass; //Create field map to automatically map fields from input class to naclass INAClassFieldMap fieldMap; fieldMap = new NAClassFieldMap(); fieldMap.CreateMapping(naClass.ClassDefinition, inputFC.Fields); classLoader.FieldMap = fieldMap; //Load Network Locations int rowsIn = 0; int rowsLocated = 0; IFeatureCursor featureCursor = inputFC.Search(null, true); classLoader.Load((ICursor)featureCursor, null, ref rowsIn, ref rowsLocated); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//********************************************************************************* // Load Network Locations //********************************************************************************* public void LoadNANetworkLocations(string strNAClassName, IFeatureClass inputFC, double maxSnapTolerance) { INamedSet classes = m_NAContext.NAClasses; INAClass naClass = classes.get_ItemByName(strNAClassName) as INAClass; // Delete existing Locations before loading new ones naClass.DeleteAllRows(); // Create a NAClassLoader and set the snap tolerance (meters unit) INAClassLoader classLoader = new NAClassLoader(); classLoader.Locator = m_NAContext.Locator; if (maxSnapTolerance > 0) ((INALocator3)classLoader.Locator).MaxSnapTolerance = maxSnapTolerance; classLoader.NAClass = naClass; //Create field map to automatically map fields from input class to NAClass INAClassFieldMap fieldMap = new NAClassFieldMap(); fieldMap.CreateMapping(naClass.ClassDefinition, inputFC.Fields); classLoader.FieldMap = fieldMap; // Avoid loading network locations onto non-traversable portions of elements INALocator3 locator = m_NAContext.Locator as INALocator3; locator.ExcludeRestrictedElements = true; locator.CacheRestrictedElements(m_NAContext); //Load Network Locations int rowsIn = 0; int rowsLocated = 0; IFeatureCursor featureCursor = inputFC.Search(null, true); classLoader.Load((ICursor)featureCursor, null, ref rowsIn, ref rowsLocated); //Message all of the network analysis agents that the analysis context has changed ((INAContextEdit)m_NAContext).ContextChanged(); }
public bool ShowModal(IMapControl3 mapControl, IEngineNetworkAnalystEnvironment naEnv) { // Initialize variables m_okClicked = false; m_listDisplayTable = new System.Collections.ArrayList(); var activeCategory = naEnv.NAWindow.ActiveCategory as IEngineNAWindowCategory2; if (activeCategory == null) { return(false); } IDataLayer dataLayer = activeCategory.DataLayer; if (dataLayer == null) { return(false); } // Set up the title of this dialog String dataLayerName = GetDataLayerName(dataLayer); if (dataLayerName.Length == 0) { return(false); } this.Text = "Load Items into " + dataLayerName; // Make sure the combo box lists only the appropriate possible input data layers PopulateInputDataComboBox(mapControl, dataLayer); //Select the first display table from the list if (cboInputData.Items.Count > 0) { cboInputData.SelectedIndex = 0; } // Show the window this.ShowDialog(); // If we selected a layer and clicked OK, load the locations if (m_okClicked && (cboInputData.SelectedIndex >= 0)) { try { // Get a cursor on the source display table (either though the selection set or table) // Use IDisplayTable because it accounts for joins, querydefs, etc. // IDisplayTable is implemented by FeatureLayers and StandaloneTables. // IDisplayTable displayTable = m_listDisplayTable[cboInputData.SelectedIndex] as IDisplayTable; ICursor cursor; if (chkUseSelection.Checked) { ISelectionSet selSet; selSet = displayTable.DisplaySelectionSet; selSet.Search(null, false, out cursor); } else { cursor = displayTable.SearchDisplayTable(null, false); } // Get the NAContext from the active analysis layer INAContext naContext = naEnv.NAWindow.ActiveAnalysis.Context; // Get the dataset for the active NAClass IDataset naDataset = activeCategory.NAClass as IDataset; // Setup NAClassLoader and Load Locations INAClassLoader2 naClassLoader = new NAClassLoader() as INAClassLoader2; naClassLoader.Initialize(naContext, naDataset.Name, cursor); // Avoid loading network locations onto non-traversable portions of elements INALocator3 locator = naContext.Locator as INALocator3; locator.ExcludeRestrictedElements = true; locator.CacheRestrictedElements(naContext); int rowsIn = 0; int rowsLocated = 0; naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated); // Let the user know if some of the rows failed to locate if (rowsIn != rowsLocated) { MessageBox.Show("Out of " + rowsIn + " + rows, " + rowsLocated + " rows were located", "Loading locations", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception e) { MessageBox.Show(e.Message, "Loading locations failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(true); } return(false); }
public bool ShowModal(IMapControl3 mapControl, IEngineNetworkAnalystEnvironment naEnv) { // Initialize variables m_okClicked = false; m_listDisplayTable = new System.Collections.ArrayList(); var activeCategory = naEnv.NAWindow.ActiveCategory as IEngineNAWindowCategory2; if (activeCategory == null) return false; IDataLayer dataLayer = activeCategory.DataLayer; if (dataLayer == null) return false; // Set up the title of this dialog String dataLayerName = GetDataLayerName(dataLayer); if (dataLayerName.Length == 0) return false; this.Text = "Load Items into " + dataLayerName; // Make sure the combo box lists only the appropriate possible input data layers PopulateInputDataComboBox(mapControl, dataLayer); //Select the first display table from the list if (cboInputData.Items.Count > 0) cboInputData.SelectedIndex = 0; // Show the window this.ShowDialog(); // If we selected a layer and clicked OK, load the locations if (m_okClicked && (cboInputData.SelectedIndex >= 0)) { try { // Get a cursor on the source display table (either though the selection set or table) // Use IDisplayTable because it accounts for joins, querydefs, etc. // IDisplayTable is implemented by FeatureLayers and StandaloneTables. // IDisplayTable displayTable = m_listDisplayTable[cboInputData.SelectedIndex] as IDisplayTable; ICursor cursor; if (chkUseSelection.Checked) { ISelectionSet selSet; selSet = displayTable.DisplaySelectionSet; selSet.Search(null, false, out cursor); } else cursor = displayTable.SearchDisplayTable(null, false); // Get the NAContext from the active analysis layer INAContext naContext = naEnv.NAWindow.ActiveAnalysis.Context; // Get the dataset for the active NAClass IDataset naDataset = activeCategory.NAClass as IDataset; // Setup NAClassLoader and Load Locations INAClassLoader2 naClassLoader = new NAClassLoader() as INAClassLoader2; naClassLoader.Initialize(naContext, naDataset.Name, cursor); // Avoid loading network locations onto non-traversable portions of elements INALocator3 locator = naContext.Locator as INALocator3; locator.ExcludeRestrictedElements = true; locator.CacheRestrictedElements(naContext); int rowsIn = 0; int rowsLocated = 0; naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated); // Let the user know if some of the rows failed to locate if (rowsIn != rowsLocated) MessageBox.Show("Out of " + rowsIn + " + rows, " + rowsLocated + " rows were located", "Loading locations", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception e) { MessageBox.Show(e.Message, "Loading locations failure", MessageBoxButtons.OK, MessageBoxIcon.Error ); } return true; } return false; }
public bool ShowModal(IMapControl3 mapControl, IEngineNetworkAnalystEnvironment naEnv) { // Initialize variables m_okClicked = false; m_listDisplayTable = new System.Collections.ArrayList(); // Get the NALayer and NAContext INALayer naLayer = naEnv.NAWindow.ActiveAnalysis; INAContext naContext = naLayer.Context; //Get the active category IEngineNAWindowCategory2 activeCategory = naEnv.NAWindow.ActiveCategory as IEngineNAWindowCategory2; if (activeCategory == null) { return(false); } INAClass naClass = activeCategory.NAClass; IDataset naDataset = naClass as IDataset; IDataLayer pDataLayer = activeCategory.DataLayer; ILayer pLayer = pDataLayer as ILayer; IFeatureLayer pFeatureLayer = pDataLayer as IFeatureLayer; IStandaloneTable pStandaloneTable = pDataLayer as IStandaloneTable; esriGeometryType targetGeoType = esriGeometryType.esriGeometryNull; String dataLayerName = ""; if (pFeatureLayer != null) { if (pLayer.Valid) { IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; if (pFeatureClass != null) { targetGeoType = pFeatureClass.ShapeType; dataLayerName = pLayer.Name; } } } else if (pStandaloneTable != null) { dataLayerName = pStandaloneTable.Name; } if (dataLayerName.Length == 0) { return(false); } this.Text = "Load Items into " + dataLayerName; // Loop through all the sourcedisplayTables having targetGeoType to the combo box and the // list of displayTables IEnumLayer sourceLayers = null; ILayer sourceLayer = null; IDisplayTable sourceDisplayTable = null; UID searchInterfaceUID = new UID(); if (targetGeoType != esriGeometryType.esriGeometryNull) { searchInterfaceUID.Value = typeof(IFeatureLayer).GUID.ToString("B"); sourceLayers = mapControl.Map.get_Layers(searchInterfaceUID, true); sourceLayer = sourceLayers.Next(); while (sourceLayer != null) { IFeatureLayer sourceFeatureLayer = sourceLayer as IFeatureLayer; sourceDisplayTable = sourceLayer as IDisplayTable; if ((sourceFeatureLayer != null) && (sourceDisplayTable != null)) { IFeatureClass sourceFeatureClass = sourceFeatureLayer.FeatureClass; esriGeometryType sourceGeoType = sourceFeatureClass.ShapeType; if ((sourceGeoType == targetGeoType) || (targetGeoType == esriGeometryType.esriGeometryPoint && sourceGeoType == esriGeometryType.esriGeometryMultipoint)) { // Add the layer name to the combobox and the layer to the list cboInputData.Items.Add(sourceLayer.Name); m_listDisplayTable.Add(sourceDisplayTable); } } sourceLayer = sourceLayers.Next(); } } else //if (targetGeoType == esriGeometryType.esriGeometryNull) { IStandaloneTableCollection sourceStandaloneTables = mapControl.Map as IStandaloneTableCollection; IStandaloneTable sourceStandaloneTable = null; sourceDisplayTable = null; int count = 0; if (sourceStandaloneTables != null) { count = sourceStandaloneTables.StandaloneTableCount; } for (int i = 0; i < count; ++i) { sourceStandaloneTable = sourceStandaloneTables.get_StandaloneTable(i); sourceDisplayTable = sourceStandaloneTable as IDisplayTable; if ((sourceStandaloneTable != null) && (sourceDisplayTable != null)) { // Add the table name to the combobox and the layer to the list cboInputData.Items.Add(sourceStandaloneTable.Name); m_listDisplayTable.Add(sourceDisplayTable); } } searchInterfaceUID.Value = typeof(INALayer).GUID.ToString("B"); sourceLayers = mapControl.Map.get_Layers(searchInterfaceUID, true); sourceLayer = sourceLayers.Next(); while (sourceLayer != null) { INALayer sourceNALayer = sourceLayer as INALayer; if (sourceNALayer != null) { sourceStandaloneTables = sourceNALayer as IStandaloneTableCollection; sourceStandaloneTable = null; sourceDisplayTable = null; count = 0; if (sourceStandaloneTables != null) { count = sourceStandaloneTables.StandaloneTableCount; } for (int i = 0; i < count; ++i) { sourceStandaloneTable = sourceStandaloneTables.get_StandaloneTable(i); sourceDisplayTable = sourceStandaloneTable as IDisplayTable; if ((sourceStandaloneTable != null) && (sourceDisplayTable != null)) { // Add the table name to the combobox and the layer to the list cboInputData.Items.Add(sourceStandaloneTable.Name); m_listDisplayTable.Add(sourceDisplayTable); } } } sourceLayer = sourceLayers.Next(); } } //Select the first display table from the list if (cboInputData.Items.Count > 0) { cboInputData.SelectedIndex = 0; } // Show the window this.ShowDialog(); // If we selected a layer and clicked OK, load the locations if (m_okClicked && (cboInputData.SelectedIndex >= 0)) { // Get a cursor on the source display table (either though the selection set or table) // Use IDisplayTable because it accounts for joins, querydefs, etc. // IDisplayTable is implemented by FeatureLayers and StandaloneTables. // IDisplayTable displayTable = m_listDisplayTable[cboInputData.SelectedIndex] as IDisplayTable; ICursor cursor; if (chkUseSelection.Checked) { ISelectionSet selSet; selSet = displayTable.DisplaySelectionSet; selSet.Search(null, false, out cursor); } else { cursor = displayTable.SearchDisplayTable(null, false); } // Setup NAClassLoader and Load Locations INAClassLoader2 naClassLoader = new NAClassLoader() as INAClassLoader2; naClassLoader.Initialize(naContext, naDataset.Name, cursor); // Avoid loading network locations onto non-traversable portions of elements INALocator3 locator = naContext.Locator as INALocator3; locator.ExcludeRestrictedElements = true; locator.CacheRestrictedElements(naContext); int rowsIn = 0; int rowsLocated = 0; naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated); return(true); } return(false); }
//װ���������Ԫ�ص�λ�� private void LoadNANetworkLocations(string strNAClassName, IFeatureClass inputFC, double snapTolerance) { INAClass naClass; INamedSet classes; classes = m_NAContext.NAClasses; naClass = classes.get_ItemByName(strNAClassName) as INAClass; // delete existing Locations except if that a barriers naClass.DeleteAllRows(); // Create a NAClassLoader and set the snap tolerance (meters unit) INAClassLoader classLoader = new NAClassLoader(); classLoader.Locator = m_NAContext.Locator; if (snapTolerance > 0) classLoader.Locator.SnapTolerance = snapTolerance; classLoader.NAClass = naClass; //Create field map to automatically map fields from input class to naclass INAClassFieldMap fieldMap; fieldMap = new NAClassFieldMap(); fieldMap.CreateMapping(naClass.ClassDefinition, inputFC.Fields); classLoader.FieldMap = fieldMap; //Load Network Locations int rowsIn = 0; int rowsLocated = 0; IFeatureCursor featureCursor = inputFC.Search(null, true); classLoader.Load((ICursor)featureCursor, null, ref rowsIn, ref rowsLocated); }
public bool ShowModal(IMapControl3 mapControl, IEngineNetworkAnalystEnvironment naEnv) { // Initialize variables m_okClicked = false; m_lstLayers = new System.Collections.ArrayList(); this.Text = "Load Locations into " + naEnv.NAWindow.ActiveCategory.Layer.Name; // Loop through all the layers, adding the point feature layers to the combo box and array IEnumLayer layers = mapControl.Map.get_Layers(null, true); ILayer layer; layer = layers.Next(); while (layer != null) { IFeatureLayer fLayer = layer as IFeatureLayer; IDisplayTable displayTable = layer as IDisplayTable; if ((fLayer != null) && (displayTable != null)) { IFeatureClass fClass = fLayer.FeatureClass; if (fClass.ShapeType == esriGeometryType.esriGeometryPoint) { // Add the layer name to the combobox and the layer to the list cboPointLayers.Items.Add(layer.Name); m_lstLayers.Add(layer); } } layer = layers.Next(); } //Select the first point feature layer from the list if (cboPointLayers.Items.Count > 0) cboPointLayers.SelectedIndex = 0; // Show the window this.ShowDialog(); // If we selected a layer and clicked OK, load the locations if (m_okClicked && (cboPointLayers.SelectedIndex >= 0)) { // Get the NALayer and NAContext INALayer naLayer = naEnv.NAWindow.ActiveAnalysis; INAContext naContext = naLayer.Context; //Get the active category IEngineNAWindowCategory activeCategory = naEnv.NAWindow.ActiveCategory; INAClass naClass = activeCategory.NAClass; IDataset naDataset = naClass as IDataset; // Get a cursor to the input features (either though the selection set or table) // Use IDisplayTable because it accounts for joins, querydefs, etc. IDisplayTable displayTable = m_lstLayers[cboPointLayers.SelectedIndex] as IDisplayTable; ICursor cursor; if (chkUseSelectedFeatures.Checked) { ISelectionSet selSet; selSet = displayTable.DisplaySelectionSet; selSet.Search(null, false, out cursor); } else { cursor = displayTable.SearchDisplayTable(null, false); } // Setup NAClassLoader and Load Locations INAClassLoader2 naClassLoader = new NAClassLoader() as INAClassLoader2; naClassLoader.Initialize(naContext, naDataset.Name, cursor); int rowsIn = 0; int rowsLocated = 0; naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated); return true; } else { return false; } }
public bool ShowModal(IMapControl3 mapControl, IEngineNetworkAnalystEnvironment naEnv) { // Initialize variables m_okClicked = false; m_lstLayers = new System.Collections.ArrayList(); this.Text = "Load Locations into " + naEnv.NAWindow.ActiveCategory.Layer.Name; // Loop through all the layers, adding the point feature layers to the combo box and array IEnumLayer layers = mapControl.Map.get_Layers(null, true); ILayer layer; layer = layers.Next(); while (layer != null) { IFeatureLayer fLayer = layer as IFeatureLayer; IDisplayTable displayTable = layer as IDisplayTable; if ((fLayer != null) && (displayTable != null)) { IFeatureClass fClass = fLayer.FeatureClass; if (fClass.ShapeType == esriGeometryType.esriGeometryPoint) { // Add the layer name to the combobox and the layer to the list cboPointLayers.Items.Add(layer.Name); m_lstLayers.Add(layer); } } layer = layers.Next(); } //Select the first point feature layer from the list if (cboPointLayers.Items.Count > 0) { cboPointLayers.SelectedIndex = 0; } // Show the window this.ShowDialog(); // If we selected a layer and clicked OK, load the locations if (m_okClicked && (cboPointLayers.SelectedIndex >= 0)) { // Get the NALayer and NAContext INALayer naLayer = naEnv.NAWindow.ActiveAnalysis; INAContext naContext = naLayer.Context; //Get the active category IEngineNAWindowCategory activeCategory = naEnv.NAWindow.ActiveCategory; INAClass naClass = activeCategory.NAClass; IDataset naDataset = naClass as IDataset; // Get a cursor to the input features (either though the selection set or table) // Use IDisplayTable because it accounts for joins, querydefs, etc. IDisplayTable displayTable = m_lstLayers[cboPointLayers.SelectedIndex] as IDisplayTable; ICursor cursor; if (chkUseSelectedFeatures.Checked) { ISelectionSet selSet; selSet = displayTable.DisplaySelectionSet; selSet.Search(null, false, out cursor); } else { cursor = displayTable.SearchDisplayTable(null, false); } // Setup NAClassLoader and Load Locations INAClassLoader2 naClassLoader = new NAClassLoader() as INAClassLoader2; naClassLoader.Initialize(naContext, naDataset.Name, cursor); int rowsIn = 0; int rowsLocated = 0; naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated); return(true); } else { return(false); } }