Ejemplo n.º 1
0
        //加载参与分析的点要素
        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();
        }
Ejemplo n.º 2
0
        /// <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();
        }