Set Visible Extent for a RasterCatalogLayer


This sample shows one way to set the visible extent for a RasterCatalogLayer because currently there is not a "VisibleExtent" property on RasterCatalogLayers like there is on RasterLayers. In this sample the extent is not persisted in the RasterCatalogTable or the map document. One way to get the same extent for RasterCatalogLayers each time you open the map document is to persist the extent through an extension by having it implement the IPersistVariant interface (refer to the sample under COM techniques->Persistence). Then call the subroutine of set_extent_of_RasterCatalogLayer in OpenDocument event handler. In the future release, there will be a VisibleExtent property for RasterCatalogLayer, which will make the process in this sample unnecessary.

How to use:
  1. Add a RasterCatalogLayer to ArcMap and zoom to some extent.
  2. Copy and paste the code into ArcMap VB Editor.
  3. Change the index of the RasterCatalogLayer in the subroutine of set_visible_extent_of_RasterCatalogLayer if necessary.
  4. Run set_visible_extent_of_RasterCatalogLayer subroutine, the visible extent of the RasterCatalogLayer will be set to the current extent.
Private m_map As IMap
Private m_doc As IMxDocument

Public Sub set_visible_extent_of_RasterCatalogLayer()
  Set m_doc = ThisDocument
  Set m_map = m_doc.FocusMap
  Dim pCatalogLayer As IRasterCatalogLayer
   'Get the RasterCatalogLayer
   Set pCatalogLayer = m_map.Layer(0)
  Dim pEnv As IEnvelope
  Set pEnv = m_doc.ActivatedView.Extent
  set_extent_of_RasterCatalogLayer pCatalogLayer, pEnv
End Sub

Private Sub set_extent_of_RasterCatalogLayer(pCatalogLayer As IRasterCatalogLayer, pEnv As IEnvelope)
  Dim pRasterDataset As IRasterDataset
  Dim pRasterCatTbl As IRasterCatalogTable
  Set pRasterCatTbl = pCatalogLayer.CatalogTable
  Dim i As Long
  For i = 0 To pRasterCatTbl.Size - 1
    Set pRasterDataset = pRasterCatTbl.RasterDataset(i)
    Dim pRaster As IRaster
    Set pRaster = pRasterDataset.CreateDefaultRaster
    Dim pRasterGeomProc As IRasterGeometryProc
    Set pRasterGeomProc = New RasterGeometryProc
     'Reset in case its been clipped before by a different extent
     pRasterGeomProc.Reset pRaster
    pRasterGeomProc.Clip pEnv, pRaster
    pRasterGeomProc.Register pRaster
  Next i
End Sub