In this topic
Downloading native format source rasters
The following code example shows how to download native format source rasters from an image service:
[C#] public static void DownloadRasters(IImageServer imageServer)
{
//Cast.
IImageServer3 imageServer3=(IImageServer3)imageServer;
//Create a fidset that contains the OBJECTID of the target rasters.
IFIDSet fidSet=new FIDSetClass();
fidSet.Add(1);
fidSet.Add(2);
//Define the Web client.
System.Net.WebClient webClient=new System.Net.WebClient();
//Download the source rasters.
IImageServerDownloadResults isDownloadResults=imageServer3.Download(fidSet,
null, null);
IImageServerDownloadResult isDownloadResult;
string url, fileName;
for (int i=0; i < isDownloadResults.Count; i++)
{
isDownloadResult=isDownloadResults.get_Element(i);
url=imageServer3.GetFile(isDownloadResult);
fileName="c:\\temp\\" + url.Substring(url.LastIndexOf("/") + 1);
webClient.DownloadFile(url, fileName);
}
}
[VB.NET] Public Shared Sub DownloadRasters(ByVal imageServer As IImageServer)
'Cast.
Dim imageServer3 As IImageServer3=CType(imageServer, IImageServer3)
'Create a fidset that contains the OBJECTID of the target rasters.
Dim fidSet As IFIDSet=New FIDSetClass()
fidSet.Add(1)
fidSet.Add(2)
'Define the Web client.
Dim webClient As New System.Net.WebClient()
'Download the source rasters.
Dim isDownloadResults As IImageServerDownloadResults=imageServer3.Download(fidSet, Nothing, Nothing)
Dim isDownloadResult As IImageServerDownloadResult
Dim url As String, fileName As String
For i As Integer=0 To isDownloadResults.Count - 1
isDownloadResult=isDownloadResults.Element(i)
url=imageServer3.GetFile(isDownloadResult)
fileName="c:\temp\" & url.Substring(url.LastIndexOf("/") + 1)
webClient.DownloadFile(url, fileName)
Next
End Sub
Clipping and downloading source rasters to TIFF
The following code example shows how to clip source rasters based on a geometry and download them to TIFF:
[C#] public static void ClipDownloadRasters(IImageServer imageServer, IGeometry
clipGeometry)
{
//Cast.
IImageServer3 imageServer3=(IImageServer3)imageServer;
//Query the image service using the clip geometry.
ISpatialFilter spatFilter=new ImageQueryFilterClass();
spatFilter.Geometry=clipGeometry;
spatFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;
IFIDSet fidSet=imageServer3.GetCatalogItemIDs((IQueryFilter)spatFilter);
//Define the Web client.
System.Net.WebClient webClient=new System.Net.WebClient();
//Clip and download rasters to TIFF images. The format can be TIFF, NITF, or Imagine image file format.
IImageServerDownloadResults isDownloadResults=imageServer3.Download(fidSet,
clipGeometry, "TIFF");
IImageServerDownloadResult isDownloadResult;
string url, fileName;
for (int i=0; i < isDownloadResults.Count; i++)
{
isDownloadResult=isDownloadResults.get_Element(i);
url=imageServer3.GetFile(isDownloadResult);
fileName="c:\\temp\\" + url.Substring(url.LastIndexOf("/") + 1);
webClient.DownloadFile(url, fileName);
}
}
[VB.NET] Public Shared Sub ClipDownloadRasters(ByVal imageServer As IImageServer, ByVal clipGeometry As IGeometry)
'Cast.
Dim imageServer3 As IImageServer3=CType(imageServer, IImageServer3)
'Query the image service using the clip geometry.
Dim spatFilter As ISpatialFilter=New ImageQueryFilterClass()
spatFilter.Geometry=clipGeometry
spatFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects
Dim fidSet As IFIDSet=imageServer3.GetCatalogItemIDs(DirectCast(spatFilter, IQueryFilter))
'Define the Web client.
Dim webClient As New System.Net.WebClient()
'Clip and download rasters to TIFF images. The format can be TIFF, NITF, or Imagine image file format.
Dim isDownloadResults As IImageServerDownloadResults=imageServer3.Download(fidSet, clipGeometry, "TIFF")
Dim isDownloadResult As IImageServerDownloadResult
Dim url As String, fileName As String
For i As Integer=0 To isDownloadResults.Count - 1
isDownloadResult=isDownloadResults.Element(i)
url=imageServer3.GetFile(isDownloadResult)
fileName="c:\temp\" & url.Substring(url.LastIndexOf("/") + 1)
webClient.DownloadFile(url, fileName)
Next
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):
- ESRI.ArcGIS.Carto
- ESRI.ArcGIS.Server
- ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)
- ESRI.ArcGIS.Geodatabase
- ESRI.ArcGIS.Geometry
Development licensing | Deployment licensing |
---|---|
ArcGIS Desktop Advanced | ArcGIS Desktop Advanced |
ArcGIS Desktop Standard | ArcGIS Desktop Standard |
ArcGIS Desktop Basic | ArcGIS Desktop Basic |
Engine Developer Kit | Engine |