/// <summary>
        /// GetTraversalResultLayer will generate a layer out of the traversal result for the specified element type
        /// </summary>
        private IFeatureLayer GetTraversalResultLayer(esriNetworkElementType elementType, INATraversalResultQuery2 naTraversalResultQuery)
        {
            //Junctions Traversal Result Feature Layer
            IFeatureClass traversalResultFeatureClass = naTraversalResultQuery.get_FeatureClass(elementType);

            if (traversalResultFeatureClass != null)
            {
                // save the rows in this class out when the MXD is saved
                INAClass naClass = traversalResultFeatureClass as INAClass;
                naClass.SaveRowsOnPersist = true;

                // create the traversal result layer
                IFeatureLayer traversalResultLayer = new FeatureLayerClass();
                traversalResultLayer.FeatureClass = traversalResultFeatureClass;
                traversalResultLayer.Name         = traversalResultFeatureClass.AliasName;

                // Set up the layer with an appropriate symbology
                var geoFeatureLayer = traversalResultLayer as IGeoFeatureLayer;
                geoFeatureLayer.RendererPropertyPageClassID = (new SingleSymbolPropertyPageClass()).ClassID;
                geoFeatureLayer.Renderer = GetRenderer(elementType);

                return(traversalResultLayer);
            }
            return(null);
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: zyyfix/ArcEngine-WGIS
        /// <summary>
        /// 清除路径和图层信息
        /// </summary>
        private void menuEndRoute_Click(object sender, EventArgs e)
        {
            //解决完后,删除图层内容
            ITable pTable_inputFClass = pPathFinder.inputFClass as ITable;

            pTable_inputFClass.DeleteSearchedRows(null);
            //删除上一次路径route网络上下文
            IFeatureClass routesFC;

            routesFC = pPathFinder.m_NAContext.NAClasses.get_ItemByName("Routes") as IFeatureClass;
            ITable pTable1 = routesFC as ITable;

            pTable1.DeleteSearchedRows(null);
            //删除上一次路径Stops网络上下文
            INAClass stopsNAClass = pPathFinder.m_NAContext.NAClasses.get_ItemByName("Stops") as INAClass;
            ITable   ptable2      = stopsNAClass as ITable;

            ptable2.DeleteSearchedRows(null);
            //删除上一次barries网络上下文
            INAClass barriesNAClass = pPathFinder.m_NAContext.NAClasses.get_ItemByName("Barriers") as INAClass;
            ITable   pTable3        = barriesNAClass as ITable;

            pTable3.DeleteSearchedRows(null);
            pPathFinder.PGC.DeleteAllElements();
            pPathFinder.clickedcount = 0;
            axMapControl1.Refresh();
        }
コード例 #3
0
        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);
        }
		/// <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();
        }
コード例 #5
0
        public void LoadNANetworkLocations(string strNAClassName, IFeatureClass pInputFC, double SnapTolerance)
        {
            INAClass class2 = this.m_pNAContext.NAClasses.get_ItemByName(strNAClassName) as INAClass;

            class2.DeleteAllRows();
            INAClassLoader loader = new NAClassLoaderClass
            {
                Locator = this.m_pNAContext.Locator
            };

            if (SnapTolerance > 0.0)
            {
                loader.Locator.SnapTolerance = SnapTolerance;
            }
            loader.NAClass = class2;
            INAClassFieldMap map = new NAClassFieldMapClass();

            map.CreateMapping(class2.ClassDefinition, pInputFC.Fields);
            loader.FieldMap = map;
            int            rowsInCursor = 0;
            int            rowsLocated  = 0;
            IFeatureCursor cursor       = pInputFC.Search(null, true);

            loader.Load((ICursor)cursor, null, ref rowsInCursor, ref rowsLocated);
        }
コード例 #6
0
        private void clearAll()
        {
            global.networkAnalysis = false;
            pMainForm.getMainAxMapControl().CurrentTool = null;
            ITable pTable = global.inputFClass as ITable;

            pTable.DeleteSearchedRows(null);
            //提取路径前,删除上一次路径route网络上下文
            IFeatureClass routesFC;

            routesFC = global.m_NAContext.NAClasses.get_ItemByName("Routes") as IFeatureClass;
            ITable pTable1 = routesFC as ITable;

            pTable1.DeleteSearchedRows(null);
            //提取路径前,删除上一次路径Stops网络上下文
            INAClass stopsNAClass = global.m_NAContext.NAClasses.get_ItemByName("Stops") as INAClass;
            ITable   ptable2      = stopsNAClass as ITable;

            ptable2.DeleteSearchedRows(null);
            //提取路径前,删除上一次barries网络上下文
            INAClass barriesNAClass = global.m_NAContext.NAClasses.get_ItemByName("Barriers") as INAClass;
            ITable   pTable3        = barriesNAClass as ITable;

            pTable3.DeleteSearchedRows(null);
            global.PGC.DeleteAllElements();
            global.clickedcount = 0;
            (global.p2DMap as IActiveView).Refresh();
        }
