How To: Restrict origin-destination analysis to solve routes for matching based on a common ID


An origin-destination (OD) cost matrix solves from every origin to every destination. In some cases, this is too much and the user may wish to restrict the origins to only route to certain destinations based on a matching ID. Attached is a sample model that helps accomplish this task.

Prior to following the procedure, the Network Analyst extension must be enabled in ArcMap.

This sample model is not supported by Esri Support Services. This is a model to help with this situation and is designed for learning purposes only.


For this model to function, it must be run from the Catalog window in an open .mxd file. In addition, the .mxd file must contain a network dataset and origin / destination point data (with matching IDs).

Download and unzip the 'SampleModel.zip' folder below.

This model only functions properly in Edit mode.

Right-click and edit the model 'Selective_ODCost_Matrix' and follow the steps as written in the model.

  1. Input the source network dataset. To do this, double-click the 'Input Network Dataset' bubble in the model. After this is done, check the accumulators (miles, minutes, etc..) to be appended to the routes to gather the driving distance and time.
  2. Input the destination points.
  3. Select the field that contains the ID from the destinations to be used to match with the origins.
  4. Input the origin points.
  5. Set the SQL expression. This expression can be formatted as "Your_ID_Field = %Value%"

    If the ID field is a string, be sure to use '' around %Value%. For example: IDField = '%Value%'

    This sets a query on the origins to only load points that match the unique selection from the iterator.
  6. Determine the folder location for the saved route results.
  7. Validate the model. If enabled, the entire model is colored.
  8. Run the model. The output is individual shapefiles for all the matching origin and destination routes.

    Optionally, after validating the entire model, double-click the 'Field Mapping' parameters to go into each of the 'Add Locations' tools. Set the field map so the NAME field is set to the Unique ID or Name field of the input origin or destination. This makes the output more legible by showing which origin goes to which destination.

Related Information