I want to determine the type of data that is referenced in a layer file. For example, I open a layer file that is referencing a raster dataset. In code how do you determine that the layer file is referencing a raster dataset? Right now I first use a 'try' block and QI to the IFeatureLayer interface. If this fails then in the 'catch' block I QI to IRasterLayer. I would rather first determine that the layer is pointing to a raster dataset and then use a 'switch/case' block to work with the appropriate interface.
My current method:
string LayerFileLocation = "C:\SomeLayerFile.lyr";
ILayerFile layerFile = new ESRI.ArcGIS.Carto.LayerFileClass();
layerFile.Open(LayerFileLocation);
ILayer pLayer = layerFile.Layer;
IFeatureLayer2 pFeatureLayer2;
IRasterLayer pRasterLayer;
try
{
pFeatureLayer2 = (IFeatureLayer2)pLayer;
}
catch
{
pRasterLayer = (IRasterLayer)pLayer;
}
Dennis Geasan
GIS Technolgies