コード例 #7
0
ファイル: exportForm.cs プロジェクト: uwmyuan/EVDS
        private bool LoadLocations(IFeatureWorkspace featureWorkspace)
        {
            IFeatureClass inputFeatureClass = null;

            try
            {
                inputFeatureClass = featureWorkspace.OpenFeatureClass(txtInputFacilities.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Specified input feature class does not exist");
                return(false);
            }

            INamedSet classes = m_naContext.NAClasses;
            INAClass  naClass = classes.get_ItemByName("Facilities") as INAClass;

            // delete existing locations, except barriers
            naClass.DeleteAllRows();

            // Create a NAClassLoader and set the snap tolerance (meters unit)
            INAClassLoader naClassLoader = new NAClassLoaderClass();

            naClassLoader.Locator = m_naContext.Locator;
            naClassLoader.Locator.SnapTolerance = 100;
            naClassLoader.NAClass = naClass;

            // Create field map to automatically map fields from input class to NAClass
            INAClassFieldMap naClassFieldMap = new NAClassFieldMapClass();

            naClassFieldMap.CreateMapping(naClass.ClassDefinition, inputFeatureClass.Fields);
            naClassLoader.FieldMap = naClassFieldMap;

            // 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;

            naClassLoader.Load(inputFeatureClass.Search(null, true) as ICursor, null, ref rowsIn, ref rowsLocated);

            if (rowsLocated <= 0)
            {
                MessageBox.Show("Facilities were not loaded from input feature class");
                MessageBox.Show("没有导入任何结果!");
                return(false);
            }

            // Message all of the network analysis agents that the analysis context has changed
            INAContextEdit naContextEdit = m_naContext as INAContextEdit;

            naContextEdit.ContextChanged();

            return(true);
        }
コード例 #8
0
        /// <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");
        }
コード例 #9
0
ファイル: NetWorkAnalysClass.cs プロジェクト: crt106/WhuGIS
        /// <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();
        }
コード例 #10
0
        /// <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();
        }
コード例 #11
0
        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);
                }
            }
        }
コード例 #12
0
ファイル: RouteClass.cs プロジェクト: secondii/Yutai
        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");
        }
コード例 #13
0
ファイル: frmLoadLocation.cs プロジェクト: Leopold-Z/Test
        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);
        }
コード例 #14
0
        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
            var 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;
            }

            ESRI.ArcGIS.Controls.IEngineNAWindowCategory naWindowCategory = naEnv.NAWindow.ActiveCategory;
            if (naWindowCategory == null)
            {
                MessageBox.Show("Error: There is no active category for the NAWindow");
                return;
            }

            INAClass naClass = naWindowCategory.NAClass;

            if (naClass == null)
            {
                MessageBox.Show("Error: There is no NAClass for the active category");
                return;
            }

            INAClassDefinition naClassDefinition = naClass.ClassDefinition;

            if (naClassDefinition == null)
            {
                MessageBox.Show("Error: NAClassDefinition is null for the active NAClass");
                return;
            }

            if (!naClassDefinition.IsInput)
            {
                MessageBox.Show("Error: Locations can only be loaded into an input NAClass");
                return;
            }

            // Set the Active Analysis layer to be the layer right-clicked on
            naEnv.NAWindow.ActiveAnalysis = naLayer;

            // Show the Property Page form for ArcGIS Network Analyst extension
            var loadLocations = new frmLoadLocations();

            if (loadLocations.ShowModal(m_mapControl, naEnv))
            {
                // Notify that the context has changed, because we have added locations to a NAClass within it
                var contextEdit = naEnv.NAWindow.ActiveAnalysis.Context as INAContextEdit;
                contextEdit.ContextChanged();

                // Refresh the NAWindow and the map
                m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, m_mapControl.Extent);
                naEnv.NAWindow.UpdateContent(naEnv.NAWindow.ActiveCategory);
            }
        }
コード例 #15
0
        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);
            }
        }