视频图像处理系列索引 || Arcgis/Engine/Server开发索引 || Web Map Gis开发索引 || jquery表格组件 JQGrid索引
WPF MVVM模式开发实现简明教程索引 || ArcGIS Runtime WPF(.net C#)开发简明教程索引

创建ServiceArea

/// <summary>

        /// Services the area.

        /// </summary>

        /// <param name="networkDataset">The network dataset.</param>

        public void ServiceArea(INetworkDataset networkDataset)

        {

            log.WriteLog("开始创建ServiceArea...");

 

            IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();

            IWorkspace workspace = workspaceFactory.OpenFromFile(Functions.g_WorkSpacePath, 0);

            IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;

           

            CreateSolverContext(networkDataset);

            if (!LoadLocations(featureWorkspace, Functions.g_Hospital))

            {

                log.WriteLog("LoadLocations失败!");

            }

 

            log.WriteLog("ServiceArea创建完成!");

        }

 

/// <summary>

        /// Geodatabase function: get network dataset

        /// </summary>

        /// <param name="networkDataset">Input network dataset</param>

        /// <returns>DE network dataset</returns>

        public IDENetworkDataset GetDENetworkDataset(INetworkDataset networkDataset)

        {

            // Cast from the network dataset to the DatasetComponent

            IDatasetComponent dsComponent = networkDataset as IDatasetComponent;

 

            // Get the data element

            return dsComponent.DataElement as IDENetworkDataset;

        }

 

        /// <summary>

        /// Create NASolver and NAContext

        /// </summary>

        /// <param name="networkDataset">Input network dataset</param>

        private void CreateSolverContext(INetworkDataset networkDataset)

        {

            if (networkDataset == null) return;

 

            //Get the Data Element

            IDENetworkDataset deNDS = GetDENetworkDataset(networkDataset);

 

            INASolver naSolver = new NAServiceAreaSolverClass();

            m_NAContext = naSolver.CreateContext(deNDS, naSolver.Name);

            ((INAContextEdit)m_NAContext).Bind(networkDataset, new GPMessagesClass());

        }

 

/// <summary>

        /// Loads the locations.

        /// </summary>

        /// <param name="featureWorkspace">The feature workspace.</param>

        /// <param name="inputFacilities">The input facilities.</param>

        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>

        private bool LoadLocations(IFeatureWorkspace featureWorkspace, string inputFacilities)

        {

            IFeatureClass inputFeatureClass = null;

            try

            {

                inputFeatureClass = featureWorkspace.OpenFeatureClass(inputFacilities);

            }

            catch (Exception)

            {

                log.WriteLog("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;

            ((INALocator3)naClassLoader.Locator).MaxSnapTolerance = 500;

            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;

            IQueryFilter qf = new QueryFilterClass();

            qf.WhereClause = "aaaaaaaaaaa";  

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

 

            if (rowsLocated <= 0)

            {

                log.WriteLog("Facilities were not loaded from input feature class");

                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;

        }

 

posted @ 2016-04-15 10:39  jhlong  阅读(674)  评论(0编辑  收藏  举报
海龙的博客 jhlong@cnblogs 版权所有© 转载请注明链接.有用请推荐一下
代码全部经过本人测试,但不保证复制粘贴就正常运行,更不保证能解决你的问题,请结合前后代码及描述理解后修改和使用