arcpy.ProjectRaster_management fails when called from Console Application

945
3
01-09-2019 03:08 PM
ThomasCox
Occasional Contributor

We are experiencing an arcpy error when attempting to execute the arcpy geoprocessing tool "arcpy.ProjectRaster_management" from a C# console application.  The application is passing parameters to the python script .  The returned message is:

“Failed to open raster dataset: “ C:\DopplerConsoleRasters\Comp_20190106_1600PM_20190106_1620PM_GRID\p190106_1601.tif: No such file or directory Failed to execute (ProjectRaster)

This gets a bit involved, but hopefully the following is written clearly enough.  I appreciate anyone wading through it..

Prior to calling this python script, the same console application successfully calls python scripts that rely on "arcpy.conversion.ASCIIToRaster" and "arcpy.management.Flip".  These python scripts accept arguments, build paths and names, and work without issue. The initial raster is successfully created from "arcpy.conversion.ASCIIToRaster".  The second raster is successfully created from "arcpy.management.Flip"

We followed the same pattern with "arcpy.ProjectRaster_management" script.  This script relies on the raster created by arcpy.management.Flip as the input and is supposed to output the projected raster (p190106_1601.tif).  From the error message cited above, the tool is complaining about opening the raster dataset that is the output of this project script.  It recognizes the input raster, which was created by the flip process immediately before that.

As a test, we ran the console application to the point of generating the initial raster and the flipped version and ended the console application. We then moved the code in the console application that calls "arcpy.ProjectRaster_management" python script  to the beginning of the console application, with the initial raster and the flipped raster already generated from the earlier run. This initially failed.  However, on a lark, we removed the LOG file from the directory and rand the console application again with the input rasters already baked up from an earlier run. This worked with the python script successfully generating the projected raster with no complaints.

We found that the python script doing the projection would work with the previously established rasters already there as long as there was no LOG file in the directory.  We thought the LOG file was somehow interfering with the project bit, so we altered the python scripts to remove the LOG file following the execution of the tool.  However, the project bit still failed when it was run in the normal order. (following the "arcpy.conversion.ASCIIToRaster" and the "arcpy.management.Flip".)

So a quick summary of all of this is that the project python script succeeds if the console app is run with the input rasters already baked up from an earlier run.  It fails when it is called in the console app immediately following the creation of the input raster.  The project command also appears to object to the LOG file being present as well.

Initially, I I thought this might be a timing issue, and placed a sleep thread in the console application following the creation of the initial rasters and before when the project script was called.  I have also tried removing he LOG file through the C# console app. It seems some remnant from the earlier process (convert, and or flip) that is interfering with Project doing its job.  

 

I have all of these processes successfully behaving in an ArcGIS Pro application.  However, that is relying on the ProSDK.

Any insight would be appreciated. 

 

0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

can you confirm that all inputs were in that really long folder and all the inputs and outputs were indeed *.tif rasters…( the file extension is important, since you will end up with esri grids if you don't and your file paths could be an issue)

0 Kudos
ThomasCox
Occasional Contributor

Thanks for responding.  Yes, quite confident regarding the syntax. The rasters are tifs.  They are the output from the earlier python processing scripts.Directory

0 Kudos
ThomasCox
Occasional Contributor

I have found that calling the project python script again, immediately after it fails, works on the second call. As mentioned above, the project command errors out when initially called .. "Failed to open raster dataset ..." as described in the initial post.  In the C# Console application, when I call the for the python script to be executed again immediately after the first failure, the project command behaves nicely.  Appears to be some type of timing issue, though not sure how to remedy. The first call results in the failure, the second call succeeds calling the same script, same parameters. 

ExecuteArcPyScript.run_arcpy2(@"C:\DopplerConsoleRasters\PythonScripts\TestingProject.py", strGridDirectory + @"\" + strFlippedVersion, strGridDirectory + @"\" + strProjectedVersion);

ExecuteArcPyScript.run_arcpy2(@"C:\DopplerConsoleRasters\PythonScripts\TestingProject.py", strGridDirectory + @"\" + strFlippedVersion, strGridDirectory + @"\" + strProjectedVersion);

 

0 Kudos