Select to view content in your preferred language

od cost matrix

1109
5
05-28-2013 04:12 AM
Tom_AndersEngebakken
Deactivated User
Hi

I have created a python script that runs an OD cost matrix over five years, from 1999 to 2004. I have set up an OD cost matrix for each year, which I think is very cumbersome. Is there someone who can show me how I do this with a loop in python (arcpy) instead of setting up the OD cost matrix for each year.
In my orgins and Destinations I also have a field called HOSPITALS. In the OD cost matrix, this field should be connected to each other so there will only be an analysis of each orgins to Destination.
How can i do this?
Tags (2)
0 Kudos
5 Replies
ChristophHütt
Deactivated User
Hi,
I would recommend a procedure and the call the procedure in a loop:

something like:
1. Procedure
def odmatrix(para1, ...):
   arcpy.MakeFeatureLayer_management (inOrgins, para1)
   ....


and later calling this procedure (maybe then with a loop) with the needed parameters that change.

 
...
odmatrix("Pas_Lyr1999", ...)
odmatrix("Pas_Lyr2000", ...)
...
 



If that works put your parameters in a list a run a for-loop:

listlyr ("Pas_Lyr1999", "Pas_Lyr2000",...)

for i in listlyr:
   odmatrix (i,...)


Haven't checked the syntax really, hope that answers your questions?
0 Kudos
Tom_AndersEngebakken
Deactivated User
Hi
I'll see if I understand it. I'm completely new to python.

But how can I connect the HOSPITALS fields from orgins and Destinations together? I will see which hospital patients are admitted to, but now it is estimated that each patient is admitted to all hospitals.
0 Kudos
BradShore1
Deactivated User
Look into using a Route layer instead of an OD Cost Matrix. You can you the ROUTENAME field in the Route layer to link the stops (orgins and destinations) based on Hospitals field.
0 Kudos
Tom_AndersEngebakken
Deactivated User
Hey Brad

I did not quite understand what you meant how to do it with the route layer. Can you please explain it a little better to me?

Tom Anders
0 Kudos
BradShore1
Deactivated User
With a route layer, you can load multiple features into it to be able to solve the route. If you define the RouteName field in the route layer (in your case you could use the Hospital ID), you can solve routes between Members and the Hospital they were seen at. The only downside to this is getting the data set up correctly.

You will need 2 features to do this, a Member feature and a Hospital feature. Here's the catch, in the hospital feature, there needs to be a record for every Member. So, if you have 20 Members total, 10 are seen at Hospital a, and 10 were seen at Hospital b, the Hospital feature will need 20 record total (10 Hospital a and 10 Hospital b). You can then load each feature into the stops of the Route Layer with the RouteName field defined on Hospital ID and it will calculate the distance between each Member and the Hospital they were seen at.

There are quite a few threads in the Network Analysis forums about how to use the RouteName field. I hope this makes sense and helps out.
0 Kudos