English

Error: Failed to rename the specified file

Error Message

This error occurs when using the MakePermanentAs method to make a temporary output from a spatial analyst function into a permanent raster (grid):

“Failed to rename the specified file”

Cause

This happens when the permanent output file specified is a grid raster dataset and is in the same directory as the temporary output. MakePermanentAs does not make another copy of the grid, instead, it renames the temporary grid. If the references to the grid are not released before calling MakePermanentAs, an error will occur.

Solution or Workaround

Use the SaveAs method instead of MakePermanentAs. Alternatively, release the references to the temporary grid, then call MakePermanentAs.

  • Use the SaveAs method instead of MakePermanentAs:

    Code:
    Dim pRBC As IRasterBandCollection
    Set pRBC = pOutGDS '-- pOutGDS is a IGeoDataset generated from a SA function
    Dim pDS As IGeoDataset
    Set pDS = pRBC.SaveAs("test2", pWs, "TIFF")

  • Release the references to the temporary grid, then call MakePermanentAs:

    Code:
    Public Function MakePermanentAs(pSAOutRaster As IRaster)
    '-- pSAOutRaster is a Raster Object from a Spatial operation
    Dim pRasBC As IRasterBandCollection
    Set pRasBC = pSAOutRaster

    '-- Get the dataset from the first band
    Dim pOutDS As IRasterDataset
    Set pOutDS = pRasBC.Item(0).RasterDataset

    '-- QI the dataset for ITemporaryDataset
    Dim pTemp As ITemporaryDataset
    Set pTemp = pOutDS

    '-- Release the raster before making the dataset permanent
    Set pRasBC = Nothing
    Set pOutGDS = Nothing

    Dim pDS As IDataset
    Set pDS = pTemp.MakePermanentAs("c:\temp\outgrd", Nothing, "GRID")
    End Function