Select to view content in your preferred language

Check if layer is raster in TOC using ArcObjects

4439
2
Jump to solution
08-27-2015 07:46 PM
MasroorHussain
Deactivated User

Hi,

I want to write a piece of code (ArcObjects 10.3 c#) to check if a layer in table of contents in ArcGIS is raster. Can someone help me please.

Thanks

Masroor

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Here's VB.NET code (from an add-in) that will cycle through each layer in your map and do something if it's a raster

Dim pEnumLayers As ESRI.ArcGIS.Carto.IEnumLayer
Dim pLayer As ESRI.ArcGIS.Carto.ILayer

If My.ArcMap.Document.FocusMap.LayerCount > 0 Then
    pEnumLayers = My.ArcMap.Document.FocusMap.Layers
    pLayer = pEnumLayers.Next
    Do Until pLayer Is Nothing
        If pLayer.Valid Then
            If TypeOf pLayer Is ESRI.ArcGIS.Carto.IRasterLayer Then
                ' do something
            End If
        End If
        pLayer = pEnumLayers.Next
    Loop
End If

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

Here's VB.NET code (from an add-in) that will cycle through each layer in your map and do something if it's a raster

Dim pEnumLayers As ESRI.ArcGIS.Carto.IEnumLayer
Dim pLayer As ESRI.ArcGIS.Carto.ILayer

If My.ArcMap.Document.FocusMap.LayerCount > 0 Then
    pEnumLayers = My.ArcMap.Document.FocusMap.Layers
    pLayer = pEnumLayers.Next
    Do Until pLayer Is Nothing
        If pLayer.Valid Then
            If TypeOf pLayer Is ESRI.ArcGIS.Carto.IRasterLayer Then
                ' do something
            End If
        End If
        pLayer = pEnumLayers.Next
    Loop
End If
0 Kudos
YuanLiu
Deactivated User

Hi, first to get the layer index from layer name if that's not already known, using snippet like http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//0049000000ns000000 , then check if it is ESRI.ArcGIS.Carto.IRasterLayer, similar to this snippet http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//004900000076000000

Hope this is what you are asking?