“Raster acceleration, I want to do that too!”, exclaimed the developer.

One question we tend to get after developing new things is “how do I do that”? If you are writing your own application and want to include some of the new features, here are some examples.

Today, we will discuss raster acceleration. The snippet here is in C#, but our online help also has VB.NET.

Each time you apply accelerate you need to remove the layer, apply the change, and add the layer again. If you don’t want your whole map to refresh (with only a single layer in the map) you need to remember the extent. Also, acceleration works differently between a mosaic dataset and a normal raster layer.

private void btn_Accelerate_Click(object sender, EventArgs e)
{    
   
// Get the current extent to set later on the display update
    
   
IEnvelope env = axMapControl1.Extent.Envelope;
    
   
if (axMapControl1.LayerCount > 0)
    
  
{
     
// Getting the first layer (could also use selected layer here)        
    
ILayer ly = axMapControl1.get_Layer(0);
        
    
/* Check to see what kind of layer we have. Acceleration only works
            
        
* with IRasterLayer, IMosaicLayer, IImageServerLayer, and IWCSLayer
               
        
*/        
    
if (ly is IRasterLayer)
        
    
{
            
        
IRasterLayer rasLy = (IRasterLayer)ly;
            
        
IRasterBasemapLayerFactory rasterBMLFactory = new RasterBasemapLayerFactoryClass();
            
        
IRasterBasemapLayer rasterBML = rasterBMLFactory.Create(rasLy);
            
        
ILayer layer = (ILayer)rasterBML;
            
        
// Adjust layer name to show acceleration
            
        
layer.Name = “Accelerated “ + layer.Name;
            
        
// Update display with the new layer
            
        
updateDisplay(env, layer);
        
     
}
        
     
else if (ly is MosaicLayer)
        
     
{
            
         
IMosaicLayer mosLy = (IMosaicLayer)ly;
            
         
IRasterBasemapLayerFactory rasterBMLFactory = new RasterBasemapLayerFactoryClass();
            
         
// Accelerating mosaic datasets, only the preview layer is accelerated.
            
         
IRasterBasemapLayer rasterBML = rasterBMLFactory.Create((IRasterLayer)mosLy.PreviewLayer);
            
        
ILayer layer = (ILayer)rasterBML;
            
        
// Adjust layer name to show acceleration
            
        
layer.Name = “Accelerated “ + layer.Name;
            
        
// Update display with the new layer
            
        
updateDisplay(env, layer);
        
     
}
    
  
}
}

In this case I assume there is only one layer in the map that we want to work with, so I remove everything and add the single layer back in. Otherwise I’d have to see what layer I accelerated and remove that specific layer only.

private void updateDisplay(IEnvelope env, ILayer ly)
{   
   // Get an enumeration of all layers in the Map
   
  
IEnumLayer enumLy = axMapControl1.Map.get_Layers(null, true);
   
  
ILayer lyen;
   
  
enumLy.Reset();
   
  
lyen = enumLy.Next();
   
  
while (lyen != null)
   
  
{
       
     
// Remove all layers rather than updating a single layer
       
      axMapControl1.Map.DeleteLayer(lyen);
       
     
lyen = enumLy.Next();
   
  
}
   
  
// Add my acceleratied layer
   
  
axMapControl1.AddLayer(ly);
   
  
if (env != null) { axMapControl1.Extent = env; }
   
  
axMapControl1.Update();
}

Happy AppAcceleration J

 

Written by: Robert Berger 

 

 

This entry was posted in Developer, Imagery and tagged , , , , . Bookmark the permalink.

Leave a Reply

2 Comments

  1. khalid-gis says:

    My work enviroment is arcgis server 9.2 E ,visual studio 2005 , so can apply snippet
    Khalid Altaee

  2. mharlow says:

    This kind of raster acceleration was introduced in ArcGIS Version 10.0. Therefore, if you’re asking how to do it in 9.2, then this code does not apply.