ArcGIS+C#——遍历FeatureWorkspace中所有的图层和属性表

public static void GetFcNameInFtWS(IFeatureWorkspace ipWs, ref List<IFeatureLayer> arrayFtInFWS, ref List<ITable> arrayTab)

        {

            if (ipWs == null)

            {

                return;

            }

            IWorkspace pWs = (IWorkspace)ipWs;

            IEnumDataset pEnumDs = pWs.get_Datasets(esriDatasetType.esriDTAny);

            IDataset pDs = pEnumDs.Next();

            while (pDs != null)

            {

                esriDatasetType esriDSType = pDs.Type;

                if (esriDSType == esriDatasetType.esriDTTable)

                {

                    ITable pTable = (ITable)pDs;                   

 

                    arrayTab.Add(pTable);

                    pDs = pEnumDs.Next();

                }

                else if (esriDSType == esriDatasetType.esriDTFeatureClass) //找到要素类

                {

                    IFeatureClass ipFtClass = (IFeatureClass)pDs;

 

                    IFeatureLayer pFLayer = new FeatureLayer();

                    pFLayer.FeatureClass = ipFtClass;

                    pFLayer.Name = ipFtClass.AliasName;

 

                    arrayFtInFWS.Add(pFLayer);

 

                    Marshal.ReleaseComObject(ipFtClass);

 

                    pDs = pEnumDs.Next();

 

                }

                else if (esriDSType == esriDatasetType.esriDTFeatureDataset) //找到要素集)

                {

                    IFeatureDataset pFtDs = (IFeatureDataset)pDs;

                    GetFcNameInDs (pFtDs, ref arrayFtInFWS); //获取IFeatureDataset中的所有featureclass

                    pDs = pEnumDs.Next();

                }

            }

        }
文章引自:http://blog.163.com/ljm1113@126/blog/static/579844522010324104711425/

转载自:https://blog.csdn.net/Prince999999/article/details/79046240

You may also like...