Select to view content in your preferred language

Create ILayer from IRaster

921
4
12-15-2010 10:48 AM
MeleKoneya
Frequent Contributor
I am using IMapServerDataAccess to get an IRaster using the following:

IRaster raster = (IRaster)dataAccess.GetDataSource(mapServer.DefaultMapName, mapLayer);

How do I then add that IRaster as an ILayer to ArcMap?

I have tried casting IRaster to IRasterLayer with no luck.    Do I need to cast the IRaster to another object first?   

Thanks for any assistance.    I am working in C#, but will gladly take other samples if available.

Mele
0 Kudos
4 Replies
RobertBerger
Occasional Contributor
Hi Mele,

Have you tried creating a raster layer and then calling rasLayer.CreateFromRaster? This should create your raster layer from the IRaster object you have.
IRasterLayer
Look at the snippet how to Create a Raster Layer

Hope this helps.

Robert
0 Kudos
MeleKoneya
Frequent Contributor
Thanks Robert.    I will give this a shot.     I couldn't find it so I appreciate your assistance with pointing me in the right direction.
0 Kudos
Venkata_RaoTammineni
Regular Contributor
I am using IMapServerDataAccess to get an IRaster using the following:

IRaster raster = (IRaster)dataAccess.GetDataSource(mapServer.DefaultMapName, mapLayer);

How do I then add that IRaster as an ILayer to ArcMap?

I have tried casting IRaster to IRasterLayer with no luck.    Do I need to cast the IRaster to another object first?   

Thanks for any assistance.    I am working in C#, but will gladly take other samples if available.

Mele



public static void AddRasterLayer(ESRI.ArcGIS.Carto.IActiveView activeView,
    ESRI.ArcGIS.Geodatabase.IRasterDataset rasterDataset,
    ESRI.ArcGIS.Carto.IRasterRenderer rasterRenderer)
{
    //Create a raster layer from a raster dataset. You can also create a raster layer from a raster.
    ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = new RasterLayerClass();
    rasterLayer.CreateFromDataset(rasterDataset);
    //Set the raster renderer. The default renderer will be used if passing a null value.
    if (rasterRenderer != null)
    {
        rasterLayer.Renderer = rasterRenderer;
    }
    //Add it to a map if the layer is valid.
    if (rasterLayer != null)
    {
        ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap;
        map.AddLayer((ILayer)rasterLayer);
    }
}
0 Kudos
MeleKoneya
Frequent Contributor
I used the IRasterLayer.CreatefromRaster method with success.      Thanks to both of your replies as this pointed me in the right direction.

Mele
0 Kudos