I am using Python code to calculate the closest facilities. Here, first I create a random point dataset. Then I use that random point dataset as an incident dataset when I'm creating the closest facility dataset.
My code is a loop. There I am trying to create 100 random datasets and the closest facilities from each random dataset to the school dataset. The code takes a lot of time to run. How can I increase the speed of this?
# Import arcpy module
import arcpy
import os, time, sys, subprocess
from arcpy import env
# Local variables:
Default_gdb = "C:\\Users\\Madusha\\Documents\\ArcGIS\\Default.gdb"
ms_gdb = "D:\\Crime\\python\\ms.gdb"
constrain = r"D:\Crime\python\chicago_c.shp"
nds = os.path.join(ms_gdb, "Road", "Road_ND")
Chicago_schools = r"D:\Crime\python\School2.shp"
arcpy.env.overwriteOutput = "True"
arcpy.CheckOutExtension("Network")
Measurements_Units = "Meters"
NumFacilitiesToFind=1
inNetworkDataset = nds
inFacilities = Chicago_schools
outGeodatabase =ms_gdb
measurement_units = Measurements_Units
for n in range(1, 101):
print 'Processing {0} of 100'.format(n)
a=arcpy.CreateRandomPoints_management(ms_gdb, 'dataset_{}'.format(n) , constrain, constrain, "FID_fishne", "SUM_MEAN_c", "POINT", "0")
inIncidents = a
outRoutes = 'NNRoutes2012_{}'.format(n)
outDirections = 'NNDirections2012_{}'.format(n)
outClosestFacilities = 'ClosestFacilities2012_{}'.format(n)
arcpy.na.FindClosestFacilities(inIncidents, inFacilities, measurement_units,
inNetworkDataset, outGeodatabase, outRoutes,
outDirections, outClosestFacilities,
Number_of_Facilities_to_Find=NumFacilitiesToFind)
print "Script completed successfully"
in_memory
where ever possible, instead of writing to disk. In your case, I think the only place you could use memory is with CreateRandomPoints. For JUST that tool, updatems_gdb
toin_memory
. It wont save a lot of time, but it'll help a bit.