This project is read-only.

How to get the full path of layer

Jan 11, 2011 at 3:05 AM


     if i add tow layer, one for shapefile, another for grid, i want to know the full path of each layer, for example, one is c:\aa.shp, another is c:\bb.img. What should i do?

Jan 11, 2011 at 4:11 AM

You need to access the DataSet property on the layer, cast it appropriately and then get the filename.

public string GetFilename(int iLayer)
  IFeatureSet fs = Map1.Layers[iLayer].DataSet as IFeatureSet;
  if(fs != null)
    // layer is a vector layer if fs != null
    string filename = fs.filename;
    return filename;
  IRaster r = Map1.Layers[1].DataSet as IRaster;
  if(r != null)
    // layer is a raster layer.
    string filename = r.filename;
    return filename;
  IImageData id = Map1.Layers[iLayer].DataSet as IImageData
  if(id != null)
    // layer is an image layer
    return id.filename;

What I can't remember is if filename is on the dataset itself.  If not, then you will have to cast to IFeatureSet or IRaster before you can read the filename.  If so, then you may be able to read the filename directly from the dataset object.  I can't remember right now and I'm away from my computer with the source code on it.






Jan 11, 2011 at 5:10 AM

ok,i will try it. Thanks Ted.