Quantcast
Channel: Question and Answer » arcmap
Viewing all articles
Browse latest Browse all 248

Adding a layer can sometimes load raster footprint!

$
0
0

Just trying to refine my ArcObjects code to add a layer into ArcMap based on passing the fully quailified (String) name of the layer – problem is, if it’s a raster, it will load in the vector footprint of the raster which is no good. I want to load the raster in, not it’s footprint.

I can’t see anything obvious that allows you to test for rasterness, other than swapping the test in my code around – i.e testing for raster first then vector. Is there anything I am missing, is there a more elegant code out there to achieve this?

CODE

public static ILayer GetLayerFromSourceName(String name)
        {
            ILayer esriLayer = null;
            IWorkspace2 wsp2 = (IWorkspace2)Workspace;

        try
        {
            if (wsp2.get_NameExists(esriDatasetType.esriDTFeatureClass, name))
            {

                IFeatureLayer featureLayer = new FeatureLayerClass();
                featureLayer.FeatureClass = GeodatabaseManager.FeatureWorkspace.OpenFeatureClass(name);
                esriLayer = (ILayer)featureLayer;
            }
            else if (wsp2.get_NameExists(esriDatasetType.esriDTRasterDataset, name) ||
                wsp2.get_NameExists(esriDatasetType.esriDTRasterCatalog, name))
            {
                //This works only for remote raster datasests.
                IRasterDataset rasterDataset = null;
                IRasterLayer rasterLayer = new RasterLayerClass();
                rasterDataset = RasterWorkapaceEx.OpenRasterDataset(name);
                rasterLayer.CreateFromDataset(rasterDataset);

                esriLayer = (ILayer)rasterLayer;
            }
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
        }
        return esriLayer;
    }

Viewing all articles
Browse latest Browse all 248

Trending Articles