I have a shapefile and I need to create an OD cost matrix, but I only need the distances between points which are on the same polyline.

Is there any way to do that?

I am not much familiar with ArcGIS and only know the basics.

1 Answer 1


You would need to do this in two steps.

  1. Run Spatial Join geoprocessing tool on your points and lines feature classes. This will add a field to the point feature class that will have information about which polyline they intersect.

  2. Use arcpy or ModelBuilder to iteratively create an OD layer loading all points within every group (that is, those that share the same value for the polyline objectid) as both origins and destination and then solve it. This will give you all-to-all routes.

Look here for the sample on how to do this: Solve (Network Analyst)

  • If the source data is large, i find creating a all-to-all OD matrix first and then filtering the relevant ones from the table (i also find line creation is reduntant) much more efficient than adding removing OD pairs iteratively.
    – fatih_dur
    Commented Jul 22, 2017 at 1:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.