How do I delete a network analyst layer (i.e., Service Area, Closest Facility) using python 3 (ArcGIS Pro)?

2118
13
Jump to solution
07-13-2019 06:23 PM
AndrewClark2
New Contributor III

Hi,

I am building a toolbox using Python 3 in ArcGIS Pro 2.4. It involves a series of network analysis processes, including closest facility and service area. I am using arcpy.na.MakeClosestFacilityAnalysisLayer and arcpy.na.MakeServiceAreaAnalysisLayer. I am able to create them no problem, but I am having lots of trouble with manipulating them, including: 

  • I cannot select the location where they are stored - they always get placed in the default GDB even though I am trying to put them "in_memory";
  • I cannot name them something meaningful - They always are named ServiceArea1, Service Area2; and 
  • I cannot delete the final layer using python (arcpy.Delete_management) once I am done with it - so every time I rerun the syntax it adds a new file with the wrong name (e.g., ServiceArea2) and my tool crashes. 

Anyone have any suggestion on how to fix this and make it work correctly? I want to be able to create it in a specified location, name it something that is meaningful and then delete the file when it is done.

Thanks!

Andrew

0 Kudos
13 Replies
MelindaMorang
Esri Regular Contributor

Would it be possible for you to share your facilities with me so I can test your script?  I can't tell from looking at it what's going wrong, but I'd like to get to the bottom of it.  I don't need your network dataset.

0 Kudos
AndrewClark2
New Contributor III

Hi Melinda,

Here is the file. I have zipped it into Google Drive as a shapefile. Let me know you if you have any issue!

Locations.zip - Google Drive 

Thanks so much. 

0 Kudos
MelindaMorang
Esri Regular Contributor

Hi Andrew.  Your script works fine with the addition of this line:

ServArea.defaultImpedanceCutoffs = [1]

Seems like you shouldn't need this because all your facilities have explicitly-set break values in the Breaks field, but for some reason it's getting confused.  I'll log a bug on our end to address this item of confusion, but I think if you add this to your code in the part where you're setting the service area properties, you should be good to go.

0 Kudos
AndrewClark2
New Contributor III

Thank you so much!

0 Kudos