Add a raster type GeoDataset to the Map for visual display.
[C#]
/// <summary> /// Add a raster type GeoDataset to the Map for visual display. /// </summary> /// <param name="geoDataset">An IGeoDataset interface that is a raster to display in the Map.</param> /// <param name="map">An IMap interface that will display the raster.</param> /// <remarks> /// GeoDatasets are generic. This snippet is looking for the specific GeoDatasets of the Type: /// IRasterDataset. /// </remarks> public void AddGeoDatasetRasterToMap(ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset, ESRI.ArcGIS.Carto.IMap map) { // Only allow IRasterDataset type of GeoDatasets if (geoDataset is ESRI.ArcGIS.Geodatabase.IRasterDataset) { // Only allow a valid Map if (map != null) { // Create a raster for viewing ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = new ESRI.ArcGIS.Carto.RasterLayerClass(); ESRI.ArcGIS.Geodatabase.IRasterDataset rasterDataset = (ESRI.ArcGIS.Geodatabase.IRasterDataset)geoDataset; rasterLayer.CreateFromDataset(rasterDataset); // Add the raster to the map map.AddLayer(rasterLayer); } } }
[Visual Basic .NET]
''' <summary> ''' Add a raster type GeoDataset to the Map for visual display. ''' </summary> ''' <param name="geoDataset">An IGeoDataset interface that is a raster to display in the Map.</param> ''' <param name="map">An IMap interface that will display the raster.</param> ''' <remarks> ''' GeoDatasets are generic. This snippet is looking for the specific GeoDatasets of the Type: ''' IRasterDataset. ''' </remarks> Public Sub AddGeoDatasetRasterToMap(ByVal geoDataset As ESRI.ArcGIS.Geodatabase.IGeoDataset, ByVal map As ESRI.ArcGIS.Carto.IMap) ' Only allow IRasterDataset type of GeoDatasets If (TypeOf geoDataset Is ESRI.ArcGIS.Geodatabase.IRasterDataset) Then ' Only allow a valid Map If map IsNot Nothing Then ' Create a raster for viewing Dim rasterLayer As ESRI.ArcGIS.Carto.IRasterLayer = New ESRI.ArcGIS.Carto.RasterLayerClass Dim rasterDataset As ESRI.ArcGIS.Geodatabase.IRasterDataset = CType(geoDataset, ESRI.ArcGIS.Geodatabase.IRasterDataset) rasterLayer.CreateFromDataset(rasterDataset) ' Add the raster to the map map.AddLayer(rasterLayer) End If End If End Sub