How to use Arcpy.Delete_management to delete rasters?

439
2
02-21-2020 09:27 AM
RuthCostley1
New Contributor

Hi! I have this piece of code that loops through a set of tins and creates contours. The piece of code will create a contour from the first tin, but on the next tin in the folder it says that the tin is unsupported. My last line of code calls it to delete a raster which I had working in memory "memory/tempraster", but now I've noticed when I don't put it in memory, It doesn't delete the raster. Can anyone help? Thanks

tin_list = arcpy.ListDatasets("*", "Tin")
if contour_options == self.contourBase[0]:
    for tin in tin_list:
        outcontname =tin+"_cont"
        outcontnamelyr = os.path.basename(os.path.normpath(tin))+"_cont_lyr"
        arcpy.AddMessage("TIN to raster")
        arcpy.TinRaster_3d(tin, "raster","FLOAT", "NATURAL_NEIGHBORS","CELLSIZE %s"%(raster_options))
        arcpy.AddMessage("Contours")
        contResult = arcpy.Contour_3d( "raster",outcontname,1.0,0.0)
        while contResult.status < 4:
            time.sleep(0.2)
        arcpy.Delete_management("raster", '')
0 Kudos
2 Replies
DavidPike
MVP Frequent Contributor

Are you saying the problem is its failing on the second iteration? What's the full error? Can you print the tin filepath if that's what's erroring?

Why do you need the time.sleep?

0 Kudos
RuthCostley1
New Contributor

The script created 1 contour from Yck_pt1, and I have received the message "tin to raster". The tin filepath is currently at C:\Bathymetrycontours\Yck. The exact error is below. I have confirmed that Yck_pt2 is a tin, and I can run the exact tool in ArcPro with the dataset, and it does indeed work and exist. I removed the time.sleep, but I still get the error. Thanks for your help!

ERROR 000732: Input TIN: Dataset Yck_pt2 does not exist or is not supported
Failed to execute (TinRaster).
Failed to execute. Parameters are not valid.
ERROR 000732: Input TIN: Dataset Yck_pt2 does not exist or is not supported
Failed to execute (TinRaster).
Failed to execute (BathymetryContours)

0 Kudos