private void FormMain_Load(object sender, EventArgs e) { Ctrl_Tab.SelectedIndex = 1; Ctrl_Tab.SelectedIndex = 0; IFeatureWorkspace pFWorkspace = OpenWorkspace(@"data.gdb") as IFeatureWorkspace; INetworkDataset networkDataset = OpenNetworkDataset(pFWorkspace as IWorkspace, "rdCenLineDataSet_ND", "rdCenLineDataSet"); m_NAContext = CreateSolverContext(networkDataset); INetworkLayer pNetworkLayer = new NetworkLayerClass(); pNetworkLayer.NetworkDataset = networkDataset; ILayer pLayer = pNetworkLayer as ILayer; pLayer.Name = "NetworkLayer"; Ctrl_Map.AddLayer(pLayer, 0); IFeatureLayer pJunctionLayer = new FeatureLayerClass(); pJunctionLayer.FeatureClass = pFWorkspace.OpenFeatureClass("rdCenLineDataSet_ND_Junctions"); pJunctionLayer.Name = pJunctionLayer.FeatureClass.AliasName; Ctrl_Map.AddLayer(pJunctionLayer, 0); IFeatureLayer pRoadLayer = new FeatureLayerClass(); pRoadLayer.FeatureClass = pFWorkspace.OpenFeatureClass("road_toLine"); pRoadLayer.Name = pRoadLayer.FeatureClass.AliasName; Ctrl_Map.AddLayer(pRoadLayer, 0); INALayer pNALayer = m_NAContext.Solver.CreateLayer(m_NAContext); (pNALayer as ILayer).Name = m_NAContext.Solver.DisplayName; Ctrl_Map.AddLayer(pNALayer as ILayer, 0); }
private INALayer CreateRouteAnalysisLayer(string sName, INetworkDataset pNetworkDataset) { INARouteSolver solver = new NARouteSolverClass(); INASolverSettings settings = solver as INASolverSettings; INASolver solver2 = solver as INASolver; solver.FindBestSequence = true; solver.PreserveFirstStop = true; solver.PreserveLastStop = false; solver.UseTimeWindows = false; solver.OutputLines = esriNAOutputLineType.esriNAOutputLineTrueShapeWithMeasure; IStringArray restrictionAttributeNames = settings.RestrictionAttributeNames; restrictionAttributeNames.Add("Oneway"); settings.RestrictionAttributeNames = restrictionAttributeNames; IDatasetComponent component = pNetworkDataset as IDatasetComponent; IDENetworkDataset dataElement = component.DataElement as IDENetworkDataset; INAContext context = solver2.CreateContext(dataElement, sName); (context as INAContextEdit).Bind(pNetworkDataset, new GPMessagesClass()); INALayer layer = solver2.CreateLayer(context); (layer as ILayer).Name = sName; return(layer); }
public static bool AddLocation(INALayer layer, string locationClassName, IPoint point, string locationName, StringObjectDictionary locationProperties, double tolerance) { INALocator locator = layer.Context.Locator; locator.SnapTolerance = tolerance; INALocation location = null; IPoint outPoint = null; double distanceFromPoint = 0.0; locator.QueryLocationByPoint(point, ref location, ref outPoint, ref distanceFromPoint); INAClass class2 = layer.Context.NAClasses.get_ItemByName(locationClassName) as INAClass; IFeatureClass class3 = class2 as IFeatureClass; IFeature feature = class3.CreateFeature(); feature.Shape = point; int num2 = class3.FeatureCount(null); int index = -1; IClass class4 = class3; INALocationObject obj2 = feature as INALocationObject; obj2.NALocation = location; index = class4.FindField(NetworkConstants.NAME_FIELD); if (locationName.Trim().Length > 0) { feature.set_Value(index, locationName); } index = class4.FindField(NetworkConstants.SEQUENCE_FIELD); if (index >= 0) { feature.set_Value(index, num2); } index = class4.FindField(NetworkConstants.STATUS_FIELD); if (location.IsLocated) { feature.set_Value(index, 0); } else { feature.set_Value(index, 1); } if ((locationProperties != null) && (locationProperties.Count > 0)) { IEnumerator enumerator = locationProperties.Keys.GetEnumerator(); while (enumerator.MoveNext()) { string current = enumerator.Current as string; if ((current != null) && (current.Length > 0)) { index = class4.FindField(current); if (index != -1) { feature.set_Value(index, locationProperties[current]); } } } } feature.Store(); return(location.IsLocated); }
public bool ShowModal(INALayer naLayer) { m_okClicked = false; // Get the NAContext and NetworkDataset INAContext naContext = naLayer.Context; INetworkDataset networkDataset = naContext.NetworkDataset; // Setup the window based on the current NALayer settings PopulateControls(naLayer); tabPropPages.SelectedIndex = 1; this.Text = ((ILayer)naLayer).Name + " Properties"; this.ShowDialog(); if (m_okClicked) { // Update the layer properties based on the items chosen UpdateNALayer(naLayer); // Update the Context so it can respond to changes made to the solver settings IGPMessages gpMessages = new GPMessagesClass(); IDENetworkDataset deNetworkDataset = ((IDatasetComponent)networkDataset).DataElement as IDENetworkDataset; naContext.Solver.UpdateContext(naContext, deNetworkDataset, gpMessages); } return(m_okClicked); }
public static void GetPermittedAttributes(INALayer layer, out string[] impedences, out string[] restrictions, out string[] hierarchies) { ArrayList list = new ArrayList(); ArrayList list2 = new ArrayList(); ArrayList list3 = new ArrayList(); INetworkDataset networkDataset = layer.Context.NetworkDataset; for (int i = 0; i < networkDataset.AttributeCount; i++) { INetworkAttribute attribute = networkDataset.get_Attribute(i); if (attribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost) { list.Add(attribute.Name); } else if (attribute.UsageType == esriNetworkAttributeUsageType.esriNAUTRestriction) { list2.Add(attribute.Name); } else if (attribute.UsageType == esriNetworkAttributeUsageType.esriNAUTHierarchy) { list3.Add(attribute.Name); } } impedences = (string[])list.ToArray(typeof(string)); restrictions = (string[])list2.ToArray(typeof(string)); hierarchies = (string[])list3.ToArray(typeof(string)); }
/// <summary> /// To open the editor form, we need to first determine which barrier is /// being edited, then pass that value to the form /// </summary> private void OpenBarrierEditorForm() { // get the barrier layer by using the category name to as the NAClassName INAWindowCategory activeCategory = GetActiveCategory(); string categoryName = activeCategory.NAClass.ClassDefinition.Name; INALayer naLayer = GetActiveAnalysisLayer(); ILayer layer = naLayer.get_LayerByNAClassName(categoryName); // get a selection count and popup a message if more or less than one item is selected IFeatureSelection fSel = layer as IFeatureSelection; ISelectionSet selSet = fSel.SelectionSet; if (selSet.Count != 1) { System.Windows.Forms.MessageBox.Show("Only one barrier in a category can be selected at a time for this command to execute", "Barrier Location Editor Warning"); } else { // get the object IDs of the selected item int id = selSet.IDs.Next(); // Get the barrier feature by using the selected ID IFeatureClass fClass = naLayer.Context.NAClasses.get_ItemByName(categoryName) as IFeatureClass; IFeature barrierFeature = fClass.GetFeature(id); // display the form for editing the barrier EditorForm form = new EditorForm(m_application, naLayer.Context, barrierFeature); form.ShowDialog(); form = null; } }
public void ClearRouteAnalyst(AxMapControl mapControl) { //清除所有图标 SymbolUtil.ClearElement(mapControl); stopPoints.Clear(); barryPoints.Clear(); barryElements.Clear(); stopElements.Clear(); //清除网络分析图层 for (int i = 0; i < mapControl.LayerCount; i++) { ILayer layer = mapControl.get_Layer(i); INetworkLayer networkLayer = layer as INetworkLayer; INALayer naLayer = layer as INALayer; if (networkLayer != null || naLayer != null) { mapControl.DeleteLayer(i); } } //清除网络数据集 ILayer datalayer = LayerUtil.QueryLayerInMap(mapControl, "网络数据集"); if (datalayer != null) { mapControl.Map.DeleteLayer(datalayer); } IActiveView pActiveView = mapControl.ActiveView; pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); mapControl.Refresh(); }
public override void OnClick() { // Get the NALayer and corresponding NAContext of the layer that // was right-clicked on in the table of contents // m_MapControl.CustomProperty was set in frmMain.axTOCControl1_OnMouseDown INALayer naLayer = (INALayer)m_mapControl.CustomProperty; // Set the Active Analysis layer to be the layer right-clicked on m_naEnv.NAWindow.ActiveAnalysis = naLayer; if (!Enabled) { return; } // Show the Property Page form for Network Analyst frmLoadLocations loadLocations = new frmLoadLocations(); if (loadLocations.ShowModal(m_mapControl, m_naEnv)) { // If loaded locations, refresh the NAWindow and the Screen m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, m_mapControl.Extent); m_naEnv.NAWindow.UpdateContent(m_naEnv.NAWindow.ActiveCategory); } }
public ILayer GetNetworkAnalysisLayer() { INALayer naLayer = m_NAContext.Solver.CreateLayer(m_NAContext); ILayer layer = naLayer as ILayer; layer.Name = m_NAContext.Solver.DisplayName; return(layer); }
/// <summary> /// Create the analysis layer, load the locations, solve the analysis, and write to disk /// </summary> public void SolveRoute() { // Open the feature workspace, input feature class, and network dataset // As Workspace Factories are Singleton objects, they must be instantiated with the Activator IWorkspaceFactory workspaceFactory = System.Activator.CreateInstance(System.Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory")) as IWorkspaceFactory; IFeatureWorkspace featureWorkspace = workspaceFactory.OpenFromFile(Application.StartupPath + FGDB_WORKSPACE, 0) as IFeatureWorkspace; IFeatureClass inputStopsFClass = featureWorkspace.OpenFeatureClass(INPUT_STOPS_FC); // Obtain the dataset container from the workspace ESRI.ArcGIS.Geodatabase.IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset(FEATURE_DATASET); var featureDatasetExtensionContainer = featureDataset as ESRI.ArcGIS.Geodatabase.IFeatureDatasetExtensionContainer; ESRI.ArcGIS.Geodatabase.IFeatureDatasetExtension featureDatasetExtension = featureDatasetExtensionContainer.FindExtension(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTNetworkDataset); var datasetContainer3 = featureDatasetExtension as ESRI.ArcGIS.Geodatabase.IDatasetContainer3; // Use the container to open the network dataset. ESRI.ArcGIS.Geodatabase.IDataset dataset = datasetContainer3.get_DatasetByName(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTNetworkDataset, NETWORK_DATASET); INetworkDataset networkDataset = dataset as INetworkDataset; // Create the Route NALayer INALayer naLayer = CreateRouteAnalysisLayer("Route", networkDataset); INAContext naContext = naLayer.Context; INAClass stopsNAClass = naContext.NAClasses.get_ItemByName("Stops") as INAClass; IFeatureClass routesFC = naContext.NAClasses.get_ItemByName("Routes") as IFeatureClass; // Load the Stops INAClassFieldMap naClassFieldMap = new NAClassFieldMapClass(); naClassFieldMap.set_MappedField("Name", INPUT_NAME_FIELD); INAClassLoader naLoader = new NAClassLoaderClass(); naLoader.Locator = naContext.Locator; naLoader.NAClass = stopsNAClass; naLoader.FieldMap = naClassFieldMap; // Avoid loading network locations onto non-traversable portions of elements INALocator3 locator = naContext.Locator as INALocator3; locator.ExcludeRestrictedElements = true; locator.CacheRestrictedElements(naContext); int rowsInCursor = 0; int rowsLocated = 0; naLoader.Load(inputStopsFClass.Search(new QueryFilterClass(), false) as ICursor, new CancelTrackerClass(), ref rowsInCursor, ref rowsLocated); //Message all of the network analysis agents that the analysis context has changed ((INAContextEdit)naContext).ContextChanged(); //Solve INASolver naSolver = naContext.Solver; naSolver.Solve(naContext, new GPMessagesClass(), new CancelTrackerClass()); //Save the layer to disk SaveLayerToDisk(naLayer as ILayer, System.Environment.CurrentDirectory + @"\Route.lyr"); }
/// <summary> /// Occurs in determining whether or not to include the command as a context menu item /// <param name="naLayer">The active analysis layer</param> /// <param name="categoryGroup">The selected group in the NAWindow</param> /// </summary> bool INAWindowCommand2.AppliesToGroup(INALayer naLayer, INAWindowCategoryGroup categoryGroup) { if (categoryGroup != null) { return(Applies(naLayer, categoryGroup.Category)); } return(false); }
private void clearLocationsToolStripMenuItem_Click(object sender, EventArgs e) { IMapControl3 mapControl = (IMapControl3)axMapControl1.Object; IEngineNetworkAnalystHelper naHelper = m_naEnv as IEngineNetworkAnalystHelper; IEngineNAWindow naWindow = m_naWindow; INALayer naLayer = naWindow.ActiveAnalysis; naHelper.DeleteAllNetworkLocations(); mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, mapControl.Extent); }
public override void OnClick() { if (m_mapControl == null) { MessageBox.Show("Error: Map control is null for this command"); return; } // Get the NALayer and corresponding NAContext of the layer that // was right-clicked on in the table of contents // m_MapControl.CustomProperty was set in frmMain.axTOCControl1_OnMouseDown INALayer naLayer = m_mapControl.CustomProperty as INALayer; if (naLayer == null) { MessageBox.Show("Error: NALayer was not set as the CustomProperty of the map control"); return; } var naEnv = CommonFunctions.GetTheEngineNetworkAnalystEnvironment(); if (naEnv == null || naEnv.NAWindow == null) { MessageBox.Show("Error: EngineNetworkAnalystEnvironment is not properly configured"); return; } // Set the active Analysis layer IEngineNAWindow naWindow = naEnv.NAWindow; if (naWindow.ActiveAnalysis != naLayer) { naWindow.ActiveAnalysis = naLayer; } // Remember what the current category is IEngineNAWindowCategory originalCategory = naWindow.ActiveCategory; // Loop through deleting all the items from all the categories INamedSet naClasses = naLayer.Context.NAClasses; var naHelper = naEnv as IEngineNetworkAnalystHelper; for (int i = 0; i < naClasses.Count; i++) { IEngineNAWindowCategory category = naWindow.get_CategoryByNAClassName(naClasses.get_Name(i)); naWindow.ActiveCategory = category; naHelper.DeleteAllNetworkLocations(); } //Reset to the original category naWindow.ActiveCategory = originalCategory; // Redraw the map m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, m_mapControl.Extent); }
/// <summary> /// Initialize the solver by calling the ArcGIS Network Analyst extension functions. /// </summary> private void Initialize() { IFeatureWorkspace featureWorkspace = null; INetworkDataset networkDataset = null; try { // Open the Network Dataset IWorkspace workspace = OpenWorkspace(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"ArcGIS\data\SanFrancisco\SanFrancisco.gdb")); networkDataset = OpenNetworkDataset(workspace, "Transportation", "Streets_ND"); featureWorkspace = workspace as IFeatureWorkspace; } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Unable to open dataset. Error Message: " + ex.Message); this.Close(); return; } // Create NAContext and NASolver m_NAContext = CreateSolverContext(networkDataset); // Get available cost attributes from the network dataset INetworkAttribute networkAttribute; for (int i = 0; i < networkDataset.AttributeCount - 1; i++) { networkAttribute = networkDataset.get_Attribute(i); if (networkAttribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost) { comboCostAttribute.Items.Add(networkAttribute.Name); } } comboCostAttribute.SelectedIndex = 0; textTargetFacility.Text = ""; textCutoff.Text = ""; // Load locations from feature class IFeatureClass inputFClass = featureWorkspace.OpenFeatureClass("Stores"); LoadNANetworkLocations("Origins", inputFClass, 100); inputFClass = featureWorkspace.OpenFeatureClass("Hospitals"); LoadNANetworkLocations("Destinations", inputFClass, 5100); // Create layer for network dataset and add to ArcMap INetworkLayer networkLayer = new NetworkLayerClass(); networkLayer.NetworkDataset = networkDataset; var layer = networkLayer as ILayer; layer.Name = "Network Dataset"; axMapControl.AddLayer(layer, 0); // Create a network analysis layer and add to ArcMap INALayer naLayer = m_NAContext.Solver.CreateLayer(m_NAContext); layer = naLayer as ILayer; layer.Name = m_NAContext.Solver.DisplayName; axMapControl.AddLayer(layer, 0); }
private void miClearLocations_Click(object sender, System.EventArgs e) { var mapControl = axMapControl1.Object as IMapControl3; var naHelper = m_naEnv as IEngineNetworkAnalystHelper; IEngineNAWindow naWindow = m_naWindow; INALayer naLayer = naWindow.ActiveAnalysis; // we do not have to run ContextChanged() as with adding an item and loading locations, // because that is done by the DeleteAllNetworkLocations method. naHelper.DeleteAllNetworkLocations(); mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, mapControl.Extent); }
public bool Applies(INALayer naLayer, INAWindowCategory category) { // The category is associated with an NAClass. // In our case, we want the PolygonBarriers and PolylineBarriers classes if (category != null) { string categoryName = category.NAClass.ClassDefinition.Name; if (categoryName == "PolygonBarriers" || categoryName == "PolylineBarriers") { return(true); } } return(false); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // Show the Property Page form for the NALayer // Get the NALayer that was right-clicked on in the table of contents // m_MapControl.CustomProperty was set in frmMain.axTOCControl1_OnMouseDown INALayer naLayer = (INALayer)m_mapControl.CustomProperty; frmNALayerProperties props = new frmNALayerProperties(); if (props.ShowModal(naLayer)) { // Notify the ActiveView that the contents have changed so the TOC and NAWindow know to refresh themselves. m_mapControl.ActiveView.ContentsChanged(); } }
private void miLoadLocations_Click(object sender, System.EventArgs e) { IMapControl3 mapControl = (IMapControl3)axMapControl1.Object; // 显示网络分析的属性页窗体 frmLoadLocations loadLocations = new frmLoadLocations(); if (loadLocations.ShowModal(mapControl, m_naEnv)) { // 上下文已更改,已将位置添加到其中的一个naclass INAContextEdit contextEdit = m_naEnv.NAWindow.ActiveAnalysis.Context as INAContextEdit; contextEdit.ContextChanged(); // 如果加载,刷新NAWindow屏幕 INALayer naLayer = m_naWindow.ActiveAnalysis; mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, mapControl.Extent); m_naWindow.UpdateContent(m_naWindow.ActiveCategory); } }
private void miLoadLocations_Click(object sender, System.EventArgs e) { var mapControl = axMapControl1.Object as IMapControl3; // Show the Property Page form for ArcGIS Network Analyst extension var loadLocations = new frmLoadLocations(); if (loadLocations.ShowModal(mapControl, m_naEnv)) { // notify that the context has changed because we have added locations to a NAClass within it var contextEdit = m_naEnv.NAWindow.ActiveAnalysis.Context as INAContextEdit; contextEdit.ContextChanged(); // If loaded locations, refresh the NAWindow and the Screen INALayer naLayer = m_naWindow.ActiveAnalysis; mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, mapControl.Extent); m_naWindow.UpdateContent(m_naWindow.ActiveCategory); } }
public static INALayer CreateNetworkAnalysisLayer(string name, INetworkDataset networkDataset, INASolver naSolver) { if (naSolver is INARouteSolver) { return(CreateRouteAnalysisLayer(name, networkDataset, naSolver as INARouteSolver)); } if (naSolver is INAClosestFacilitySolver) { return(CreateClosestFacilityLayer(name, networkDataset, naSolver as INAClosestFacilitySolver)); } IDatasetComponent component = (IDatasetComponent)networkDataset; IDENetworkDataset dataElement = (IDENetworkDataset)component.DataElement; INAContext context = naSolver.CreateContext(dataElement, name); ((INAContextEdit)context).Bind(networkDataset, null); INALayer layer = naSolver.CreateLayer(context); ((ILayer)layer).Name = name; return(layer); }
public static void GetClasses(INALayer layer, out NameValueCollection inputClasses, out NameValueCollection outputClasses) { INamedSet nAClasses = layer.Context.NAClasses; inputClasses = new NameValueCollection(); outputClasses = new NameValueCollection(); for (int i = 0; i < nAClasses.Count; i++) { INAClass class2 = nAClasses.get_Item(i) as INAClass; string name = class2.ClassDefinition.Name; string str2 = layer.get_LayerByNAClassName(name).Name; if (class2.ClassDefinition.IsInput) { inputClasses.Add(str2, name); } else { outputClasses.Add(str2, name); } } }
/// <summary> /// OnClick is the main function for the add-in. When the button is clicked in ArcMap, /// this code will execute /// </summary> protected override void OnClick() { // Verify that the network extension has been loaded properly. var naExt = ArcMap.Application.FindExtensionByName("Network Analyst") as INetworkAnalystExtension; if (naExt == null || naExt.NAWindow == null) { return; } // There must be an active analysis layer INALayer naLayer = naExt.NAWindow.ActiveAnalysis; if (naLayer == null || naLayer.Context == null) { return; } // Use the network layer factory to generate the layers ILayerFactory layerFactory = new EngineNetworkLayerFactoryClass(); var dataset = naLayer.Context.NetworkDataset as IDataset; if (layerFactory.get_CanCreate(dataset.FullName)) { // Calling create will open a popup asking the user if the network sources // should be added as well. If the user clicks NO, then the returned // IEnumLayer will only return a network layer for the network dataset. // If the user clicks YES, then IEnumLayer will also return layers for // the network sources IEnumLayer enumLayer = layerFactory.Create(dataset.FullName); ILayer layer = enumLayer.Next(); while (layer != null) { ArcMap.Document.FocusMap.AddLayer(layer); layer = enumLayer.Next(); } } }
private void UpdateSelectionEIDArrayParameterValues() { IMap map = ActiveMap; if (map == null) { return; } INAWindow naWindow = m_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; } string baseName = SubsetHelperUI.SelectionEIDArrayBaseName; VarType vt = SubsetHelperUI.GetEIDArrayParameterType(); List <string> sourceNames = SubsetHelperUI.FindParameterizedSourceNames(nds, baseName, vt); Dictionary <string, ILongArray> oidArraysBySourceName = SubsetHelperUI.GetOIDArraysBySourceNameFromMapSelection(map, sourceNames); SubsetHelperUI.UpdateEIDArrayParameterValuesFromOIDArrays(m_nax, oidArraysBySourceName, baseName); }
private void UpdateGraphicsEIDArrayParameterValues() { IGraphicsContainer graphics = ActiveGraphics; if (graphics == null) { return; } INAWindow naWindow = m_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; } string baseName = SubsetHelperUI.GraphicsEIDArrayBaseName; VarType vt = SubsetHelperUI.GetEIDArrayParameterType(); List <string> sourceNames = SubsetHelperUI.FindParameterizedSourceNames(nds, baseName, vt); IGeometry searchGeometry = SubsetHelperUI.GetSearchGeometryFromGraphics(graphics); SubsetHelperUI.UpdateEIDArrayParameterValuesFromGeometry(m_nax, searchGeometry, baseName); }
private void Solve() { INALayer layer = this.CreateRouteAnalysisLayer("Route", this.m_pNetworkDataset); INAContext nAContext = layer.Context; INAClass class2 = nAContext.NAClasses.get_ItemByName("Stops") as INAClass; IFeatureClass class3 = nAContext.NAClasses.get_ItemByName("Routes") as IFeatureClass; INAClassFieldMap map = new NAClassFieldMapClass(); map.set_MappedField("Name", this.SHAPE_INPUT_NAME_FIELD); INAClassLoader loader = new NAClassLoaderClass { Locator = nAContext.Locator, NAClass = class2, FieldMap = map }; int rowsInCursor = 0; int rowsLocated = 0; loader.Load(this.m_pInputStopsFClass.Search(new QueryFilterClass(), false) as ICursor, new CancelTrackerClass(), ref rowsInCursor, ref rowsLocated); nAContext.Solver.Solve(nAContext, new GPMessagesClass(), new CancelTrackerClass()); this.SaveLayerToDisk(layer as ILayer, Environment.CurrentDirectory + @"\Route.lyr"); }
public static INALayer CreateClosestFacilityLayer(string layerName, INetworkDataset networkDataset, INAClosestFacilitySolver naClosesFacilitySolver) { INASolverSettings settings = naClosesFacilitySolver as INASolverSettings; INASolver solver = naClosesFacilitySolver as INASolver; IDatasetComponent component = networkDataset as IDatasetComponent; IDENetworkDataset dataElement = component.DataElement as IDENetworkDataset; INAContext context = solver.CreateContext(dataElement, layerName); (context as INAContextEdit).Bind(networkDataset, new GPMessagesClass()); INALayer layer = solver.CreateLayer(context); (layer as ILayer).Name = layerName; naClosesFacilitySolver.CreateTraversalResult = true; naClosesFacilitySolver.TravelDirection = esriNATravelDirection.esriNATravelDirectionFromFacility; naClosesFacilitySolver.OutputLines = esriNAOutputLineType.esriNAOutputLineTrueShapeWithMeasure; IStringArray restrictionAttributeNames = settings.RestrictionAttributeNames; restrictionAttributeNames.Add("Oneway"); settings.RestrictionAttributeNames = restrictionAttributeNames; solver.UpdateContext(context, dataElement, new GPMessagesClass()); return(layer); }
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 override void OnClick() { IEngineNetworkAnalystEnvironment naEnv = new EngineNetworkAnalystEnvironmentClass(); IEngineNetworkAnalystHelper naHelper = naEnv as IEngineNetworkAnalystHelper; IEngineNAWindow naWindow = naEnv.NAWindow; // Get the NALayer and corresponding NAContext of the layer that // was right-clicked on in the table of contents // m_MapControl.CustomProperty was set in frmMain.axTOCControl1_OnMouseDown INALayer naLayer = (INALayer)m_mapControl.CustomProperty; INAContext naContext = naLayer.Context; // Set the active Analysis layer if (naWindow.ActiveAnalysis != naLayer) { naWindow.ActiveAnalysis = naLayer; } // Remember what the current category is IEngineNAWindowCategory currentCategory = naWindow.ActiveCategory; // Loop through deleting all the items from all the categories INamedSet naClasses = naContext.NAClasses; for (int i = 0; i < naClasses.Count; i++) { IEngineNAWindowCategory category = naWindow.get_CategoryByNAClassName(naClasses.get_Name(i)); naWindow.ActiveCategory = category; naHelper.DeleteAllNetworkLocations(); } //Reset to the original category naWindow.ActiveCategory = currentCategory; m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, m_mapControl.Extent); }
public bool Applies(INALayer naLayer, INAWindowCategory Category) { return true; }
public bool Applies(INALayer naLayer, INAWindowCategory category) { // The category is associated with an NAClass. // In our case, we want the PolygonBarriers and PolylineBarriers classes if (category != null) { string categoryName = category.NAClass.ClassDefinition.Name; if (categoryName == "PolygonBarriers" || categoryName == "PolylineBarriers") return true; } return false; }
private void PopulateInputDataComboBox(IMapControl3 mapControl, IDataLayer dataLayer) { esriGeometryType targetGeoType = GetDataLayerGeometryType(dataLayer); IEnumLayer sourceLayers = null; ILayer sourceLayer = null; IDisplayTable sourceDisplayTable = null; UID searchInterfaceUID = new UID(); if (targetGeoType != esriGeometryType.esriGeometryNull) { // Only include layers that are of type IFeatureLayer searchInterfaceUID.Value = typeof(IFeatureLayer).GUID.ToString("B"); sourceLayers = mapControl.Map.get_Layers(searchInterfaceUID, true); // iterate over all of the feature layers sourceLayer = sourceLayers.Next(); while (sourceLayer != null) { // Verify that the layer is a feature layer and a display table IFeatureLayer sourceFeatureLayer = sourceLayer as IFeatureLayer; sourceDisplayTable = sourceLayer as IDisplayTable; if ((sourceFeatureLayer != null) && (sourceDisplayTable != null)) { // Make sure that the geometry of the feature layer matches the geometry // of the class into which we are loading 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(); } } // The layer being loaded into has no geometry type else { // Find all of the standalone table that are not part of an NALayer 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); } } // Find all of the standalone tables that are part of an NALayer 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(); } } }
/// <summary> /// Occurs in determining whether or not to include the command as a context menu item /// <param name="naLayer">The active analysis layer</param> /// <param name="categoryGroup">The selected group in the NAWindow</param> /// </summary> bool INAWindowCommand2.AppliesToGroup(INALayer naLayer, INAWindowCategoryGroup categoryGroup) { if (categoryGroup != null) { return Applies(naLayer, categoryGroup.Category); } return false; }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add ShortPathSolveCommand.OnClick implementation string name = NetWorkAnalysClass.getPath(path) + "\\data\\Geodatabase.gdb"; IFeatureWorkspace pFWorkspace = NetWorkAnalysClass.OpenWorkspace(name) as IFeatureWorkspace; //"RouteNetwork", "BaseData"参数不可更改 networkDataset = NetWorkAnalysClass.OpenPathNetworkDataset(pFWorkspace as IWorkspace, "RouteNetwork", "BaseData"); m_NAContext = NetWorkAnalysClass.CreatePathSolverContext(networkDataset); //通过网络数据集创建网络分析上下文 //打开要素数据集 inputFClass = pFWorkspace.OpenFeatureClass("Stops"); barriesFClass = pFWorkspace.OpenFeatureClass("Barries"); if (IfLayerExist("NetworkDataset") == false) { ILayer layer; INetworkLayer networkLayer; networkLayer = new NetworkLayerClass(); networkLayer.NetworkDataset = networkDataset; layer = networkLayer as ILayer; layer.Name = "NetworkDataset"; m_hookHelper.ActiveView.FocusMap.AddLayer(layer); layer.Visible = false; } if (IfLayerExist(m_NAContext.Solver.DisplayName) == true) { for (int i = 0; i < m_hookHelper.FocusMap.LayerCount; i++) { if (m_hookHelper.FocusMap.get_Layer(i).Name == m_NAContext.Solver.DisplayName) { m_hookHelper.FocusMap.DeleteLayer(m_hookHelper.FocusMap.get_Layer(i)); } } } INALayer naLayer = m_NAContext.Solver.CreateLayer(m_NAContext); ILayer pLayer = naLayer as ILayer; pLayer.Name = m_NAContext.Solver.DisplayName; m_hookHelper.ActiveView.FocusMap.AddLayer(pLayer); if (inputFClass.FeatureCount(null) < 2) { MessageBox.Show("只有一个站点,不能进行路径分析!"); return; } IGPMessages gpMessages = new GPMessagesClass(); //加载站点要素,并设置容差 NetWorkAnalysClass.LoadNANetworkLocations("Stops", inputFClass, m_NAContext, 80); //加载障碍点要素,并设置容差 NetWorkAnalysClass.LoadNANetworkLocations("Barriers", barriesFClass, m_NAContext, 5); INASolver naSolver = m_NAContext.Solver;//创建网络分析对象 try { naSolver.Solve(m_NAContext, gpMessages, null); } catch (Exception ex) { MessageBox.Show("未能找到有效路径" + ex.Message, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); return; } for (int i = 0; i < m_hookHelper.FocusMap.LayerCount; i++) { if (m_hookHelper.FocusMap.get_Layer(i).Name == m_NAContext.Solver.DisplayName) { ICompositeLayer pCompositeLayer = m_hookHelper.FocusMap.get_Layer(i) as ICompositeLayer; { for (int t = 0; t < pCompositeLayer.Count; t++) { ILayer pResultLayer = pCompositeLayer.get_Layer(t); if (pResultLayer.Name == "Stops" || pResultLayer.Name == "Barriers") { pResultLayer.Visible = false; continue; } } } } } IGeoDataset geoDataset; IEnvelope envelope; geoDataset = m_NAContext.NAClasses.get_ItemByName("Routes") as IGeoDataset; envelope = geoDataset.Extent; if (!envelope.IsEmpty) { envelope.Expand(1.1, 1.1, true); } m_hookHelper.ActiveView.Extent = envelope; m_hookHelper.ActiveView.Refresh(); }
private void 加载网络ToolStripMenuItem1_Click(object sender, EventArgs e) { IWorkspace pWs = GetMDBWorkspace(@".\data\Geometric.mdb"); IFeatureWorkspace pFtWs = pWs as IFeatureWorkspace; INetworkDataset pNetWorkDataset = GetNetDataset(pFtWs, "network", "network_ND"); pNASolveClass = new NARouteSolverClass(); loadNet(axMapControl1.Map, pNetWorkDataset); pNaContext = GetSolverContext(pNASolveClass, pNetWorkDataset); pNALayer = GetNaLayer(pNASolveClass, pNaContext); axMapControl1.Map.AddLayer(pNALayer as ILayer); }