I have a network dataset and I would like to know the network distance (not Euclidean) from each feature point in a shapefile to each other point in another shapefile with the same number of points. However, I would like to have separate tables for each feature, rather than one large table.

Is it possible to iterate through the point features in one shapefile, add the individual point as the "Origin" to an OD Cost Matrix (which already has the "Destination" locations added), solve for the Matrix, and export the lines or the line table, then move on the the next point and do the same? Or is there perhaps a simpler way to do this?

I know I will end up with a ton of tables, but I am hoping to run some analysis the individual tables.

Here is a graphic model from ModelBuilder I was working on: enter image description here

  • 1
    Can you confirm you are working with a network? As it stands I'm unclear on if you're looking for distances along a network or straight line (Euclidean) distances. If you are talking about a network, do you want network paths/routes as lines, or just the network distances in a table? Depending on clarifications, you can either sort through the overall matrix and export the relevant rows to individual tables, or rather than using OD Cost Matrix you want Closest Facility iteratively on each of your origins. How many origins are we talking?
    – Chris W
    Feb 20 '15 at 22:41
  • Yes, it is a network and I am looking for network distances. I just want the distances in a table. I was actually just thinking it would probably be easier to simply sort through the matrix and export rows. I am talking about 3,993 origins, so kind of a lot. A script that could export relevant rows would be great, though the final matrix was too large to load into excel.
    – alidrisi
    Feb 21 '15 at 14:26
  • I think I may have found the proper script (using Windows PowerShell): Import-Csv C:*FileName*.txt | Where-Object {$_.OriginID -eq "1"} | export-csv -Delimiter `t -NoTypeInformation -Path C:*NewFileName*.csv I am sort of new to scripting. Is there a way to iterate through all rows in the table (ie, OriginID=1,2,3,etc...)?
    – alidrisi
    Feb 21 '15 at 20:50
  • You should edit your question to append additional clarifying details requested in comments. I'm not much of a scripter yet myself, but what you've got in your comment looks like a start - however it's not using GIS, so at that point the question becomes more appropriate for StackOverflow rather than here. I've mentioned a split tool in my answer that might do what you need.
    – Chris W
    Feb 21 '15 at 21:23
  • Thanks, I have edited the original question to indicate that I am working with a network and am interested in obtaining network distances. Once I realized I could likely write a script to separate tables by origin I realized it may be outside of the purview of this forum. However, I may look to see if there is a Python script that could be added to a model after creating the full OD matrix that will separate the tables by OriginID.
    – alidrisi
    Feb 21 '15 at 23:25

Yes, there are two possible approaches to use.

One is to use the OD Cost Matrix tool and simply split up the resulting table. You'd select all records with the same origin point and export them to a new table. There is at least one Split by Attributes custom tool for ArcGIS out there (referenced here but the 10.x link there is currently broken) that can do this for shapefile/feature class, however I'm not sure if it would work with just tables (ie no geometry). Of course, you can generate straight lines with OD Cost Matrix and that might be a workaround. There might also be limits if trying to do this to a shapefile output depending on number of matches for each origin. This is likely to be the faster of the two approaches in terms of processing. I found another such tool (I think it's different) here: http://www.umesc.usgs.gov/management/dss/split_by_attribute_tool.html

The second approach is to build your model to iterate through origin points, but rather than using OD Cost Matrix you'd use Closest Facility. Since there's only one facility (selected origin), you'll get the distances and route line to all destinations. However this would be considerably more processing intensive than OD Cost Matrix - see the Tip on the OD help page or the CF help page. Note that an iterator executes the entire model with each iteration - you may need to create a submodel to hold part of the process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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