C# ArcGIS Engine实现获取图层字段信息

        /// <summary>
        /// 得到所有的图层
        /// </summary>
        /// <returns></returns>
        public static List<string> GetLayerNameList()
        {
            List<string> layerNameList = new List<string>();
            IWorkspace workSpace = CommonUtils.GetSdeIWorkSpace();
            IEnumDatasetName enumDatasetName;
            IDatasetName datasetName;
            //获取图层名
            enumDatasetName = workSpace.get_DatasetNames(esriDatasetType.esriDTFeatureClass);
            datasetName = enumDatasetName.Next();
            while (datasetName != null)
            {
                layerNameList.Add(datasetName.Name);
                datasetName = enumDatasetName.Next();
            }
            CommonUtils.RelComObject(enumDatasetName);
            CommonUtils.RelComObject(workSpace);
            return layerNameList;
        }
         /// <summary>
        /// 得到对应层字段
        /// </summary>
        /// <param name="layerName">层名</param>
        /// <returns></returns>
        public static List<string> GetFieldNameList(string layerName)
        {
            IFeatureClass featureClass = (CommonUtils.GetSdeIWorkSpace() as IFeatureWorkspace).OpenFeatureClass(layerName);
            IFields pFields = featureClass.Fields;  //获取图层的字段
            List<string> fieldNameList = new List<string>();
            for (int i = 0; i < pFields.FieldCount; i++)
            {
                fieldNameList.Add(pFields.get_Field(i).Name);
            }
            return fieldNameList;
        }

猜你喜欢

转载自blog.csdn.net/qq_30430463/article/details/111562375