• 创建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;
    
            }
  • 相关阅读:
    明年,我们依然年轻
    总有些东西会如台风一样的来
    ora00257错误处理方法
    ORACLE登录错误的解决方法
    C#中public new void add()的new在这里的意义
    Oracle Form Builder配置问题的一些总结
    作为程序员,你应该知道的职场晋升之路
    ORA01034错误的解决方法
    【转】JQUERY刷新页面
    【转】对C# 中堆栈,堆,值类型,引用类型的理解
  • 原文地址:https://www.cnblogs.com/jhlong/p/5394418.html
Copyright © 2020-2023  润新知