列出MXD中的所有要素类

时间:2016-03-14 16:04:32

标签: c# loops arcmap arcobjects

我有一个mxd文件,我已加载到ArcMap中。装完后,有几层;其中一些有多个要素类。最终结果列出了每个要素类的所有文件路径/位置/来源,但是现在,我只需要知道如何列出所有已加载的要素类。当我说列表时,它们实际上可以通过消息框输出到屏幕。我知道我需要遍历每一层,但是利用正确的界面并访问ArcMaps属性是我迷失的地方。

对此的任何帮助将不胜感激。我还在学习ArcObjects以及它如何运作以及迫切需要帮助。提前谢谢。

1 个答案:

答案 0 :(得分:0)

这将是C#中循环遍历所有图层的示例,如果它是一个要素图层,则直到工作空间获取路径或其中的任何内容:

/* Make a list of all feature classes. */
List<ILayer> layers_list = new List<ILayer>();
IMap map = get_map();
IEnumLayer enumLayer = map.get_Layers(null, true);
ILayer layer = null;
while (layer = enumLayer.Next() != null) {
    // we're looking for a feature class only
    if (layer is IFeatureLayer) {
        try {
            IFeatureClass fclass = ((IFeatureLayer)layer).FeatureClass;
            IFeatureLayer featureLayer = (IFeatureLayer)layer;
            // Get the dataset and workspace of the feature class
            IDataset ds = (IDataset)fclass;
            IWorkspace ws = (IWorkspace)ds.Workspace;
            // Do something with the workspace, like getting the path or
            // whatever...
        } catch (Exception e) {
            MessageBox.Show("Layer ' " + layer.Name + "': \n\n" + e.Message);
        }
    }
}