I am trying to delete the network analysis dataset as part of a workflow, but having no success. Is there an arcpy protocol that can be used to delete the dataset and feature classes? I have attempted to use the arcpy.Delete_management() call with no success.
Did see this in the Data Management - Delete documentation...
'Feature classes and tables participating in a network analysis dataset or a topology cannot be deleted'
But I can manually delete them from the GDB after I am done with them. But not with a script?
# General workflow...
na_lyr_name = "Service Area"
na_result = arcpy.na.MakeServiceAreaAnalysisLayer(routing_src, na_lyr_name, etc)
arcpy.na.AddLocations(na_lyr_name, etc)
arcpy.na.Solve(na_lyr_name, "SKIP", "TERMINATE", None, '')
na_lyr = na_result[0]
# Go create feature layers off the lines and polygon results of the network analysis...
# Then clean up the now unneeded NA dataset...
# First tried just deleting the dataset itself...
arcpy.Delete_management(na_lyr)
# or...
arcpy.Delete_management(na_lyr_name)
# Then tried looping through the layers
for lyr in na_lyr.listLayers():
layer_path = os.path.join(DATA_GDB, lyr.name)
temp = arcpy.Delete_management(layer_path)
# debug...returns True and layer name
print(temp, lyr.name)
No errors thrown. The 'temp' print statement in there shows the Delete reporting successful. But the dataset remains in the GDB when I examine the file.
Context:
This is a workflow that will be repeated quarterly, maybe monthly. The process is pretty standard: build a network along roadways from fixed points to create a service area. Then buffers are then built off the service area and passed on to a web map and web app.
I could just have someone manually go in after every run to delete the NA layers but would prefer the script clean up after itself.