How to edit rasters in an image service


Summary
Image services support editing (using the ArcGIS 10.1 mosaic dataset). This topic demonstrates how to add new rasters to an image service, update rasters (or attributes) in an image service, and delete a raster from an image service.


Adding rasters to an image service

The following code example demonstrates how to add new rasters to an image service. These rasters are from a location that can be accessed by ArcGIS Server, for example, a Universal (or Uniform) Naming Convention (UNC) path, or Hypertext Transfer Protocol (HTTP) uniform resource locator (URL).
[C#]
public static void AddRastersToImageService(IImageServer imageServer, List < string
    > fileNames, List < string > fileUrls, IPropertySet attributes)
{
    //Construct an item description.    
    IRasterItemDescription itemDescription = new RasterItemDescriptionClass();

    //Define source raster names, locations, and type.
    IStringArray dataFileNames = new StrArrayClass();
    //File names example: Image32.tif, Image32.tfw, Image32.aux.
    foreach (string fileName in fileNames)
        dataFileNames.Add(fileName);
    itemDescription.DataFileNames = dataFileNames;
    IStringArray dataFileURLs = new StrArrayClass();
    //File URL examples: c:\temp\Image32.tif, c:\temp\Image32.tfw, http:\\host\Image32.aux.
    foreach (string fileurl in fileUrls)
        dataFileURLs.Add(fileurl);
    itemDescription.DataFileURLs = dataFileURLs;
    itemDescription.Type = "Raster Dataset";

    //Raster pyramids,statistics,thumbnail.
    itemDescription.BuildPyramids = false;
    itemDescription.BuildThumbnail = false;
    itemDescription.ComputeStatistics = false;

    //If you need to overwrite default raster properties/metadata, provide here.
    itemDescription.Properties = attributes;

    //Construct item descriptions.
    IRasterItemDescriptions itemDescriptions = new RasterItemDescriptionsClass();
    itemDescriptions.Add(itemDescription);

    //Add.
    IImageServerEditResults isEditResults = ((IImageServer4)imageServer).Add
        (itemDescriptions);
}
[VB.NET]
Public Shared Sub AddRastersToImageService(imageServer As IImageServer, fileNames As List(Of String), fileUrls As List(Of String), Attributes As IPropertySet)
'Construct an item description.
Dim itemDescription As IRasterItemDescription = New RasterItemDescriptionClass()

'Define source raster names, locations, and type.
Dim dataFileNames As IStringArray = New StrArrayClass()
'File names example: Image32.tif, Image32.tfw, Image32.aux.
For Each fileName As String In fileNames
    dataFileNames.Add(fileName)
Next
itemDescription.DataFileNames = dataFileNames
Dim dataFileURLs As IStringArray = New StrArrayClass()
'File URL examples: c:\temp\Image32.tif, c:\temp\Image32.tfw, http:\\host\Image32.aux.
For Each fileurl As String In fileUrls
    dataFileURLs.Add(fileurl)
Next
itemDescription.DataFileURLs = dataFileURLs
itemDescription.Type = "Raster Dataset"

'Raster pyramids,statistics,thumbnai.l
itemDescription.BuildPyramids = False
itemDescription.BuildThumbnail = False
itemDescription.ComputeStatistics = False

'If you need to overwrite default raster properties/metadata, provide here.
itemDescription.Properties = Attributes

'Construct item descriptions.
Dim itemDescriptions As IRasterItemDescriptions = New RasterItemDescriptionsClass()
itemDescriptions.Add(itemDescription)

'Add.
Dim isEditResults As IImageServerEditResults = DirectCast(imageServer, IImageServer4).Add(itemDescriptions)
End Sub

Updating rasters and attributes in an image service

This sample demonstrates how to edit raster items in an image service. This operation can be used to update attribute values of the catalog table, replace existing raster, or update georeferencing information.
[C#]
public static void UpdateImageService(IImageServer imageServer, List < string >
    fileNames, List < string > fileUrls, IPropertySet attributes)
{
    //Define catalog item ID.
    IFIDSet fids = new FIDSetClass();
    fids.Add(2);
    //Construct an item description.
    IRasterItemDescription itemDescription = new RasterItemDescriptionClass();
    //Put attribute name/value to a property set.
    itemDescription.Properties = attributes;

    //If you need to replace raster.
    IStringArray dataFileNames = new StrArrayClass();
    //File names example: Image32.tif, Image32.tfw, Image32.aux.
    foreach (string fileName in fileNames)
        dataFileNames.Add(fileName);
    itemDescription.DataFileNames = dataFileNames;
    IStringArray dataFileURLs = new StrArrayClass();
    //File URLs example: c:\temp\Image32.tif, c:\temp\Image32.tfw, http:\\host\Image32.aux.
    foreach (string fileurl in fileUrls)
        dataFileURLs.Add(fileurl);
    itemDescription.DataFileURLs = dataFileURLs;
    itemDescription.Type = "Raster Dataset";
    //If you need to rebuild/replace raster, use the following.
    itemDescription.BuildPyramids = false;
    itemDescription.BuildThumbnail = false;
    itemDescription.ComputeStatistics = false;

    //If you need to revise georeference infomation.
    IPolynomialXform polyxform = new PolynomialXformClass();
    polyxform.ApplyShift(esriTransformDirection.esriTransformForward, 100, 100);
    itemDescription.GeodataXform = polyxform;
    itemDescription.GeodataXformApplyMethod =
        esriGeodataXformApplyMethod.esriGeodataXformApplyAppend;
    //Construct item descriptions.
    IRasterItemDescriptions itemDescriptions = new RasterItemDescriptionsClass();
    itemDescriptions.Add(itemDescription);
    //Update.
    IImageServerEditResults editResults = ((IImageServer4)imageServer).Update(fids,
        itemDescriptions);
}
[VB.NET]
Public Shared Sub UpdateImageService(imageServer As IImageServer, fileNames As List(Of String), fileUrls As List(Of String), Attributes As IPropertySet)
'Define catalog item ID.
Dim fids As IFIDSet = New FIDSetClass()
fids.Add(2)
'Construct an item description.
Dim itemDescription As IRasterItemDescription = New RasterItemDescriptionClass()
'Put attribute name/value to a property set.
itemDescription.Properties = Attributes
'If need to rebuild/replace raster, use the following.
Dim dataFileNames As IStringArray = New StrArrayClass()
'File names example: Image32.tif, Image32.tfw, Image32.aux.
For Each fileName As String In fileNames
    dataFileNames.Add(fileName)
Next
itemDescription.DataFileNames = dataFileNames
Dim dataFileURLs As IStringArray = New StrArrayClass()
'File URL examples: c:\temp\Image32.tif, c:\temp\Image32.tfw, http:\\host\Image32.aux.
For Each fileurl As String In fileUrls
    dataFileURLs.Add(fileurl)
Next
itemDescription.DataFileURLs = dataFileURLs
itemDescription.Type = "Raster Dataset"
itemDescription.BuildPyramids = False
itemDescription.BuildThumbnail = False
itemDescription.ComputeStatistics = False
'if need to revise georeference infomation
Dim polyxform As IPolynomialXform = New PolynomialXformClass()
polyxform.ApplyShift(esriTransformDirection.esriTransformForward, 100, 100)
itemDescription.GeodataXform = polyxform
itemDescription.GeodataXformApplyMethod = esriGeodataXformApplyMethod.esriGeodataXformApplyAppend
'Construct item descriptions.
Dim itemDescriptions As IRasterItemDescriptions = New RasterItemDescriptionsClass()
itemDescriptions.Add(itemDescription)
'Update.
Dim editResults As IImageServerEditResults = DirectCast(imageServer, IImageServer4).Update(fids, itemDescriptions)
End Sub

Deleting rasters from an image service

The following code demonstrates how to delete rasters from an  image service:
[C#]
public static void DeleteRastersFromImageService(IImageServer imageServer, int id)
{
    //Define catalog item ID.
    IFIDSet fids = new FIDSetClass();
    fids.Add(id);
    //Delete.
    IImageServerEditResults editResults = ((IImageServer4)imageServer).Delete(fids);
}
[VB.NET]
Public Shared Sub DeleteRastersFromImageService(imageServer As IImageServer, id As Integer)
'Define catalog item ID.
Dim fids As IFIDSet = New FIDSetClass()
fids.Add(id)
'Delete.
Dim editResults As IImageServerEditResults = DirectCast(imageServer, IImageServer4).Delete(fids)
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
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
Engine Developer Kit Engine