How to open raster data


Summary
This topic lists the supported raster formats, describes the Raster class and RasterLayer class, and provides code examples of how to open raster data, including adding a RasterLayer to a map.

In this topic


To use the code in this topic, add references to ESRI.ArcGISExplorer.dll and ESRI.ArcGISExplorer.Application.dll. Add the following namespace references via using (C#) or Imports (VB .NET) statements:
  • ESRI.ArcGISExplorer.Data
  • ESRI.ArcGISExplorer.Mapping
  • ESRI.ArcGISEXplorer.Application

Supported raster formats

ArcGIS Explorer supports the display of the following raster formats:
  • Geodatabase raster format
  • File-based formats:
    • IMAGINE image (.img)
    • Bitmap (.bmp)
    • Joint Photographic Experts Group (.jpg, .jpeg)
    • Portable Network Graphics (.png)
    • Graphic Interchange Format (.gif)
    • Tagged Image File Format (.tif, .tiff)
    • ARC/INFO and Space Imaging BIL (.bil)
    • ARC/INFO and Space Imaging BIP (.bip)
    • ARC/INFO and Space Imaging BSQ (.bsq)
    • DTED Level 0-2 (.dted)
    • ERDAS 7.5 LAN (.lan)
    • ERDAS 7.5 GIS (.gis)
    • JP2 (.jp2)
    • MrSID (.sid)
    • RAW (.raw)
    • NTIF (.ntf)
    • USGS ASCII DEM (.dem)
    • X11 Pixmap (.xpm)
    • PC Raster (.map)
    • PCI Geomatics Database File (.pix)
    • JPC (.jpc)
    • J2C (.j2c)
    • J2K (.j2k)
    • HDF (.hdf)
    • BSB (.kap)
    • Raster Product Format RPF, CIB, CADRG (.toc)
    • DIGEST ASRP & USRP (.img)
Raster catalogs or file-based image catalogs can be added using a layer file (.lyr) or layer package (.lpk).

Raster class and RasterLayer class

Raster objects allow you to access raster data from a file or geodatabase and a RasterLayer allows you to add raster data to the map. The following describes a Raster and RasterLayer class:
  • Raster class—Represents the raster data stored on disk and cannot be added to the map. Use this class to determine information about the source data, such as the cell size, number of rows or columns, and names of the constituent raster bands. You can also optimize the raster by building pyramids, export the raster to a Windows bitmap, and perform analysis to find the cell value or color at a particular point.
  • RasterLayer class—Represents a type of MapItem that can be added to the map and relies on having an underlying Raster object allowing the data to display. Use this class to specify if the layer represents heights or if it should be draped when in the 3D view. You can also use properties on the class to control layer visibility, scale thresholds, and transparency.
From a RasterLayer object, you can access the underlying Raster object using the RasterLayer.Raster property. Conversely, it is easy to create a RasterLayer object from a Raster object using the Raster.OpenFromRaster method.

Opening a geodatabase raster

A Raster object can be created for a geodatabase raster using the Geodatabase.OpenRaster method or one of the static convenience methods available on the Raster class: Raster.OpenFileGeodatabaseRaster and Raster.OpenArcSDERaster. See the following code example:
[C#]
//Option 1—Use the Geodatabase.OpenRaster instance method.
Geodatabase gdb = new Geodatabase(@"C:\Data\Scotland.gdb");
Raster mtnRaster = gdb.OpenRaster("NORTHGORMS_HO");
//Option 2—Use one of the the static methods on the Raster class.
Raster mtnRaster2 = Raster.OpenFileGeodatabaseRaster(@"C:\Data\Scotland.gdb", 
    "NORTHGORMS_HO");
Raster mtnRaster3 = Raster.OpenArcSDERaster(@"C:\Data\Enterprise.sde", 
    "SCOTADMIN.NORTHGORMS_HO");
//or
Raster mtnRaster4 = Raster.OpenArcSDERaster(new ArcSDEConnectionProperties(
    "server", "5151", "user", "pwd"), "SCOTADMIN.SOUTHGORMS_HO");
[VB.NET]
'Option 1—Use the Geodatabase.OpenRaster instance method.
Dim gdb As Geodatabase = New Geodatabase("C:\Data\Scotland.gdb")
Dim mtnRaster As Raster = gdb.OpenRaster("NORTHGORMS_HO")
'Option 2—Use one of the the static methods on the Raster class.
Dim mtnRaster2 As Raster = Raster.OpenFileGeodatabaseRaster("C:\Data\Scotland.gdb", "NORTHGORMS_HO")
Dim mtnRaster3 As Raster = Raster.OpenArcSDERaster("C:\Data\Enterprise.sde", "SCOTADMIN.NORTHGORMS_HO")
'or
Dim mtnRaster4 As Raster = Raster.OpenArcSDERaster(New ArcSDEConnectionProperties("server", "5151", "user", "pwd"), "SCOTADMIN.SOUTHGORMS_HO")
For more information on connecting to a geodatabase, see How to connect to a geodatabase.

Opening a file-based raster

A Raster object can be created for a file-based raster using the DataDirectory.OpenRaster method or using the static convenience method, Raster.OpenRasterfile, available on the Raster class. See the following code example:
[C#]
//Option 1—Use the DataDirectory.OpenRaster instance method.
DataDirectory dataDir = new DataDirectory(@"C:\Data");
Raster mtnRaster = dataDir.OpenRaster("NORTHGORMS.jpg");
//Option 2—Use the static Raster.OpenRasterFile method.
Raster mtnRaster2 = Raster.OpenRasterFile(@"C:\Data\NORTHGORMS.jpg");
[VB.NET]
'Option 1—Use the DataDirectory.OpenRaster instance method.
Dim dataDir As DataDirectory = New DataDirectory("C:\Data")
Dim mtnRaster As Raster = dataDir.OpenRaster("NORTHGORMS.jpg")
'Option 2—Use the static Raster.OpenRasterFile method.
Dim mtnRaster2 As Raster = Raster.OpenRasterFile("C:\Data\NORTHGORMS.jpg")
Always include the file extension when specifying the name of the raster to open.

Creating a RasterLayer

The ArcGIS Explorer application programming interface (API) provides the following alternative approaches to creating RasterLayer objects:
  • Provides the developer with the flexibility to determine when a layer should be connected to a data source.
  • Provides easy to use convenience methods.
See the following table that shows these approaches:
Approach
Steps
Pros and Cons
Create the RasterLayer, then manually connect to the data.
  1. Set up the DataSourceProperties object.
  2. Create the RasterLayer.
  3. Connect the RasterLayer.
  • Highly flexible. You decide when to connect and disconnect the RasterLayer.
  • Easy to trap connection issues.
  • Slightly more complicated approach.
Single-step to create the RasterLayer and connect to the data. 
  1. Use the appropriate static method on the Raster class for a particular raster type
  • Simple, you can add layer on a single line of code.
  • Need to catch connection exceptions.
  • Less flexible.
The following code example shows the first approach where a RasterLayer is created, then manually connected to the underlying data source using the Connect method:
[C#]
//Create a DataSourceProperties object that holds the connection information to the raster data source.
DataSourceProperties rasterLayerConnectionProps = new DataSourceProperties(@
    "C:\Data\Scotland.gdb", "NORTHGORMS_HO");
//Create a raster layer.
RasterLayer mtnRasterLayer = new RasterLayer(rasterLayerConnectionProps);
//Connect the layer to the raster data source.
bool connected = mtnRasterLayer.Connect();
//Add the layer to the map.
if (connected)
{
   
        ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map.ChildItems.Add(mtnRasterLayer);
}

else
{
    //Investigate connection issue.
    ConnectionStatus status = mtnRasterLayer.ConnectionStatus;
    if (status.HasError)
    {
        System.Diagnostics.Debug.Print(status.ErrorString);
    }
}
[VB.NET]
'Create a DataSourceProperties object that holds the connection information to the raster data source.
Dim rasterLayerConnectionProps As DataSourceProperties = New DataSourceProperties("C:\Data\Scotland.gdb", "NORTHGORMS_HO")
'Create a raster layer.
Dim mtnRasterLayer As RasterLayer = New RasterLayer(rasterLayerConnectionProps)
'Connect the layer to the raster data source.
Dim connected As Boolean = mtnRasterLayer.Connect()
'Add the layer to the map.
If (connected) Then
    ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map.ChildItems.Add(mtnRasterLayer)
Else
    'Investigate connection issue.
    Dim status As ConnectionStatus = mtnRasterLayer.ConnectionStatus
    If status.HasError Then
        System.Diagnostics.Debug.Print(status.ErrorString)
    End If
End If
You can use the IsConnected property to check whether a layer is connected to a data source and the ConnectionStatus property to investigate connection problems.
The DataSourceProperties class holds connection information relating to any of the supported raster formats by only setting the properties that are appropriate for a particular data source type. For example, the connection to a file-based raster can be fully defined using the Path property. 
The following code example shows the second approach where a RasterLayer is created and connected to the underlying data source using each of the static convenience methods:
[C#]
//File geodatabase raster.
try
{
    RasterLayer rasterLayer1 = RasterLayer.OpenFileGeodatabaseRaster(@
        "C:\Data\Scotland.gdb", "NORTHGORMS_HO");
}

catch (ConnectionException connEx)
{
    System.Diagnostics.Debug.Print(connEx.Message);
}

//Add try/catch blocks to test for connection problems...
//ArcSDE raster.
RasterLayer rasterLayer2 = RasterLayer.OpenArcSDERaster(new
                           ArcSDEConnectionProperties("serverName", "5151", "scotuser", "scotuser"), 
                           "scotadmin.SOUTHGORMS_HO");
//A file-base raster.
RasterLayer rasterLayer3 = RasterLayer.OpenRasterFile(@
    "\\leven\Data\Yellowstone\hillshade.img");
//For a raster instance (which is a file geodatabase raster).
Raster mtnRaster = Raster.OpenFileGeodatabaseRaster(@"C:\Data\Scotland.gdb", 
    "NORTHGORMS_HO");
RasterLayer rasterLayer4 = RasterLayer.OpenFromRaster(mtnRaster);
[VB.NET]
'File geodatabase raster.
Try
Dim rasterLayer1 As RasterLayer = RasterLayer.OpenFileGeodatabaseRaster("C:\Data\Scotland.gdb", "NORTHGORMS_HO")
Catch connEx As ConnectionException
System.Diagnostics.Debug.Print(connEx.Message)
End Try
'Add try/catch blocks to test for connection problems...
'ArcSDE raster.
Dim rasterLayer2 As RasterLayer = RasterLayer.OpenArcSDERaster(New ArcSDEConnectionProperties("serverName", "5151", "scotuser", "scotuser"), "scotadmin.SOUTHGORMS_HO")
'A file-base raster.
Dim rasterLayer3 As RasterLayer = RasterLayer.OpenRasterFile("\\leven\Data\Yellowstone\hillshade.img")
'For a raster instance (which is a file geodatabase raster).
Dim mtnRaster As Raster = Raster.OpenFileGeodatabaseRaster("C:\Data\Scotland.gdb", "NORTHGORMS_HO")
Dim rasterLayer4 As RasterLayer = RasterLayer.OpenFromRaster(mtnRaster)

Accessing raster data stored in a raster column in a table

A geodatabase table can store raster data in columns that have a raster ColumnTypeThe following code example shows how to return a Windows bitmap for a photo that is stored in a raster column in a table:
[C#]
//Open the geodatabase feature class.
Table propertyTable = Table.OpenFileGeodatabaseTable(@
    "\\leven\Data\Fish\data\PropertyInfo.gdb", "Taxlots");
//Return a row.
Row propertyRow = propertyTable.GetRow(1);
//Return the photo stored in the PropertyPicture column as a raster.
Raster propertyPhoto = propertyRow.Values["PropertyPicture"] as Raster;
//Convert the raster to a Windows bitmap.
System.Drawing.Bitmap photo = propertyPhoto.GetBitmap();
[VB.NET]
'Open the geodatabase feature class.
Dim propertyTable As Table = Table.OpenFileGeodatabaseTable("\\leven\Data\Fish\data\PropertyInfo.gdb", "Taxlots")
'Return a row.
Dim propertyRow As Row = propertyTable.GetRow(1)
'Return the photo stored in the PropertyPicture column as a raster.
Dim propertyPhoto As Raster = DirectCast(propertyRow.Values.Item("PropertyPicture"), Raster)
'Convert the raster to a Windows bitmap.
Dim photo As System.Drawing.Bitmap = propertyPhoto.GetBitmap()
For more information on accessing the values in a table, see How to access data in a table.


See Also:

How to connect to a geodatabase
How to access data in a table