I really appreciate if anyone can help me out with this.
I want to calculate network distance from each subject (n=8000) to a facility (n=290) .
Each subject is supposed to go to one specific facility which is in their town.
Therefore, my approach was to
1. create point FC of subjects with the field "townname" which identifies where a subject lives.
2. create point FC of facilities with the field "townname" which identifies where a facility locates at.
3. execute MakreRouteAnalysisLayer by using field mapping
However after many attempts, only around 100 lines are created as output.
I want to have 8000 lines as output which each line has distance value to the associated facility.
If anyone could give any suggestions on this, I would really appreciate.
My codes below:
env.overwriteOutput = True
# calculate distance from subject to associated hospital
inPath1 = r"C:\Users\kenta\OneDrive\GISData_Import\ADF2012_DISSOLVE.gdb"
inPath2 = r"G:\ResearchProjects_data\gen_cohre\geocode.gdb"
inPath3 = r"G:\ResearchProjects_data\gen_cohre\Walkabiliy_Indices.gdb"
outPath = r"G:\ResearchProjects_data\gen_cohre\Walkability_final.gdb"
network = os.path.join(inPath1, "ADF", "ADF_ND")
stops_home = os.path.join(inPath3, "hospital")
stops_work = os.path.join(inPath2, "subject")
layer_name = "hosDistance"
out_routes_featureclass = os.path.join(outPath,"hosRoutes")
travel_mode = "Driving Time"
#Create a new Route layer.
result_object = arcpy.na.MakeRouteAnalysisLayer(network, layer_name, travel_mode)
#Get the layer object from the result object.
#The route layer can now be referenced using the layer object.
layer_object = result_object.getOutput(0)
#Get the names of all the sublayers within the route layer.
sublayer_names = arcpy.na.GetNAClassNames(layer_object)
#Stores the layer names that we will use later
stops_layer_name = sublayer_names["Stops"]
routes_layer_name = sublayer_names["Routes"]
#Before loading the subject home and hospital locations as route stops, set
#up field mapping. Map the "townname" field from the input data to
#the RouteName property in the Stops sublayer, which ensures that each
#unique townname will be placed in a separate route.
field_mappings = arcpy.na.NAClassFieldMappings(layer_object, stops_layer_name)
field_mappings["RouteName"].mappedFieldName = "townname"
#Add the home and hospital locations as Stops. The same field mapping
#works for both input feature classes because they both have a field called
arcpy.na.AddLocations(layer_object, stops_layer_name, stops_home,
arcpy.na.AddLocations(layer_object, stops_layer_name, stops_work,
field_mappings, "", append="APPEND")
#Solve the route layer.
# Get the output Routes sublayer and save it to a feature class
routes_sublayer = layer_object.listLayers(routes_layer_name)