How to create an image server layer


Creating an image server layer

The following code example shows how to create an image server layer from a uniform resource locator (URL), clip a portion of the image, and save it to a file:
[C#]
public static void AccessImageServerLayer()
{
    //Create an image server layer by passing a URL.
    IImageServerLayer imageserverlayer = new ImageServerLayerClass();
    string URL = "http://mengrai/arcgis/services/amazon/imageserver";
    imageserverlayer.Initialize(URL);

    //Get the raster from the image server layer.
    IRaster raster = imageserverlayer.Raster;

    //The raster from an image server is normally large; 
    //define the size of the raster.
    IRasterProps rasterProps = (IRasterProps)raster;
    IEnvelope clipEnvelope = new EnvelopeClass();
    clipEnvelope.PutCoords(779000, 9628000, 786000, 9634000);
    rasterProps.Extent = clipEnvelope;
    rasterProps.Width = 256;
    rasterProps.Height = 256;

    //Save the clipped raster to the file geodatabase.
    ISaveAs saveas = (ISaveAs)raster;
    Type factoryType = Type.GetTypeFromProgID(
        "esriDataSourcesGDB.FileGDBWorkspaceFactory");
    IWorkspaceFactory workspaceFact = (IWorkspaceFactory)Activator.CreateInstance
        (factoryType);
    IWorkspace workspace = workspaceFact.OpenFromFile(@"c:\temp\fgdb.gdb", 0);
    saveas.SaveAs("clipfromimageserverlayer", workspace, "gdb");
}
[VB.NET]
Public Shared Sub AccessImageServerLayer()
'Create an image server layer by passing a URL.
Dim imageserverlayer As IImageServerLayer = New ImageServerLayerClass()
Dim URL As String = "http://mengrai/arcgis/services/amazon/imageserver"
imageserverlayer.Initialize(URL)

'Get the raster from the image server layer.
Dim raster As IRaster = imageserverlayer.Raster

'The raster from an image server is normally large;
'define the size of the raster.
Dim rasterProps As IRasterProps = CType(raster, IRasterProps)
Dim clipEnvelope As IEnvelope = New EnvelopeClass()
clipEnvelope.PutCoords(779000, 9628000, 786000, 9634000)
rasterProps.Extent = clipEnvelope
rasterProps.Width = 256
rasterProps.Height = 256

'Save the clipped raster to the file geodatabase.
Dim saveas As ISaveAs = CType(raster, ISaveAs)
Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory")
Dim workspaceFact As IWorkspaceFactory = Activator.CreateInstance(factoryType)
Dim workspace As IWorkspace = workspaceFact.OpenFromFile("c:\temp\fgdb.gdb", 0)
saveas.SaveAs("clipfromimageserverlayer", workspace, "gdb")

End Sub






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcInfo ArcInfo
ArcView ArcView
ArcEditor ArcEditor
Engine Developer Kit Engine Runtime