Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Let's say I load up two layers, and then save an .mxd file. Now I want to get the path names of my layers from the .mxd file. Is there a way to do this in ArcEngine?

I'm using ArcEngine 10 with VS2010 & C#

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Using the MapDocument CoClass, you can do this (pseudocode, I don't know any .Net languages):

void handle_layer(layer, data_sources)
{
    data_layer = layer as IDataLayer
    group_layer = layer as ICompositeLayer

    if (data_layer != null)
    {
       data_sources.Insert(data_layer.DataSourceName.NameString)
    }

    if (group_layer != null)
    {
       layer_count = group_layer.Count
       for (layer_index in 0..layer_count)
       {
          handle_layer(group_layer.Layer[layer_index], data_sources)
       }
    }
}

data_sources = list<string>

mxd = MapDocument as IMapDocument
mxd.Open(filename, "")
map_count = mxd.MapCount
for (map_index in 0..map_count)
{
  map = mxd.Map[map_index]
  layer_count = map.LayerCount
  for (layer_index in 0..layer_count)
  {
    handle_layer(map.Layer[layer_index], data_sources)
  }
}

The trick is to get the path string from the IName in each data layer.

If you mean you want the path of the original .lyr file you used to add the layers to the TOC, no, that information is not stored anywhere in the MXD.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.