Couple of general suggestions. Not really a Network Analyst expert, but hopefully these apply.
- really look at what needs to within the looping structure. I'm probably not understanding all the logic in there, but it does seem like there are some variables and operations that would yield the same result with each iteration (particularly at the beginning of the loop).
- is there a way to avoid using the
Append
operation inside your looping? This is a relatively expensive operation. In the past, I've created a numpy array within a loop and then usedarcpy.da.numpyArrayToFeatureClass
to ingest all of that information at once (see my response to another question for an examplesee my response to another question for an example). - I'm guessing the
arcpy.na.Solve
operation is pretty expensive. Does this need to be solved iteratively or can it be done once all thearcpy.na.AddLocations
operations are done? For that matter, if you collect all the locations within the loop, can thearcpy.na.AddLocations
be done below the loop (could use numpy arrays, or even just a list of point geometries)? - is it necessary to create
outGeographicalAreaCentroidsSelection
? Can the selection on the original feature layer be used as input toAddLocations
instead? - can the two
SelectLayerByAttribute_management
operations be merged into one?