Search code examples
c++visual-studio-2010visual-c++arcgis

How to access unwanted save file name and delete it?


I need to filter my raster image by a fixed threshold. So I use ILogicalOp functions. Whenever I use them, an output file will be saved on workspace, which is unwanted due to my large database. The saving happens exactly after rasOut[i] = RMath.LessThan(inputRas[i], cons01). How can I prevent this? Or how to get saved file name and delete it? Any comments would be Appreciated?

private IGeoDataset[] CalcColdThreshold(IGeoDataset[] inputRas)
{
    IGeoDataset[] rasOut = new IGeoDataset[inputRas.Length];
    IGeoDataset emptyRas=null;
    ILogicalOp RMath;
    RMath = new RasterMathOpsClass();
    IRasterAnalysisEnvironment env;
    env = (IRasterAnalysisEnvironment)RMath;
    IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
    IWorkspace workspace = workspaceFactory.OpenFromFile(System.IO.Path.GetFullPath(workSpace_save.Text), 0);
    env.OutWorkspace = workspace;
    IRasterMakerOp Rmaker = new RasterMakerOpClass();
    IGeoDataset cons01;
    Threshold_value = 15000;
    cons01 = Rmaker.MakeConstant(Threshold_value, false);
    for (int i = 0; i < inputRas.Length; i++)
    {
        rasOut[i] = RMath.LessThan(inputRas[i], cons01);
    } 
    return rasOut;
}

Solution

  • (disclaimer: I'm not actually a C++ programmer, just trying to provide some pointers to get you going since no one else seems to have any answers.) (converted from comment)

    The IScratchWorkspaceFactory interface sounds like it will do what you want - instead of creating your workspace variable using IWorkspaceFactory.OpenFromFile, try creating a scratch workspace instead? According to the documentation it will be automatically cleaned up when your application exits.

    Just remember to use a different workspace for your final output. :)