[GIS] ArcGIS – Geoprocessing creating temporary files (e.g. “g_g193”). What produces these and how can they be cleaned up

arcgis-10.0geoprocessing

I have a couple of ArcGIS extensions that are running a lot of geoprocessing models with a mix of ArcObjects. I've noticed that the some, as of yet unidentified, geoprocessing steps are creating temporary raster files (e.g. g_g193, g_g983, g_g892). The funny thing is, these files are not being directed to my selected temporary workspace or the default Arc workspace. They are actually being sent to the 'bin' folder of my extension, which is obviously an issue since these temp files should not be stored with my included DLLs and EXE files.

It's important to mention that my extension makes many calls to Arc geoprocessing, so it's difficult to location the source of these files. The interesting thing is, if I walk through all of my code using break points in .NET these files don't always get created. It's like Arc is not cleaning up these temp files if the processing is moving very quickly, but it will clean them up if given time (e.g. user steps through slowly). Regardless, I don't want these files anywhere near my 'bin' folder.

Any insight would be greatly appreciated!

Best Answer

Sorted this out, finally.

Map Algebra and other Spatial Analyst operations that do not explicitly invoke the Geoprocessor object have an environment setting (IRasterAnalysisEnvironment) different from that of the standard GP.Environment. This environment must be set, or else it will default to the location of the extension (e.g. the binary folder). You'd think it would use the same default geodatabase as the other Spatial Analyst tools, but this is clearly not the case.

Here is a simple example from the ESRI documentation.

    Public Sub UsingRasterMapAlgebra()
    'Get rasters.
    Dim inRas01 As IRasterDataset
    inRas01 = OpenRasterDataset("c:\temp", "degs")
    Dim inRas02 As IRasterDataset
    inRas02 = OpenRasterDataset("c:\temp", "negs")
    'Create RasterMapAlgebraOp.
    Dim mapAlgebraOp As IMapAlgebraOp
    mapAlgebraOp = New RasterMapAlgebraOpClass()
    'Set environment.
    Dim env As IRasterAnalysisEnvironment
    env = mapAlgebraOp
    Dim workspaceFactory As IWorkspaceFactory = New RasterWorkspaceFactoryClass()
    Dim workspace As IWorkspace = workspaceFactory.OpenFromFile("c:\temp", 0)
    env.OutWorkspace = workspace
    'Bind rasters.
    mapAlgebraOp.BindRaster(inRas01, "Ras01")
    mapAlgebraOp.BindRaster(inRas02, "Ras02")
    'Execute script.
    Dim rasOut As IRaster
    rasOut = mapAlgebraOp.Execute("[Ras01] + [Ras02]")
    'Save output raster.
    Dim saveAs As ISaveAs2
    saveAs = rasOut
    saveAs.SaveAs("outMA", workspace, "GRID")
End Sub