Proper parameter value for Geoprocessing Tool managment.Delete

1557
12
10-04-2017 04:24 PM
ThomasCox
Occasional Contributor

I am looking for a code example for executing the Geoprocessing tool "management.Delete".  I need to delete esri GRIDs that are created during processing in Pro.  I am not clear as to what parameter to pass.  I have looked the tool help that references input data elements.


I have tried raster datasets, raster layers.  When I pass a raster layer, the tool appears to work in that the GPResults.IsFailed property comes back false.  However, the GRID still resides on disk as a folder name and has its component files still present.


I have run the tool interactively in Pro.  It allows me to browse to the GRID, select it, and then run the command successfully.


I need to know what value to add to the parameters of the MakeValueArray as well as any syntax requirements.


Any assistance would be greatly appreciated.

0 Kudos
12 Replies
DanPatterson_Retired
MVP Emeritus

the proper parameter would be a raster dataset... with the caveat that the raster can't be open or used by 'anything', hence it can't be a layer in ArcMap, even sketchy time if Windows explorer is touching it

0 Kudos
ThomasCox
Occasional Contributor

Thanks Dan for your input.

I have spent a good bit of time trying to make this behave.  I have temporarily abandoned the effort to have the delete tool remove GRIDs that have been iteratively created during processing. Instead I have tried to run the tool programmatically against a GRID that has not been touched by the Pro Session.

I have tried the rater dataset as a parameter.  The GPResults object IsFailed shows false.  However, when I look at the rest of the parameters of the Results.Messages, it indicates that the GRID I am after does not exist, it appears to ignore the _connectionPath property of the raster dataset.  I checked this during a run and found it be correctly populated.  The ugly screen shot below shows this.

RasterDataSet Properties Screen Shot

When I execute the geoprocessing Delete tool, and examine the GResults, I see a warning message the GRID I am trying to delete does not exist.  The Delete tool does not seem to navigate the rasterdataset and use the _connectionPath.

GeoProcess Results Delete Screen Shot

I have looked at the Delete tool and note that it does not call for any environment settings.  I am generating the raster dataset directly from the directories, so the raster is never added to the Pro Session as a layer. 

I believe I need to pass more to the ValueArrayList than just the raster dataset, but am not clear as to what.

var parameters = Geoprocessing.MakeValueArray(pBasRasDataSet);

var gpResults = await Geoprocessing.ExecuteToolAsync("management.Delete", parameters);

When I look at the tool in Pro, it only calls for one parameter.  The following screen shot depicts this.

Delete Dialog from Pro

I guess the Input Data Element is expecting more than I am providing in my code attempt to execute the tool.

I am transitioning an ArcObjects application to Pro where I am able to remove GRIDS created during the ArcMap session. 

Any input to resolve the error of my ways would be welcome.

0 Kudos
DanPatterson_Retired
MVP Emeritus

The Environments settings is right beside the Parameters setting at the top.  You specify them in there.

As for the grids, they are wickedly long convoluted paths.  Can you on locally stored data in a simple folder?  esri grids are finicky, so you might want to try adding a *.tif to the rasters you are outputting since esri has moved to those as the default raster format.

0 Kudos
ThomasCox
Occasional Contributor

Thanks again for your input.  I guess I am unclear regarding the Environments setting regarding the Delete tool.  I did look at the Environments setting and it stated No Environments were necessary.  Migrating to the .tif would be a bit arduous, but perhaps I will have to down that road.

It is a bit frustrating as the Pro interactive Delete tool doesn't struggle with any of it.  Perhaps one of our friends from esri could enlighten. 

Thanks again Dan.  I know you are a strong contributor to the forum and I appreciate you taking the time.

0 Kudos
DanPatterson_Retired
MVP Emeritus

I will reach out, but in the interim ... advice from curtvprice‌ and myself on How to Name Things in ArcGIS ...

0 Kudos
curtvprice
MVP Esteemed Contributor
When I pass a raster layer, the tool appears to work in that the GPResults.IsFailed property comes back false.  However, the GRID still resides on disk as a folder name and has its component files still present.

Dan is right on, deleting a layer will only delete a layer not a dataset!  An issue you may be running into is that if you try to delete a raster data while a layer pointing to it still exists, the delete operation cannot complete. The interactive delete is probably working because the app has code to delete the layer and then the dataset.

Hope this helps!

0 Kudos
ThomasCox
Occasional Contributor

Thanks for responding Curtis. I appreciate your time.

I thought the dataset was the proper object from the beginning.  I have written ArcObjects applications that allow this behavior through the dataset, when that didn't work in Pro, I started experimenting with other parameters.

As I mentioned, to test the Delete tool free from any sr.lock files associated with having the GRID in the Pro session as a layer, I created the dataset from disk:

dataset from disk

I passed the raster dataset as a parameter to the tool and encounter the results posted above.  So it seems, independent of any 'layer' intrusion, the tool does not navigate the raster dataset, based off the GPResults message .  As the tool does not call for any environment parameters, I am not clear what else the it requires. 

Thanks again for input.

0 Kudos
curtvprice
MVP Esteemed Contributor

Unfortunately, you're a bit outside my expertise as I have zero experience with Pro SDK and minimal with ArcObjects. In geoprocessing all tool parameters are converted with str() before the tool runs. Tool parameters in GP are always passed in string representation. This allows easy code patterns in arcpy like:

lyr = arcpy.MakeFeatureLayer("test.shp", "lyrTest")
arcpy.SelectByAttribute_management(lyr, "", "FID < 20")

In the above example the result object lyr is converted "lyrTest" -- with str():  (str(lyr) == lyr.GetOutput(0) == "lyrTest") for SelectByAttribute.

It looks like above you were passing a pointer to an object (pBasRasDataSet) -- maybe you should be passing a path extracted off this object instead.

If this doesn't help I'm hoping someone that knows the Pro SDK will chime in.

0 Kudos
ThomasCox
Occasional Contributor

Thanks for your input Curtis.  I have tried numerous strategies to clean up the intermediate raster files with limited results.  I changed the raster type to .tif and attempted to remove the intermediate files with an operating system delete.  This works for the initial files, but encounters locks on the later ones and throws a message the files are being used by ArcPro.

I long for the 'old' days when you could simply delete a dataset such as:

            IWorkspace pWorkspace = (IWorkspace)ws;
            IEnumDataset pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTRasterDataset);
            IDataset pDS;

            try
            {
                pDS = pEnumDataset.Next();
                while (pDS != null)
                {
                    if (ListOfGridNamesToRemove.Contains(pDS.Name))
                    {
                        pDS.Delete();
                    }
                    pDS = pEnumDataset.Next();
                }
            }
            catch (Exception ex)
            {
                RemoveGRIDSListErr.Add(ex.Message);
            }

            System.Runtime.InteropServices.Marshal.ReleaseComObject(pWorkspace);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumDataset);

In the Pro SDK, I have not found any object based method that allows this. I understand the Pro
paradigm is to call tools to perform these tasks.  Unfortunately, I have not been able to get the "management.delete" tool to behave from code.  Additionally, I am finding in some instances, the geoprocessing tools performance is quite poor compared to their ArcObjects equivalent object methods. Look for an upcoming forum post regarding the raster 'Flip' command.  This poor performance is seen running the tool natively as well through code.

Perhaps, this delete issue might have to wait for the developer's summit.    I will update when I gain more insight as to how this process should work.

Thanks again to everyone for their input.

0 Kudos